EDGESEC  0.1.0-alpha.0+sha.ca29a8277b72f80785649ea9ef9cd7edf642d939
Secure router - reference implementation
net.h
Go to the documentation of this file.
1 
11 #ifndef NET_H_
12 #define NET_H_
13 
14 #include <stdbool.h>
15 #include <netinet/in.h>
16 #include <inttypes.h>
17 #include <net/ethernet.h>
18 
19 #include <utarray.h>
20 #include <uthash.h>
21 #include "allocs.h"
22 #include "os.h"
23 
24 #define IP_ALEN 4
25 #define OS_INET_ADDRSTRLEN 22
26 #define OS_INET6_ADDRSTRLEN 63
27 
28 #ifndef MAC2STR
29 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
30 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
31 #define MACSTR_LEN 18 // Including the '\0' character
32 /*
33  * Compact form for string representation of MAC address
34  * To be used, e.g., for constructing dbus paths for P2P Devices
35  */
36 #define COMPACT_MACSTR "%02x%02x%02x%02x%02x%02x"
37 #define COMPACT_MACSTR_LEN 13 // Including the '\0' character
38 #endif
39 
40 #ifndef IP2STR
41 #define IP2STR(a) (a)[0], (a)[1], (a)[2], (a)[3]
42 #define IPSTR "%d.%d.%d.%d"
43 #endif
44 
45 #ifndef IP62STR
46 #define IP62STR(a) \
47  (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5], (a)[6], (a)[7], (a)[8], \
48  (a)[9], (a)[10], (a)[11], (a)[12], (a)[13], (a)[14], (a)[15]
49 #define IP6STR \
50  "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x"
51 #endif
52 
59 bool validate_ipv4_string(const char *ip);
60 
69 int ip_2_nbo(const char *ip, const char *subnetMask, in_addr_t *addr);
70 
78 int ip4_2_buf(const char *ip, uint8_t buf[static IP_ALEN]);
79 
89 const char *bit32_2_ip(uint32_t addr, char ip[static OS_INET_ADDRSTRLEN]);
90 
100 const char *inaddr4_2_ip(const struct in_addr *addr,
101  char ip[static OS_INET_ADDRSTRLEN]);
102 
112 const char *inaddr6_2_ip(const struct in6_addr *addr,
113  char ip[static OS_INET6_ADDRSTRLEN]);
114 
121 uint8_t get_short_subnet(const char *subnet_mask);
122 
131 int get_ip_host(const char *ip, const char *subnet_mask, uint32_t *host);
132 
139 int disable_pmtu_discovery(int sock);
140 
155 int edge_hwaddr_aton2(const char *txt, uint8_t *addr);
156 
157 #define hwaddr_aton2(txt, addr) edge_hwaddr_aton2((txt), (addr))
158 
159 #endif
File containing the definition of the allocs functionalities.
#define OS_INET_ADDRSTRLEN
Definition: net.h:25
const char * inaddr4_2_ip(const struct in_addr *addr, char ip[static OS_INET_ADDRSTRLEN])
Convert the in_addr encoded IP4 address to an IP string.
Definition: net.c:129
#define OS_INET6_ADDRSTRLEN
Definition: net.h:26
int ip4_2_buf(const char *ip, uint8_t buf[static IP_ALEN])
IP string to buffer.
Definition: net.c:90
int get_ip_host(const char *ip, const char *subnet_mask, uint32_t *host)
Get the host identifier from an IP address string.
Definition: net.c:160
const char * inaddr6_2_ip(const struct in6_addr *addr, char ip[static OS_INET6_ADDRSTRLEN])
Convert the in6_addr encoded IP6 address to an IP string.
Definition: net.c:134
bool validate_ipv4_string(const char *ip)
Checks whether a string denotes a IPv4 address.
Definition: net.c:27
uint8_t get_short_subnet(const char *subnet_mask)
Convert from a string subnet mask to a short integer version.
Definition: net.c:139
int ip_2_nbo(const char *ip, const char *subnetMask, in_addr_t *addr)
IP string to struct in_addr_t converter.
Definition: net.c:67
int edge_hwaddr_aton2(const char *txt, uint8_t *addr)
Convert ASCII string to MAC address (in any known format)
Definition: net.c:202
#define IP_ALEN
Definition: net.h:24
int disable_pmtu_discovery(int sock)
Disable the PMTU discovery for sockets.
Definition: net.c:181
const char * bit32_2_ip(uint32_t addr, char ip[static OS_INET_ADDRSTRLEN])
Convert a 32 bit number IP to an IP string.
Definition: net.c:122
File containing the definition of the os functionalities.