socket_udp6.c (655B)
1 /* ISC license. */ 2 3 #include <skalibs/nonposix.h> 4 #include <sys/socket.h> 5 #include <netinet/in.h> 6 #include <errno.h> 7 #include <skalibs/djbunix.h> 8 #include <skalibs/ip46.h> 9 #include <skalibs/socket.h> 10 11 #ifdef SKALIBS_IPV6_ENABLED 12 13 int socket_udp6_internal (unsigned int flags) 14 { 15 int fd = socket_internal(AF_INET6, SOCK_DGRAM, 0, flags) ; 16 if (fd < 0) return fd ; 17 { 18 int option = 1 ; 19 if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &option, sizeof(option)) < 0) 20 { 21 fd_close(fd) ; 22 return -1 ; 23 } 24 } 25 return fd ; 26 } 27 28 #else 29 30 int socket_udp6_internal (unsigned int flags) 31 { 32 (void)flags ; 33 return (errno = ENOSYS, -1) ; 34 } 35 36 #endif