Skip to contentSkip to conversation

bytes received from recvmsg doesn't match FIONREAD

DISCUSSION Steven Dake 3 participants 3 messages Oct 11, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

I wanted to verify that the size of a multicast UDP message received with recvmsg matches the size of the message the kernel thinks the message is.

So I went about using the FIONREAD ioctl as follows:

res = ioctl (fd, FIONCREAD, &value);
assert (res != -1);
bytes_received = recvmsg (fd, &msg_recv, MSG_NOSIGNAL | MSG_DONTWAIT); assert (bytes_received == value);

It appears the value and bytes_received do not match after many thousands of runs with a UDP multicast protocol (www.openais.org). (neither is -1)

Am I using this ioctl improperly? Shouldn't I expect that the full datagram is returned by recvmsg no matter the state of the blocking or nonblocking mode of the file descriptor?

pls copy me on responses - i am not onlist.

Regards
-steve

maintainer
#1 lore raw

From: Steven Dake <[email protected]>
Date: Thu, 11 Oct 2007 16:08:15 -0700

Quoted 7 lines

I wanted to verify that the size of a multicast UDP message received with recvmsg matches the size of the message the kernel thinks the message is.

So I went about using the FIONREAD ioctl as follows:

res = ioctl (fd, FIONCREAD, &value);

                   ^^^^^^^^^ (typo? should be FIONREAD not FION_C_READ)
Quoted 3 lines

assert (res != -1);
bytes_received = recvmsg (fd, &msg_recv, MSG_NOSIGNAL | MSG_DONTWAIT); assert (bytes_received == value);

I think you want to use SIOCINQ, FIONREAD is only valid on files.

I'm surprised you didn't get an error return from ioctl() as the VFS code seems to enforce this.

#2 lore raw
In reply to Steven Dake

Questions of this sort should normally be directed to linux-net mailing list.

Quoted 1 line

From the code you quoted, I see at least one case where it

will fail -- when the allocated buffer you pass to recvmsg is smaller than "value" (ie. the datagram is too big for the read buffer).

If that's not the problem, I suggest you reproduce it with a small test case and post real code and results when it happens.

                                                +-DLS