public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Problem with unix sockets: SOCK_DGRAM ignores MSG_TRUNC
@ 2007-01-29 11:59 Daniel Kabs
  2007-02-05  0:52 ` David Miller
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Kabs @ 2007-01-29 11:59 UTC (permalink / raw)
  To: linux-kernel

Hi,

I use unix domain datagram sockets for IPC, e.g. I receive messages by 
calling recv().

"man 2 recv" tells me about the flags argument to a recv() call, namely:

 MSG_TRUNC
      Return  the  real  length of the packet, even when it was longer
      than the passed buffer. Only valid for packet sockets.

Thus I used recv() with flags MSG_TRUNC|MSG_PEEK in order to detect 
message truncation due to insufficient buffer size.

Strangely enough, MSG_TRUNC seems to get ignored by the kernel: If the 
message received is larger than the receive buffer I supplied, the 
function returns the size of the buffer. I think, the function should 
return the real message length instead (at least according to the manual 
page).

To work around this problem, I now use the ioctl FIONREAD instead.

On the other hand, in this mailing list, I found an old bug report 
describing the same problem using UDP sockets:

http://groups.google.com/group/fa.linux.kernel/browse_frm/thread/fb6acbb527507e26/ad0b2ba33b6b66fa

UDP sockets seem to have been patched by now. From linux/net/ipv4/udp.c:
 udp_recvmsg()
  ...
        err = copied;
        if (flags & MSG_TRUNC)
                err = skb->len - sizeof(struct udphdr);
   ...

Why doesn't unix_dgram_recvmsg() in linux/net/unix/af_unix.c contain code 
to this effect? Is this a feature or a bug? What is the correct semantics 
of MSG_TRUNC when used for unix sockets?

Cheers
Daniel Kabs

PS: According to some lkml archives, my previous mail did not come 
through, so I reposted it.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-02-07  9:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-29 11:59 Problem with unix sockets: SOCK_DGRAM ignores MSG_TRUNC Daniel Kabs
2007-02-05  0:52 ` David Miller
2007-02-06 12:55   ` Daniel Kabs
2007-02-06 20:11     ` David Schwartz
2007-02-07  8:58       ` Daniel Kabs
2007-02-07  9:31   ` Daniel Kabs

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox