Reputation: 2934
Is there anyway that I can get the sockaddr information from an incoming packet without actually doing a recvfrom on the data first? I was just wondering cause you can tell that there is something to be read with like a poll or select I was wondering if I can pull more information from this before actually reading the data that was sent. I ask this because I have a system where each individual ip/port combination has its own little internal buffer that we put chunked messages into and I need to know so that I can put it in the right internal buffer.
Upvotes: 1
Views: 88
Reputation: 20063
Yes, by supplying the MSG_PEEK flag to the recvfrom
call.
recvfrom(socket, buffer, 1, MSG_PEEK, &address, &address_len);
This will leave the datagram intact and not remove it. You can of course specify a smaller value for the buffer size to reduce unecessary read overhead. The next time you do a normal recvfrom
the datagram will be removed as normal.
recvfrom(socket, buffer, length, 0, &address, &address_len); // Do the actual read
Upvotes: 1