ICMP - Raw socket
- From: "Senthil" <Senthil@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 4 Oct 2005 06:36:43 -0700
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
.
- Follow-Ups:
- Re: ICMP - Raw socket
- From: Arkady Frenkel
- Re: ICMP - Raw socket
- Prev by Date: Re: Windows 2003 faxcomex api problem
- Next by Date: Multicast addressing and Microsoft loopback adapter
- Previous by thread: RE: Send SMS Text in C++ (WIN32 App)
- Next by thread: Re: ICMP - Raw socket
- Index(es):
Relevant Pages
|