Reputation: 34563
How do I check that the message from recvfrom() is the correct size in C or C++ on windows?
Thank you.
Upvotes: 0
Views: 634
Reputation: 283713
recvfrom
returns the number of bytes in the datagram actually received.
All you need is
if (iResult < 0) { /* network error */ }
if (iResult != BufLen) { /* wrong size */ }
Old answer, off topic
You should declare a variable to hold the size, and pass its address as the fromlen
parameter.
recvfrom
will fill in the actual size of the datagram sender's address (IP and port, so you can send a reply if you want).
Then you can test the actual size against what you expected.
Upvotes: 1