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 socket_udp6(void)12int socket_udp6(void) 13 { 14 #ifdef LIBC_HAS_IP6 15 int s; 16 17 if (noipv6) 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 noipv6=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 } 39