EDGESEC  0.1.0-alpha.0+sha.ca29a8277b72f80785649ea9ef9cd7edf642d939
Secure router - reference implementation
Macros | Functions
dhcp_config_utils.c File Reference
#include <stdlib.h>
#include <errno.h>
#include <limits.h>
#include "../utils/log.h"
#include "../utils/net.h"
#include "./dhcp_config_utils.h"
Include dependency graph for dhcp_config_utils.c:

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...
 

Macro Definition Documentation

◆ CAT

#define CAT (   a,
  ... 
)    PRIMITIVE_CAT(a, __VA_ARGS__)

◆ DEC

#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.

Author
Paul Fultz II https://github.com/pfultz2/Cloak
Remarks
Adapted from https://github.com/pfultz2/Cloak/blob/master/cloak.h

◆ DEC_0

#define DEC_0   0

◆ DEC_1

#define DEC_1   0

◆ DEC_10

#define DEC_10   9

◆ DEC_11

#define DEC_11   10

◆ DEC_12

#define DEC_12   11

◆ DEC_13

#define DEC_13   12

◆ DEC_14

#define DEC_14   13

◆ DEC_15

#define DEC_15   14

◆ DEC_16

#define DEC_16   15

◆ DEC_17

#define DEC_17   16

◆ DEC_18

#define DEC_18   17

◆ DEC_19

#define DEC_19   18

◆ DEC_2

#define DEC_2   1

◆ DEC_20

#define DEC_20   19

◆ DEC_21

#define DEC_21   20

◆ DEC_22

#define DEC_22   21

◆ DEC_3

#define DEC_3   2

◆ DEC_4

#define DEC_4   3

◆ DEC_5

#define DEC_5   4

◆ DEC_6

#define DEC_6   5

◆ DEC_7

#define DEC_7   6

◆ DEC_8

#define DEC_8   7

◆ DEC_9

#define DEC_9   8

◆ PRIMITIVE_CAT

#define PRIMITIVE_CAT (   a,
  ... 
)    a##__VA_ARGS__

◆ SCANF_DHCP_LEASE_TIME_STRING

#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)

◆ SCANF_IPv4_STRING

#define SCANF_IPv4_STRING   "%" XSTR(DEC(OS_INET_ADDRSTRLEN)) "[0123456789.]"

scanf() specifier to read an IPv4 address in dot-separated decimal notation.

◆ STR

#define STR (   x)    #x

◆ XSTR

#define XSTR (   s)    STR(s)

Function Documentation

◆ get_config_dhcpinfo()

bool get_config_dhcpinfo ( const char *  info,
config_dhcpinfo_t el 
)

Creates a config_dhcpinfo_t from a string.

Parameters
[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.

Parameters
[out]el- The parsed dhcp info.
Return values
trueOn success.
falseOn failure.