ICMP - Raw socket



Hi All,
I am trying to use a icmp socket to receive all the icmp packets that
reaches my machine. If i ping my machine from other pcs, ping is sucessful
which means there are some icmp packets reached my machine, but recvfrom
never returns. But if i ping other pcs from my machine, recvfrom returns
immediately. Could anyone let me know how can resolve this issue?

Here is the code

ZeroMemory(&sLocalSock,sizeof(sLocalSock));

sLocalSock.sin_family = AF_INET;

sLocalSock.sin_addr.S_un.S_addr = inet_addr("172.20.211.72");

//creating the socket
m_sAdvSocket=socket(AF_INET,
SOCK_RAW,
IPPROTO_ICMP);


if(m_sAdvSocket==INVALID_SOCKET)
{

wsprintf(szTempError,"%d no. Error in creating socket in
advertisement",WSAGetLastError());
MessageBox(NULL,szTempError,"Error",0);
return 0;


}


iAdvSockError=bind(m_sAdvSocket,

(SOCKADDR *)&sLocalSock,

sizeof(sLocalSock));

if(iAdvSockError== SOCKET_ERROR)
{

wsprintf(szTempError,"%d no. Error in binding socket in
advertisement",WSAGetLastError());
MessageBox(NULL,szTempError,"Error",0);
return 0;


}






int iSize=sizeof(sLocalSock);

char szIp[3500];

if(SOCKET_ERROR==recvfrom(m_sAdvSocket,(char *)&szIp,3400,0,(struct
sockaddr *)&sLocalSock,&iSize))
{
wsprintf(szTempError,"%d no. Error in receiving in
advertisement",WSAGetLastError());
MessageBox(NULL,szTempError,"Error",0);
return 0;

}


Thanks,
Senthil
.



Relevant Pages

  • Re: How to test whether a host is reachable?
    ... As the subject says I need to test whether a host computer in our ... network is reachable or not. ... Just because you could ping with ICMP packets doesn't mean you could ...
    (comp.lang.python)
  • Re: nethack.alt.org down again???
    ... ping when it was up was when a shoddy nntp server ... started blocking pings (or the firewall before it as you say) and ... Many/most corporate firewalls block most/all ICMP packets, ... responding to ICMP packets. ...
    (rec.games.roguelike.nethack)
  • Re: distributed natd
    ... > Keeping with the above ping pong idea, maybe instead of icmp packets you can ... By "ping" I did not mean sending ICMP to peer gateway, ... traffic, then we have state tables updated constantly, thus alive gateway ...
    (FreeBSD-Security)
  • Re: How to test whether a host is reachable?
    ... I think of something like a python version of ping ... which only tries to send ICMP packets. ... Server or a firewall in between most probably will filter out any ICMP ...
    (comp.lang.python)
  • Re: ICMP - Raw socket
    ... > I am trying to use a icmp socket to receive all the icmp packets ... If i ping my machine from other pcs, ... > which means there are some icmp packets reached my machine, ... But if i ping other pcs from my machine, recvfrom returns ...
    (microsoft.public.win32.programmer.networks)