I'm writing a socket application on WIndows using MSVC++6. I'm sending a UDP packet to a remote destination on a high port which should respond with an ICMP Destination Unreachable(Port Unreachable) message. I using RAW sockets to send and receive data. The select() function is used for asynchronous I/O control.
Problem : When I send 10 UDP packets I am receiving a maximum of 4 replies although 10 replies are being sent back. How I know this is that I am running a sniffer and the sniffer picks up the 10 replies but my program doesn't.
The main parts of the code are below....
// Create the socket for sending UDP datagrams
SOCKET send_sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
// Crerate the socket for receibong ICMP replies...
SOCKET recv_sock = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
// Send the UDP packet to a remote destination....
struct timeval wait;
wait.tv_sec = 1;
wait.tv_usec = 0;
// Wait for 1 second for a reply ....
if( select(recv_sock, fds, (fd_set*)0, (fd_set*)0, &wait) > 0 )
// Receive the ICMP reply....
recvfrom(recv_sock, buffer, 1024, &from, sizeof(from) );
// Print the reply to stdout...
I only receive a maximum of 4 replies after sending 10 packets when I should receive 10 replies and the sniffer I'm running does receive 10 replies. Why does this program not receive all 10 replies when you know for SURE that 10 replies are sent back to this computer.
Any help, code or suggestions will be greatly appreciated.