I need to receive incoming UDP packets using RAW socket, which is being opened using this code snippet:
static int fd;
char *iface;
iface = "eth0";
if ( (fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0 )
{
perror("socket");
}
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, iface, strlen(iface)) < 0)
{
perror("bind");
exit(EXIT_FAILURE);
}
I send, say, 100 identical packets and try to receive and count them. I use recv(...) to do this. Only 93 packets are delivered, and then recv(...) hangs waiting for next ones. But if I run "Wireshark" (which uses libpcap) on the receiving side computer and make it listen on "eth0" to UDP packets, then my app will always catch 100 packets without any problems.
I can't understand what I'm actually doing wrong, and why does "Wireshark" influence my socket receiver as well?
P.S. I already tried to increase receive buffer size, but no success.