LKML Archive on
help / color / mirror / Atom feed
From: Daniel Kabs <>
Subject: unix(7) and MSG_TRUNC semantics
Date: Thu, 11 Jan 2007 15:41:03 +0100	[thread overview]
Message-ID: <> (raw)


For IPC, I use unix domain datagram sockets. I receive messages by calling 
recv(). The man page recv(2) tells me about the flags argument to a recv 
call, namely:
      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 reckon, the function should 
return the real message size instead.

To work around this problem, I 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:

UDP sockets seem to have been patched by now. From linux/net/ipv4/udp.c:
        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?

Daniel Kabs

                 reply	other threads:[~2007-01-11 15:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \
    --subject='Re: unix(7) and MSG_TRUNC semantics' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).