serval-dna/nacl/nacl-20110221/curvecp/socket_udp.c
Daniel O'Connor bf9710fd5a Unpacked nacl-20110221 after processing by nacl-prepare-sources.
This only affects build_android, if nacl-gcc-prep is run then build/`uname -s` will be created.
2012-02-27 12:40:14 +10:30

37 lines
716 B
C

#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "socket.h"
#include "blocking.h"
static void enable_bsd_fragmentation(int fd)
{
#ifdef IP_DONTFRAG
const int x = 0;
setsockopt(fd,SOL_IP,IP_DONTFRAG,&x,sizeof x);
#endif
}
static void enable_linux_fragmentation(int fd)
{
#ifdef IP_MTU_DISCOVER
#ifdef IP_PMTUDISC_DONT
const int x = IP_PMTUDISC_DONT;
setsockopt(fd,SOL_IP,IP_MTU_DISCOVER,&x,sizeof x);
#endif
#endif
}
int socket_udp(void)
{
int fd = socket(PF_INET,SOCK_DGRAM,0);
if (fd == -1) return -1;
fcntl(fd,F_SETFD,1);
blocking_disable(fd);
enable_bsd_fragmentation(fd);
enable_linux_fragmentation(fd);
return fd;
}