forked from fritz0705/dhcpd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.h
56 lines (46 loc) · 1.08 KB
/
config.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
#pragma once
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdbool.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include "argv.h"
struct config
{
struct argv *argv;
const char *error;
struct in_addr *routers;
size_t routers_cnt;
struct in_addr *nameservers;
size_t nameservers_cnt;
struct in_addr iprange[2];
uint32_t leasetime;
uint8_t prefixlen;
};
#define CONFIG_EMPTY {\
.argv = NULL,\
.routers = NULL,\
.routers_cnt = 0,\
.nameservers = NULL,\
.nameservers_cnt = 0,\
.iprange = {{0}, {0}},\
.leasetime = 3600,\
.prefixlen = 24\
}
/**
* Fill configuration struct from argv struct
*
* @param[out] cfg Destination struct config to write information
* @param[in] argv Source argv struct
*/
extern bool config_fill(struct config *cfg, struct argv *argv);
/**
* Free any with a configuration struct related memory areas
*/
static inline void config_free(struct config *cfg)
{
if (cfg->routers)
cfg->routers = realloc(cfg->routers, cfg->routers_cnt = 0);
if (cfg->nameservers)
cfg->nameservers = realloc(cfg->nameservers, cfg->nameservers_cnt = 0);
}