SIO_RCVALL - can`t catch outgoing packets

Hello

I try to write some network analizer. I write some function wchich sepouse catch all trafic. Problem is that i can`t catch outgoing packets. This is a couple lines of code:

if(WSAStartup(MAKEWORD(2,1),&wsd) != 0)
{
ShowMessage( "Error WSAStartup" );
return ;
}

sock = socket(AF_INET, SOCK_RAW, IPPROTO_IP);

char FAR name[MAX_HOSTNAME_LAN];
gethostname(name, MAX_HOSTNAME_LAN);

struct hostent FAR * pHostent;
pHostent = (struct hostent * )new char[(sizeof(struct hostent))];
pHostent = gethostbyname(name);

SOCKADDR_IN sa;
sa.sin_family = AF_INET;
sa.sin_port = htons(65535);

memcpy(&sa.sin_addr.S_un.S_addr, pHostent->h_addr_list[0], pHostent->h_length);

bind(sock, (SOCKADDR *)&sa, sizeof(sa));

if( WSAIoctl( sock, SIO_RCVALL, &optval, sizeof(optval), NULL, 0, &dwBytesRet, NULL, NULL) != 0 )
{
Application->MessageBoxA("Problem z ustawieniem trybu gniazda", "Error", MB_OK+MB_ICONERROR );
_endthread();
}

while( true )
{
memset(RecvBuf, 0, BufferLen) ;

iBytes = recv(sock, RecvBuf, BufferLen, 0) ;

ip_hdr *pIpheader = (ip_hdr *)RecvBuf;
tcp_hdr *pTcpheader = (tcp_hdr *)(RecvBuf + sizeof(ip_hdr));
udp_hdr *pUdpheader = (udp_hdr *)(RecvBuf + sizeof(ip_hdr));

// filter src_ip
if((ip_src_filter.S_un.S_addr != 0) &&
(ip_src_filter.S_un.S_addr != pIpheader->ip_srcaddr.S_un.S_addr))
{
ShowMessage( "Error source IP");
}
......
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories