From 56b5adfb617ca66a649dceb9a054a059ff1cc387 Mon Sep 17 00:00:00 2001 From: "David S. Miller" Date: Sat, 26 Feb 2005 19:15:10 -0800 Subject: [AF_UNIX]: Fix SIOCINQ for STREAM and SEQPACKET. We should report the total bytes in the whole receive queue, not just the first packet, in these cases. Reported by Uwe Bonnes. Signed-off-by: David S. Miller --- net/unix/af_unix.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'net/unix/af_unix.c') diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 062bcc2080a7..5658798cabc1 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -1850,15 +1850,22 @@ static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) case SIOCINQ: { struct sk_buff *skb; + if (sk->sk_state == TCP_LISTEN) { err = -EINVAL; break; } spin_lock(&sk->sk_receive_queue.lock); - skb = skb_peek(&sk->sk_receive_queue); - if (skb) - amount=skb->len; + if (sk->sk_type == SOCK_STREAM || + sk->sk_type == SOCK_SEQPACKET) { + skb_queue_walk(&sk->sk_receive_queue, skb) + amount += skb->len; + } else { + skb = skb_peek(&sk->sk_receive_queue); + if (skb) + amount=skb->len; + } spin_unlock(&sk->sk_receive_queue.lock); err = put_user(amount, (int __user *)arg); break; -- cgit v1.2.3