我有一个工作嗅探器程序,用 Delphi 编写。它在局域网中很好。但是当我的计算机在 WLAN 上时,它不会记录任何内容。初始化:
if (WSAStartup(MAKEWORD(2,2), Wsa) <> 0) then ErrorMsg ('WSAStartup');
//Create a RAW Socket
sniffer:= socket(AF_INET, SOCK_RAW, IPPROTO_IP);
if (sniffer = INVALID_SOCKET) then ErrorMsg ('Socket');
//Retrive the local hostname
getmem (hostname, 100);
if (gethostname(hostname, 100) = SOCKET_ERROR) then ErrorMsg ('Gethostname');
//Retrive the available IPs of the local host
local:= gethostbyname(hostname);
if (local = nil) then ErrorMsg ('Gethostbyname');
i:= 0;
repeat
i:= i + 1;
Move (local^.h_addr^[i-1], Addr, sizeof(Tinaddr));
until (local^.h_addr^[i-1] <> #0);
Players.MyIP:= inet_ntoa(Addr);
if Players.MyIP = '0.0.0.0' then
begin
Showmessage ('No IP!?'); halt;
end;
_in:= 0;
FillChar (Dest, SizeOf(Dest), 0);
Move (local^.h_addr^[_in], dest.sin_addr.s_addr, sizeof(dest.sin_addr.s_addr));
dest.sin_family:= AF_INET;
dest.sin_port := 0;
if (bind(sniffer, @dest, sizeof(dest))) = SOCKET_ERROR then ErrorMsg ('Bind');
j:= 1;
if (WSAIoctl(sniffer, SIO_RCVALL, @j,4, nil, 0, LPDWORD(@_in),nil, nil)) = SOCKET_ERROR then ErrorMsg ('WSAIoctl');
捕获线程
while not Terminated do
begin
mangobyte:= recvfrom (sniffer,Buffer^,65536,0,nil,nil); //Eat as much as u can
if (mangobyte > 0) then
begin
adsasdasd
end
所以它不会记录任何东西。我错过了什么吗?