I try to write the app to same thing like "Ping" in windows.
I get problem that I can not receive the reply.
In this app also has sniffing function.

what happened :

When I use "Ping" in windows, my sniffer can catch all the send/rev.

When I use my app to send icmp to same address. I can catch what I send, but never rev the reply.

When I use my app to send icmp to 127.0.0.1, I get nothing in sniffer.

pls help me, thanks

here is related code: (do i need any settings? like WSAIoctl and setsockopt)

<code>
RecvAddr.sin_family=AF_INET;
RecvAddr.sin_port = htons(Port);
RecvAddr.sin_addr.s_addr=inet_addr(DEFAULT_RECV_ADDR);


icmp_socket=WSASocket(AF_INET,
SOCK_RAW,
IPPROTO_ICMP,
NULL,
0,
WSA_FLAG_OVERLAPPED);

//initialise the icmp header
ZeroMemory(buf,sizeof(buf));
int size=sizeof(buf);
size=sizeof(ICMP);
//icmp_icmp=*(ICMP *)buf;
icmp_icmp.icmp_type= 8;//ICMP ECHO
icmp_icmp.icmp_code=0;
icmp_icmp.icmp_sequence=0;
icmp_icmp.icmp_id=(WORD)GetCurrentProcessId();
icmp_icmp.icmp_timestamp=GetTickCount();
icmp_icmp.icmp_checksum=ICMPChecksum((WORD *)buf,(sizeof(ICMP)+32));
memcpy(buf,&icmp_icmp,sizeof(icmp_icmp));
//fill the payload with anything
memset(&buf[sizeof(ICMP)], '@', 32);

WORD ICMPClass::ICMPChecksum(WORD * data, int len)
{
DWORD cksum=0;

while(len>1)
{
cksum+=*data++;
len-=sizeof(WORD);
}
if(len)
{
cksum+= *(WORD*)data;
}
cksum=(cksum >>16)+(cksum &0xffff);
cksum+=(cksum >> 16);
return (WORD)(~cksum);
}


In IO class

DataBuf.len=ICMP_SEND_BUFFER_SIZE;
DataBuf.buf=buf;

overlapEventList[ICMP_WRITE]=WSACreateEvent();
overlapList[ICMP_WRITE].hEvent=overlapEventList[ICMP_WRITE];



result = WSASendTo(icmp_socket, &DataBuf, 1,&BytesSent, Flags, (SOCKADDR *) icmp->GetRecvAddr(), sizeof(SOCKADDR), &overlapList[ICMP_WRITE], NULL);


<\code>