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