ucspi-ssl  0.99e
TLS encryption for IPv6 communication
socket_udp6.c
Go to the documentation of this file.
1 #include <sys/types.h>
2 #include <sys/socket.h>
3 #include <netinet/in.h>
4 #include <errno.h>
5 #include "haveip6.h"
6 #include "socket.h"
7 
8 #ifndef EAFNOSUPPORT
9 #define EAFNOSUPPORT EINVAL
10 #endif
11 
12 int socket_udp6(void)
13 {
14 #ifdef LIBC_HAS_IP6
15  int s;
16 
17  if (ipv4) goto compat;
18  s = socket(PF_INET6,SOCK_DGRAM,0);
19  if (s == -1) {
20  if (errno == EINVAL || errno == EAFNOSUPPORT) {
21 compat:
22  s=socket(AF_INET,SOCK_DGRAM,0);
23  ipv4=1;
24  if (s==-1) return -1;
25  } else
26  return -1;
27  }
28 #ifdef IPV6_V6ONLY
29  {
30  int zero=0;
31  setsockopt(s,IPPROTO_IPV6,IPV6_V6ONLY,(void*)&zero,sizeof(zero));
32  }
33 #endif
34  return s;
35 #else
36  return socket_udp();
37 #endif
38 }
#define EAFNOSUPPORT
Definition: socket_udp6.c:9
int socket_udp(void)
Definition: socket_udp.c:9
int ipv4
Definition: socket_tcp6.c:15
int socket_udp6(void)
Definition: socket_udp6.c:12