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