Commit 9f6f9af7694ede6314bed281eec74d588ba9474f

Authored by Eric Dumazet
Committed by David S. Miller
1 parent cdf49c283e

af_unix: MSG_TRUNC support for dgram sockets

Piergiorgio Beruto expressed the need to fetch size of first datagram in
queue for AF_UNIX sockets and suggested a patch against SIOCINQ ioctl.

I suggested instead to implement MSG_TRUNC support as a recv() input
flag, as already done for RAW, UDP & NETLINK sockets.

len = recv(fd, &byte, 1, MSG_PEEK | MSG_TRUNC);

MSG_TRUNC asks recv() to return the real length of the packet, even when
is was longer than the passed buffer.

There is risk that a userland application used MSG_TRUNC by accident
(since it had no effect on af_unix sockets) and this might break after
this patch.

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Tested-by: Piergiorgio Beruto <piergiorgio.beruto@gmail.com>
CC: Michael Kerrisk <mtk.manpages@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 1 changed file with 1 additions and 1 deletions Side-by-side Diff

... ... @@ -1845,7 +1845,7 @@
1845 1845 if (UNIXCB(skb).fp)
1846 1846 siocb->scm->fp = scm_fp_dup(UNIXCB(skb).fp);
1847 1847 }
1848   - err = size;
  1848 + err = (flags & MSG_TRUNC) ? skb->len - skip : size;
1849 1849  
1850 1850 scm_recv(sock, msg, siocb->scm, flags);
1851 1851