EDGESEC  0.1.0-alpha.0+sha.ca29a8277b72f80785649ea9ef9cd7edf642d939
Secure router - reference implementation
Macros | Functions
net.h File Reference

File containing the definition of the network utilities. More...

#include <stdbool.h>
#include <netinet/in.h>
#include <inttypes.h>
#include <net/ethernet.h>
#include <utarray.h>
#include <uthash.h>
#include "allocs.h"
#include "os.h"
Include dependency graph for net.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define IP_ALEN   4
 
#define OS_INET_ADDRSTRLEN   22
 
#define OS_INET6_ADDRSTRLEN   63
 
#define MAC2STR(a)   (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
 
#define MACSTR   "%02x:%02x:%02x:%02x:%02x:%02x"
 
#define MACSTR_LEN   18
 
#define COMPACT_MACSTR   "%02x%02x%02x%02x%02x%02x"
 
#define COMPACT_MACSTR_LEN   13
 
#define IP2STR(a)   (a)[0], (a)[1], (a)[2], (a)[3]
 
#define IPSTR   "%d.%d.%d.%d"
 
#define IP62STR(a)
 
#define IP6STR    "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x"
 
#define hwaddr_aton2(txt, addr)   edge_hwaddr_aton2((txt), (addr))
 

Functions

bool validate_ipv4_string (const char *ip)
 Checks whether a string denotes a IPv4 address. More...
 
int ip_2_nbo (const char *ip, const char *subnetMask, in_addr_t *addr)
 IP string to struct in_addr_t converter. More...
 
int ip4_2_buf (const char *ip, uint8_t buf[static IP_ALEN])
 IP string to buffer. More...
 
const char * bit32_2_ip (uint32_t addr, char ip[static OS_INET_ADDRSTRLEN])
 Convert a 32 bit number IP to an IP string. More...
 
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. More...
 
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. More...
 
uint8_t get_short_subnet (const char *subnet_mask)
 Convert from a string subnet mask to a short integer version. More...
 
int get_ip_host (const char *ip, const char *subnet_mask, uint32_t *host)
 Get the host identifier from an IP address string. More...
 
int disable_pmtu_discovery (int sock)
 Disable the PMTU discovery for sockets. More...
 
int edge_hwaddr_aton2 (const char *txt, uint8_t *addr)
 Convert ASCII string to MAC address (in any known format) More...
 

Detailed Description

File containing the definition of the network utilities.

Author
Alexandru Mereacre
Date
2022

Macro Definition Documentation

◆ COMPACT_MACSTR

#define COMPACT_MACSTR   "%02x%02x%02x%02x%02x%02x"

◆ COMPACT_MACSTR_LEN

#define COMPACT_MACSTR_LEN   13

◆ hwaddr_aton2

#define hwaddr_aton2 (   txt,
  addr 
)    edge_hwaddr_aton2((txt), (addr))

◆ IP2STR

#define IP2STR (   a)    (a)[0], (a)[1], (a)[2], (a)[3]

◆ IP62STR

#define IP62STR (   a)
Value:
(a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5], (a)[6], (a)[7], (a)[8], \
(a)[9], (a)[10], (a)[11], (a)[12], (a)[13], (a)[14], (a)[15]

◆ IP6STR

#define IP6STR    "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x"

◆ IP_ALEN

#define IP_ALEN   4

◆ IPSTR

#define IPSTR   "%d.%d.%d.%d"

◆ MAC2STR

#define MAC2STR (   a)    (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]

◆ MACSTR

#define MACSTR   "%02x:%02x:%02x:%02x:%02x:%02x"

◆ MACSTR_LEN

#define MACSTR_LEN   18

◆ OS_INET6_ADDRSTRLEN

#define OS_INET6_ADDRSTRLEN   63

◆ OS_INET_ADDRSTRLEN

#define OS_INET_ADDRSTRLEN   22

Function Documentation

◆ bit32_2_ip()

const char* bit32_2_ip ( uint32_t  addr,
char  ip[static OS_INET_ADDRSTRLEN] 
)

Convert a 32 bit number IP to an IP string.

Parameters
addrThe IP in 32 bit format
[out]ipThe output buffer to store the IP. Must be at least OS_INET_ADDRSTRLEN chars long.
Returns
Pointer to the returned IP (same as ip on success)
Return values
NULLon error (see errno).

◆ disable_pmtu_discovery()

int disable_pmtu_discovery ( int  sock)

Disable the PMTU discovery for sockets.

Parameters
[in]sockThe socket descriptor
Returns
0 on success, -1 on failure

◆ edge_hwaddr_aton2()

int edge_hwaddr_aton2 ( const char *  txt,
uint8_t *  addr 
)

Convert ASCII string to MAC address (in any known format)

Authors
Jouni Malinen j@w1..nosp@m.fi and wpa_supplicant contributors
Date
2003-2019
See also
https://w1.fi/wpa_supplicant/devel/common_8h.html#ab7ec8839c8e817e241c52ad7a0299be3
Parameters
[in]txtMAC address as a string (e.g., 00:11:22:33:44:55 or 0011.2233.4455)
[out]addrBuffer for the MAC address (ETHER_ADDR_LEN = 6 bytes)
Returns
int Characters used (> 0) on success, -1 on failure

◆ get_ip_host()

int get_ip_host ( const char *  ip,
const char *  subnet_mask,
uint32_t *  host 
)

Get the host identifier from an IP address string.

Parameters
ipThe IP address string
subnet_maskThe subnet mask string
[out]hostThe returned host indentifier
Returns
0 on success, -1 on failure

◆ get_short_subnet()

uint8_t get_short_subnet ( const char *  subnet_mask)

Convert from a string subnet mask to a short integer version.

Parameters
subnet_maskThe subnet mask string
Returns
The short integer version subnet mask

◆ inaddr4_2_ip()

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.

Parameters
addrThe in_addr encoded IP
[out]ipThe output buffer to store the IP. Must be at least OS_INET_ADDRSTRLEN chars long.
Returns
Pointer to the returned IP (same as ip on success)
Return values
NULLon error (see errno).

◆ inaddr6_2_ip()

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.

Parameters
addrThe in6_addr encoded IP
[out]ipThe output buffer to store the IP. Must be at least OS_INET6_ADDRSTRLEN chars long.
Returns
Pointer to the returned IP (same as ip on success)
Return values
NULLon error (see errno).

◆ ip4_2_buf()

int ip4_2_buf ( const char *  ip,
uint8_t  buf[static IP_ALEN] 
)

IP string to buffer.

Parameters
ipThe IP address string
[out]bufThe output buffer of size IP_ALEN
Returns
0 on success, -1 on failure

◆ ip_2_nbo()

int ip_2_nbo ( const char *  ip,
const char *  subnetMask,
in_addr_t *  addr 
)

IP string to struct in_addr_t converter.

Parameters
ipThe IP address string
subnetMaskThe IP address subnet mask
[out]addrThe output struct in_addr_t value
Returns
0 on success, -1 on failure

◆ validate_ipv4_string()

bool validate_ipv4_string ( const char *  ip)

Checks whether a string denotes a IPv4 address.

Parameters
ipThe IP in fromat x.y.z.q
Returns
true if the string is an IP, false otherwise