diff options
Diffstat (limited to 'nacl/curvecp/socket_udp.c')
-rw-r--r-- | nacl/curvecp/socket_udp.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/nacl/curvecp/socket_udp.c b/nacl/curvecp/socket_udp.c new file mode 100644 index 00000000..f64762f1 --- /dev/null +++ b/nacl/curvecp/socket_udp.c | |||
@@ -0,0 +1,36 @@ | |||
1 | #include <unistd.h> | ||
2 | #include <fcntl.h> | ||
3 | #include <sys/types.h> | ||
4 | #include <sys/socket.h> | ||
5 | #include <netinet/in.h> | ||
6 | #include "socket.h" | ||
7 | #include "blocking.h" | ||
8 | |||
9 | static void enable_bsd_fragmentation(int fd) | ||
10 | { | ||
11 | #ifdef IP_DONTFRAG | ||
12 | const int x = 0; | ||
13 | setsockopt(fd,SOL_IP,IP_DONTFRAG,&x,sizeof x); | ||
14 | #endif | ||
15 | } | ||
16 | |||
17 | static void enable_linux_fragmentation(int fd) | ||
18 | { | ||
19 | #ifdef IP_MTU_DISCOVER | ||
20 | #ifdef IP_PMTUDISC_DONT | ||
21 | const int x = IP_PMTUDISC_DONT; | ||
22 | setsockopt(fd,SOL_IP,IP_MTU_DISCOVER,&x,sizeof x); | ||
23 | #endif | ||
24 | #endif | ||
25 | } | ||
26 | |||
27 | int socket_udp(void) | ||
28 | { | ||
29 | int fd = socket(PF_INET,SOCK_DGRAM,0); | ||
30 | if (fd == -1) return -1; | ||
31 | fcntl(fd,F_SETFD,1); | ||
32 | blocking_disable(fd); | ||
33 | enable_bsd_fragmentation(fd); | ||
34 | enable_linux_fragmentation(fd); | ||
35 | return fd; | ||
36 | } | ||