Skip to content

Commit

Permalink
af_unix: MSG_TRUNC support for dgram sockets
Browse files Browse the repository at this point in the history
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 <[email protected]>
Tested-by: Piergiorgio Beruto <[email protected]>
CC: Michael Kerrisk <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Eric Dumazet authored and davem330 committed Feb 22, 2012
1 parent cdf49c2 commit 9f6f9af
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion net/unix/af_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1845,7 +1845,7 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
if (UNIXCB(skb).fp)
siocb->scm->fp = scm_fp_dup(UNIXCB(skb).fp);
}
err = size;
err = (flags & MSG_TRUNC) ? skb->len - skip : size;

scm_recv(sock, msg, siocb->scm, flags);

Expand Down

0 comments on commit 9f6f9af

Please sign in to comment.