forked from yaosj2k/dnsforwarder
-
Notifications
You must be signed in to change notification settings - Fork 9
/
ipchunk.h
executable file
·60 lines (47 loc) · 1.5 KB
/
ipchunk.h
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef IPCHUNK_H_INCLUDED
#define IPCHUNK_H_INCLUDED
#include "bst.h"
#include "stablebuffer.h"
#include "common.h"
typedef struct _IpAddr {
unsigned char Addr[16]; /* Both v4 and v6. In big-endian order. */
const char *Zone;
} IpAddr;
typedef struct _IpPort {
IpAddr Ip;
uint16_t Port;
} IpPort;
typedef struct _IpSet {
IpAddr Ip;
int PrefixBits;
} IpSet;
int IpAddr_BitLength(const IpAddr *ipAddr);
int IpAddr_Is6(const IpAddr *ipAddr);
int IpAddr_HasZone(const IpAddr *ipAddr);
int IpAddr_IsValid(const IpAddr *ipAddr);
void IpAddr_From4(const unsigned char Addr[4], IpAddr *ipAddr);
void IpAddr_From6(const unsigned char Addr[16], IpAddr *ipAddr);
int IpAddr_Parse(const char *s, IpAddr *ipAddr);
BOOL IpSet_IsSingleIp(const IpSet *ipSet);
int IpSet_Parse(const char *s, const char *p, IpSet *ipSet);
typedef struct _IpElement {
IpSet IpSet;
int Type;
void *Data;
} IpElement;
typedef struct _IpChunk{
Bst AddrChunk;
Bst CidrChunk;
StableBuffer Datas;
StableBuffer Extra;
} IpChunk;
void IpChunk_Free(IpChunk *ic);
int IpChunk_Init(IpChunk *ic);
int IpChunk_Add(IpChunk *ic,
const char *Ip,
int Type,
const void *Data,
uint32_t DataLength
);
BOOL IpChunk_Find(IpChunk *ic, unsigned char *Ip, int IpBytes, int *Type, const char **Data);
#endif /* IPCHUNK_H_INCLUDED */