How do I get amount of queued data for UDP socket?

FWIW, I did some experiments to map out the behavior of FIONREAD on different platforms.

Platforms where FIONREAD returns all the data pending in a SOCK_DGRAM socket:

Mac OS X, NetBSD, FreeBSD, Solaris, HP-UX, AIX, Windows

Platforms where FIONREAD returns only the bytes for the first pending datagram:

Linux

It might also be worth noting that some implementations include headers or other overhead bytes in the count, while others only count the payload bytes. Linux appears to return the payload size, not including IP headers.

Leave a Comment