socket_send6.c (859B)
1 /* ISC license. */ 2 3 #include <skalibs/nonposix.h> 4 5 #include <string.h> 6 #include <errno.h> 7 #include <sys/socket.h> 8 #include <netinet/in.h> 9 10 #include <skalibs/uint16.h> 11 #include <skalibs/ip46.h> 12 #include <skalibs/socket.h> 13 14 #ifdef SKALIBS_IPV6_ENABLED 15 16 ssize_t socket_send6 (int s, char const *buf, size_t len, char const *ip6, uint16_t port) 17 { 18 ssize_t r ; 19 struct sockaddr_in6 sa ; 20 memset(&sa, 0, sizeof sa) ; 21 sa.sin6_family = AF_INET6 ; 22 sa.sin6_port = uint16_big(port) ; 23 memcpy(sa.sin6_addr.s6_addr, ip6, 16) ; 24 do r = sendto(s, buf, len, 0, (struct sockaddr *)&sa, sizeof sa) ; 25 while ((r == -1) && (errno == EINTR)) ; 26 return r ; 27 } 28 29 #else 30 31 ssize_t socket_send6 (int s, char const *buf, size_t len, char const *ip6, uint16_t port) 32 { 33 (void)s ; 34 (void)buf ; 35 (void)len ; 36 (void)ip6 ; 37 (void)port ; 38 return (errno = ENOSYS, -1) ; 39 } 40 41 #endif