EDGESEC
0.1.0-alpha.0+sha.ca29a8277b72f80785649ea9ef9cd7edf642d939
Secure router - reference implementation
|
#include <stdlib.h>
#include <errno.h>
#include <limits.h>
#include "../utils/log.h"
#include "../utils/net.h"
#include "./dhcp_config_utils.h"
Macros | |
#define | CAT(a, ...) PRIMITIVE_CAT(a, __VA_ARGS__) |
#define | PRIMITIVE_CAT(a, ...) a##__VA_ARGS__ |
#define | DEC(x) PRIMITIVE_CAT(DEC_, x) |
#define | DEC_0 0 |
#define | DEC_1 0 |
#define | DEC_2 1 |
#define | DEC_3 2 |
#define | DEC_4 3 |
#define | DEC_5 4 |
#define | DEC_6 5 |
#define | DEC_7 6 |
#define | DEC_8 7 |
#define | DEC_9 8 |
#define | DEC_10 9 |
#define | DEC_11 10 |
#define | DEC_12 11 |
#define | DEC_13 12 |
#define | DEC_14 13 |
#define | DEC_15 14 |
#define | DEC_16 15 |
#define | DEC_17 16 |
#define | DEC_18 17 |
#define | DEC_19 18 |
#define | DEC_20 19 |
#define | DEC_21 20 |
#define | DEC_22 21 |
#define | STR(x) #x |
#define | XSTR(s) STR(s) |
#define | SCANF_IPv4_STRING "%" XSTR(DEC(OS_INET_ADDRSTRLEN)) "[0123456789.]" |
#define | SCANF_DHCP_LEASE_TIME_STRING "%" XSTR(DEC(DHCP_LEASE_TIME_SIZE)) "s" |
Functions | |
bool | get_config_dhcpinfo (const char *info, config_dhcpinfo_t *el) |
Creates a config_dhcpinfo_t from a string. More... | |
#define CAT | ( | a, | |
... | |||
) | PRIMITIVE_CAT(a, __VA_ARGS__) |
#define DEC | ( | x | ) | PRIMITIVE_CAT(DEC_, x) |
Decrements the given number using the forbidden magicks of the C preprocessor.
Currently only works for numbers up to 22, but you can add more defines for more numbers if you want.
Boost has a preprocessor
library that can do this too, see https://www.boost.org/doc/libs/1_81_0/libs/preprocessor/doc/index.html.
#define DEC_0 0 |
#define DEC_1 0 |
#define DEC_10 9 |
#define DEC_11 10 |
#define DEC_12 11 |
#define DEC_13 12 |
#define DEC_14 13 |
#define DEC_15 14 |
#define DEC_16 15 |
#define DEC_17 16 |
#define DEC_18 17 |
#define DEC_19 18 |
#define DEC_2 1 |
#define DEC_20 19 |
#define DEC_21 20 |
#define DEC_22 21 |
#define DEC_3 2 |
#define DEC_4 3 |
#define DEC_5 4 |
#define DEC_6 5 |
#define DEC_7 6 |
#define DEC_8 7 |
#define DEC_9 8 |
#define PRIMITIVE_CAT | ( | a, | |
... | |||
) | a##__VA_ARGS__ |
#define SCANF_DHCP_LEASE_TIME_STRING "%" XSTR(DEC(DHCP_LEASE_TIME_SIZE)) "s" |
scanf() specifier to read a dnsmasq
dhcp lease time (i.e. 24h
)
#define SCANF_IPv4_STRING "%" XSTR(DEC(OS_INET_ADDRSTRLEN)) "[0123456789.]" |
scanf() specifier to read an IPv4 address in dot-separated decimal notation.
#define STR | ( | x | ) | #x |
#define XSTR | ( | s | ) | STR(s) |
bool get_config_dhcpinfo | ( | const char * | info, |
config_dhcpinfo_t * | el | ||
) |
Creates a config_dhcpinfo_t
from a string.
[in] | info | - The string to parse. The format of this string is a comma-separated value line of: <vlanid>,<ip_addr_low>,<ip_addr_upp>,<subnet_mask>,<lease_time> |
vlanid
must be a decimal integer.
All other parameters are passed as a dhcp-range
option to dnsmasq, see man dnsmasq(8)
.
For example: 0,10.0.0.2,10.0.0.254,255.255.255.0,24h
.
[out] | el | - The parsed dhcp info. |
true | On success. |
false | On failure. |