trafgen: parser: Unify proto field value parsing
[netsniff-ng-new.git] / corking.c
blobd37409fb6e763ea160fe236606add757bad66bc1
1 #include <sys/types.h>
2 #include <sys/socket.h>
3 #include <linux/udp.h>
4 #include <linux/tcp.h>
5 #include <linux/in.h>
7 #include "corking.h"
8 #include "die.h"
10 void set_udp_cork(int fd)
12 int ret, state = 1;
14 ret = setsockopt(fd, IPPROTO_UDP, UDP_CORK, &state, sizeof(state));
15 if (unlikely(ret))
16 panic("Cannot cork UDP socket!\n");
19 void set_udp_uncork(int fd)
21 int ret, state = 0;
23 ret = setsockopt(fd, IPPROTO_UDP, UDP_CORK, &state, sizeof(state));
24 if (unlikely(ret))
25 panic("Cannot uncork UDP socket!\n");
28 void set_tcp_cork(int fd)
30 int ret, state = 1;
32 ret = setsockopt(fd, IPPROTO_TCP, TCP_CORK, &state, sizeof(state));
33 if (unlikely(ret))
34 panic("Cannot cork TCP socket!\n");
37 void set_tcp_uncork(int fd)
39 int ret, state = 0;
41 ret = setsockopt(fd, IPPROTO_TCP, TCP_CORK, &state, sizeof(state));
42 if (unlikely(ret))
43 panic("Cannot uncork TCP socket!\n");
46 void set_sock_cork(int fd, bool is_udp)
48 if (is_udp)
49 set_udp_cork(fd);
50 else
51 set_tcp_cork(fd);
54 void set_sock_uncork(int fd, bool is_udp)
56 if (is_udp)
57 set_udp_uncork(fd);
58 else
59 set_tcp_uncork(fd);