skalibs

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

socket_connect6.c (817B)


      1 /* ISC license. */
      2 
      3 #include <skalibs/nonposix.h>
      4 
      5 #include <sys/socket.h>
      6 #include <netinet/in.h>
      7 #include <string.h>
      8 #include <errno.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_connect6 (int s, char const *ip6, uint16_t port)
     17 {
     18   struct sockaddr_in6 sa ;
     19   int r ;
     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 = connect(s, (struct sockaddr *)&sa, sizeof sa) ;
     25   while ((r == -1) && (errno == EINTR)) ;
     26   if ((r == -1) && (errno == EALREADY)) errno = EINPROGRESS ;
     27   return r ;
     28 }
     29 
     30 #else
     31 
     32 int socket_connect6 (int s, char const *ip6, uint16_t port)
     33 {
     34   (void)s ;
     35   (void)ip6 ;
     36   (void)port ;
     37   return (errno = ENOSYS, -1) ;
     38 }
     39 
     40 #endif