about summary refs log tree commit diff
path: root/src/headers/ip46-header
blob: 82c5e8169dcb7c1749ba8e39d7e0e8ed67aab733 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* ISC license. */

#ifndef SKALIBS_IP46_H
#define SKALIBS_IP46_H

#include <string.h>
#include <stdint.h>
#include <errno.h>

#include <skalibs/fmtscan.h>
#include <skalibs/socket.h>

#define IP46_FMT IP6_FMT
#define IP4_ANY "\0\0\0"
#define IP6_ANY "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
#define IP4_LOCAL "\177\0\0\1"
#define IP6_LOCAL "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1"

typedef struct ip46full_s ip46full, *ip46full_ref ;

struct ip46full_s
{
  char ip[16] ;
  unsigned int is6: 1 ;
} ;
#define IP46FULL_ZERO { .ip = IP6_ANY, .is6 = 0 }

#define ip46full_is6(i) ((i)->is6)
#define ip46full_fmt(s, i) ((i)->is6 ? ip6_fmt(s, (i)->ip) : ip4_fmt(s, (i)->ip))
extern size_t ip46full_scan (char const *, ip46full *) ;
extern size_t ip46full_scanlist (ip46full *, size_t, char const *, size_t *) ;
#define ip46full_from_ip4(i, ip4) (memcpy((i)->ip, ip4, 4), memset((i)->ip + 4, 0, 12), (i)->is6 = 0)
#define ip46full_from_ip6(i, ip6) (memcpy((i)->ip, ip6, 16), (i)->is6 = 1)