forked from dancrossnyc/44ripd
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlib.h
58 lines (51 loc) · 1.62 KB
/
lib.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
#ifndef RIPD_LIB_H
#define RIPD_LIB_H
#include <arpa/inet.h>
#include <inttypes.h>
#include <stdbool.h>
typedef struct Bitvec Bitvec;
typedef struct IPMap IPMap;
typedef struct RIPPacket RIPPacket;
typedef struct RIPResponse RIPResponse;
/*
* We use a bit vector to keep track of allocated interfaces.
*/
struct Bitvec {
uint64_t *words;
size_t nwords;
size_t firstclr;
};
/*
* A PATRICIA trie mapping CIDR network numbers to a datum.
* The central data structure for maintaining lookup tables
* of active routes and tunnels.
*/
struct IPMap {
uint32_t key;
size_t keylen;
void *datum;
IPMap *left;
IPMap *right;
};
bool isvalidnetmask(uint32_t netmask);
int netmask2cidr(uint32_t netmask);
uint32_t revbits(uint32_t w);
IPMap *mkipmap(void);
void freeipmap(IPMap *map, void (*freedatum)(void *));
void ipmapdo(IPMap *map, int (*thunk)(uint32_t key, size_t keylen, void *datum, void *arg), void *arg);
void ipmapdotopdown(IPMap *map, int (*thunk)(uint32_t key, size_t keylen, void *datum, void *arg), void *arg);
void *ipmapinsert(IPMap *map, uint32_t key, size_t keylen, void *datum);
void *ipmapremove(IPMap *map, uint32_t key, size_t keylen);
void *ipmapnearest(IPMap *map, uint32_t key, size_t keylen);
void *ipmapfind(IPMap *map, uint32_t key, size_t keylen);
void ipaddrstr(uint32_t addr, char buf[static INET_ADDRSTRLEN]);
Bitvec *mkbitvec(void);
void freebitvec(Bitvec *bits);
int bitget(const Bitvec *bits, size_t bit);
void bitset(Bitvec *bits, size_t bit);
void bitclr(Bitvec *bits, size_t bit);
size_t nextbit(Bitvec *bits);
#ifdef USE_COMPAT
void *reallocarray(void *p, size_t nelem, size_t size);
#endif // USE_COMPAT
#endif