socket_recv6.c (836B)
1 /* ISC license. */ 2 3 #include <skalibs/nonposix.h> 4 5 #include <sys/socket.h> 6 #include <netinet/in.h> 7 #include <errno.h> 8 #include <string.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_recv6 (int s, char *buf, size_t len, char *ip6, uint16_t *port) 17 { 18 struct sockaddr_in6 sa ; 19 socklen_t dummy = sizeof sa ; 20 ssize_t r ; 21 do r = recvfrom(s, buf, len, 0, (struct sockaddr *)&sa, &dummy) ; 22 while ((r == -1) && (errno == EINTR)) ; 23 if (r == -1) return -1 ; 24 memcpy(ip6, sa.sin6_addr.s6_addr, 16) ; 25 *port = uint16_big(sa.sin6_port) ; 26 return r ; 27 } 28 29 #else 30 31 ssize_t socket_recv6 (int s, char *buf, size_t len, char *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