关于截获网卡的IP数据包的问题(200)

  • 主题发起人 主题发起人 ukn_ma4
  • 开始时间 开始时间
U

ukn_ma4

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大大好,问题如下:在用delphi做截获本机网卡的IP数据包时出现问题-------收不到任何数据包(即使明明有接收到数据包)代码如下:var MySocket:tsocket ; buffer:Array of byte; info:STRING; const SIO_RCVALL = IOC_IN or IOC_VENDOR or 1;procedure TForm1.Button1Click(Sender: TObject);var iErrorCode:integer; wsd:TWSADATA; host:sockaddr_in; Buffer: array [0..63] of char; HostEnt: PHostEnt; bopt:integer;begin if WSAStartup(MAKEWORD(2,2),wsd)=0 then begin MySocket:=socket( AF_INET , SOCK_RAW , IPPROTO_IP );//------------------ipproto_raw if MySocket<>INVALID_SOCKET then begin bopt:=1; iErrorCode:=setsockopt(MySocket, SOL_SOCKET, SO_RCVTIMEO, @bOpt, sizeof(bOpt)); if iErrorCode<>SOCKET_ERROR then begin GetHostName(Buffer, SizeOf(Buffer)); HostEnt:=GetHostByName(Buffer); if HostEnt <> nil then begin Host.sin_family:=AF_INET; Host.sin_port:=htons(7000); Host.sin_addr.s_addr :=inet_addr('192.168.0.171'); if winsock.bind(MySocket, Host, sizeof(Host))<>SOCKET_ERROR then showmessage('绑定成功') else begin showmessage('错误类型:'+IntToStr(WSAGetLastError)); //WSAEADDRNOTAVAIL 10049 Cannot assign requested address. end; end; end else showmessage('绑定失败!!'); end; end;end;// 设置网卡为混合模式procedure TForm1.Button2Click(Sender: TObject); var dwValue:integer; begin dwValue:=1; if ioctlsocket(MySocket, SIO_RCVAll, dwValue) = 0 then begin showmessage('设置模式成功'); end; end;//接收数据包procedure TForm1.Button3Click(Sender: TObject);vari,ret:integer;begin setlength(info,255); setlength(buffer,255); for i:=0 to 200 do begin ret:=recv(mysocket,buffer[0],sizeof(buffer),0); if ret>0 then begin copymemory(@info[1],@buffer[0],sizeof(buffer)); showmessage(info); end; // sleep(1000); //showmessage(info); end;end; 在vc下的实现网上有很多 可是delphi下 上网找了一星期没有什么现成的源码 请各位大大看看 谢谢!
 
流个QQ,我发一份给你!~
 
很感谢 Dstorm email ukn_ma4@126.com
 
接受答案了.
 
后退
顶部