I'm having some issues with recvfrom() not getting all the packets in C++. (and then blocking and not returning)
I send 1 query packet, and then a response is sent.
It's broken into multiple packets of 805 bytes and then ended with a packet of ~200 bytes.
From my tests, 54 packets are received in total.
However, my program is only receiving 25-35 packets total, and not the ending packet, although the packets seem to be arriving fine in WireShark.
My code can be seen here:
sockaddr_in local, dest;
local.sin_family = AF_INET;
local.sin_port = htons(58770);
local.sin_addr.S_un.S_addr = INADDR_ANY;
dest.sin_family = AF_INET;
dest.sin_addr.S_un.S_addr = inet_addr(QUERYADDR);
dest.sin_port = htons(20810);
SOCKET s;
if((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
errex("socket() failed");
if(bind(s, (sockaddr*)&local, sizeof(local)) == -1)
errex("bind() failed!");
sendto(s, (const char*)QUERY, sizeof(QUERY), 0, (sockaddr*)&dest, sizeof(dest));
while(true)
{
sockaddr_in tsaddr;
char buf[8192];
int slcl = sizeof(tsaddr);
int res = recvfrom(s, buf, sizeof(buf), 0, (sockaddr*)&tsaddr, &slcl);
printf("%i\n", res);
}
closesocket(s);
WSACleanup();
Can anyone see anything wrong?
The most likely explanation is that the packets are being dropped somewhere along the line. Wireshark just tells you that the packets are on the wire, not that they are being correctly received by the receiver.
Try checking your SO_RCVBUF socket option on the receiver to make sure that's not being overrun (which will result in dropped packets), as well as checking your network driver for any indications of errors or other problems.