--- linux-2.6.11-orig/net/unix/af_unix.c 2005-03-02 16:38:12.000000000 +0900 +++ linux-2.6.11/net/unix/af_unix.c 2005-04-03 16:36:52.000000000 +0900 @@ -1838,6 +1838,7 @@ static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) { struct sock *sk = sock->sk; + struct sk_buff *skb; long amount=0; int err; @@ -1848,8 +1849,6 @@ err = put_user(amount, (int __user *)arg); break; case SIOCINQ: - { - struct sk_buff *skb; if (sk->sk_state == TCP_LISTEN) { err = -EINVAL; @@ -1869,8 +1868,21 @@ spin_unlock(&sk->sk_receive_queue.lock); err = put_user(amount, (int __user *)arg); break; - } +#define SIOCINCOUNT 0x8907 + case SIOCINCOUNT: + /* count the number of packets waiting */ + if (sk->sk_state == TCP_LISTEN) { + err = -EINVAL; + break; + } + + spin_lock(&sk->sk_receive_queue.lock); + skb_queue_walk(&sk->sk_receive_queue, skb) + amount++; + spin_unlock(&sk->sk_receive_queue.lock); + err = put_user(amount, (int __user *)arg); + break; default: err = dev_ioctl(cmd, (void __user *)arg); break;