skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

socket_bind6.c (681B)


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