ifpps: Remove unused 'forks' member from struct ifstat
[netsniff-ng.git] / corking.c
blobce10324376b72c152d1d5467b66f6d863cfe4158
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2009, 2010 Daniel Borkmann.
4 * Subject to the GPL, version 2.
5 */
7 #include <sys/types.h>
8 #include <sys/socket.h>
9 #include <linux/udp.h>
10 #include <linux/tcp.h>
11 #include <linux/in.h>
13 #include "corking.h"
14 #include "die.h"
16 void set_udp_cork(int fd)
18 int ret, state = 1;
20 ret = setsockopt(fd, IPPROTO_UDP, UDP_CORK, &state, sizeof(state));
21 if (unlikely(ret))
22 panic("Cannot cork UDP socket!\n");
25 void set_udp_uncork(int fd)
27 int ret, state = 0;
29 ret = setsockopt(fd, IPPROTO_UDP, UDP_CORK, &state, sizeof(state));
30 if (unlikely(ret))
31 panic("Cannot uncork UDP socket!\n");
34 void set_tcp_cork(int fd)
36 int ret, state = 1;
38 ret = setsockopt(fd, IPPROTO_TCP, TCP_CORK, &state, sizeof(state));
39 if (unlikely(ret))
40 panic("Cannot cork TCP socket!\n");
43 void set_tcp_uncork(int fd)
45 int ret, state = 0;
47 ret = setsockopt(fd, IPPROTO_TCP, TCP_CORK, &state, sizeof(state));
48 if (unlikely(ret))
49 panic("Cannot uncork TCP socket!\n");
52 void set_sock_cork(int fd, bool is_udp)
54 if (is_udp)
55 set_udp_cork(fd);
56 else
57 set_tcp_cork(fd);
60 void set_sock_uncork(int fd, bool is_udp)
62 if (is_udp)
63 set_udp_uncork(fd);
64 else
65 set_tcp_uncork(fd);