Skip to content

Commit 6273172

Browse files
acmelDavid S. Miller
authored andcommitted
[DCCP]: Implement SIOCINQ/FIONREAD
Just like UDP. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Leandro Melo de Sales <leandroal@gmail.com> Signed-off-by: Ian McDonald <ian.mcdonald@jandi.co.nz> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent bada339 commit 6273172

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

net/dccp/proto.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <net/sock.h>
2727
#include <net/xfrm.h>
2828

29+
#include <asm/ioctls.h>
2930
#include <asm/semaphore.h>
3031
#include <linux/spinlock.h>
3132
#include <linux/timer.h>
@@ -378,8 +379,36 @@ EXPORT_SYMBOL_GPL(dccp_poll);
378379

379380
int dccp_ioctl(struct sock *sk, int cmd, unsigned long arg)
380381
{
381-
dccp_pr_debug("entry\n");
382-
return -ENOIOCTLCMD;
382+
int rc = -ENOTCONN;
383+
384+
lock_sock(sk);
385+
386+
if (sk->sk_state == DCCP_LISTEN)
387+
goto out;
388+
389+
switch (cmd) {
390+
case SIOCINQ: {
391+
struct sk_buff *skb;
392+
unsigned long amount = 0;
393+
394+
skb = skb_peek(&sk->sk_receive_queue);
395+
if (skb != NULL) {
396+
/*
397+
* We will only return the amount of this packet since
398+
* that is all that will be read.
399+
*/
400+
amount = skb->len;
401+
}
402+
rc = put_user(amount, (int __user *)arg);
403+
}
404+
break;
405+
default:
406+
rc = -ENOIOCTLCMD;
407+
break;
408+
}
409+
out:
410+
release_sock(sk);
411+
return rc;
383412
}
384413

385414
EXPORT_SYMBOL_GPL(dccp_ioctl);

0 commit comments

Comments
 (0)