Interpretation of POSIX.1-2008 for recvmsg

Patrick Mooney patrick.mooney at joyent.com
Fri Jul 31 18:20:18 UTC 2015


Greetings,
I have been researching differences in recvmsg() behavior across platforms
(namely Illumos and Linux) with respect to MSG_PEEK and 0-length buffers.
Certain Linux software I am attempting to run under Illumos makes a recvmsg()
call with a 0-length iovec and flags set to MSG_PEEK in order to interrogate
the size of a queued dgram.  On native Linux, recvmsg() returns the size of the
queued dgram (with the MSG_TRUNC flag set).  On both Illumos and FreeBSD, a
size of 0 is returned (with MSG_TRUNC set as well).  In reading the POSIX spec
(http://pubs.opengroup.org/onlinepubs/9699919799/functions/recvmsg.html), it is
not clear that returning 0 in this case is correct behavior.

Here is a small test program I wrote up to display the differences in behavior:
https://us-east.manta.joyent.com/patrick.mooney/public/recvmsg/peektest.c

The output on Linux:
peek len: 20 errno: 0 flags: 20
recv len: 20 errno: 0 flags: 0
... versus BSD and Illumos:
peek len: 0 errno: 2 flags: 12
recv len: 20 errno: 2 flags: 0

I am interested in your opinions on the matter.

With regards,

--Patrick


More information about the freebsd-hackers mailing list