skalibs

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

ip46-header (996B)


      1 /* ISC license. */
      2 
      3 #ifndef SKALIBS_IP46_H
      4 #define SKALIBS_IP46_H
      5 
      6 #include <sys/types.h>
      7 #include <stdint.h>
      8 #include <errno.h>
      9 
     10 #include <skalibs/fmtscan.h>
     11 #include <skalibs/tai.h>
     12 #include <skalibs/socket.h>
     13 
     14 #define IP46_FMT IP6_FMT
     15 #define IP4_ANY "\0\0\0"
     16 #define IP6_ANY "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
     17 #define IP4_LOCAL "\177\0\0\1"
     18 #define IP6_LOCAL "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1"
     19 
     20 typedef struct ip46full_s ip46full, *ip46full_ref ;
     21 
     22 struct ip46full_s
     23 {
     24   char ip[16] ;
     25   unsigned int is6: 1 ;
     26 } ;
     27 #define IP46FULL_ZERO { .ip = IP6_ANY, .is6 = 0 }
     28 
     29 #define ip46full_is6(i) ((i)->is6)
     30 #define ip46full_fmt(s, i) ((i)->is6 ? ip6_fmt(s, (i)->ip) : ip4_fmt(s, (i)->ip))
     31 extern size_t ip46full_scan (char const *, ip46full *) ;
     32 extern size_t ip46full_scanlist (ip46full *, size_t, char const *, size_t *) ;
     33 #define ip46full_from_ip4(i, ip4) (memcpy((i)->ip, ip4, 4), memset((i)->ip + 4, 0, 12), (i)->is6 = 0)
     34 #define ip46full_from_ip6(i, ip6) (memcpy((i)->ip, ip6, 16), (i)->is6 = 1)
     35