Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tracing PINGs

Status
Not open for further replies.

cyprus106

Programmer
Apr 30, 2001
654
OK, This may be a little advanced but it's at least worth a shot.

I know it's possible to know when you've been Pinged (network, internet... that kind of ping) by another machine, but how would I read that in code? Anybody know a theory or sample?

Thanks a lot, Cyprus
 
You would probably need to read all the IP datagrams comming into your machine (look at the protocol field of the header) and see which ones have an Echo Request in them.

Using Windows (Berkley) sockets, the following is from the excellent Black Sun Reasearch site from one of their winsock tutorials:

------------------------------
As usual we would set up our socket with something like the following:

SOCKET sniffsock;
SOCKADDR_IN if0;

sniffsock = socket(AF_INET, SOCK_RAW, IPPROTO_IP);

and then call bind() with this raw socket:

bind(sniffsock, (SOCKADDR *)&if0, sizeof(if0));

we then go into Promiscuous mode and recieve all of the packets by calling WSAIoctl() with SIO_RCVALL set:

WSAIoctl(sniffsock, SIO_RCVALL, &optval, sizeof(optval), NULL, 0, &dwBytesRet, NULL, NULL);

we can then use the WSARecv() function to grab the packets and feed them into a buffer like so:

recv(sniffsock, RecvBuf, sizeof(RecvBuf), 0);
------------------------------

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top