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"
Go to the source code of this file.
|
#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)) |
|
File containing the definition of the network utilities.
- Author
- Alexandru Mereacre
- Date
- 2022
- Copyright
- SPDX-FileCopyrightText: © 2022 NQMCyber Ltd and edgesec contributors SPDX-License-Identifier: LGPL-3.0-or-later
◆ COMPACT_MACSTR
#define COMPACT_MACSTR "%02x%02x%02x%02x%02x%02x" |
◆ COMPACT_MACSTR_LEN
#define COMPACT_MACSTR_LEN 13 |
◆ hwaddr_aton2
◆ IP2STR
#define IP2STR |
( |
|
a | ) |
(a)[0], (a)[1], (a)[2], (a)[3] |
◆ IP62STR
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
◆ 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
◆ OS_INET6_ADDRSTRLEN
#define OS_INET6_ADDRSTRLEN 63 |
◆ OS_INET_ADDRSTRLEN
#define OS_INET_ADDRSTRLEN 22 |
◆ 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
-
| addr | The IP in 32 bit format |
[out] | ip | The 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
-
NULL | on error (see errno). |
◆ disable_pmtu_discovery()
int disable_pmtu_discovery |
( |
int |
sock | ) |
|
Disable the PMTU discovery for sockets.
- Parameters
-
[in] | sock | The socket descriptor |
- Returns
- 0 on success, -1 on failure
◆ edge_hwaddr_aton2()
int edge_hwaddr_aton2 |
( |
const char * |
txt, |
|
|
uint8_t * |
addr |
|
) |
| |
◆ 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
-
| ip | The IP address string |
| subnet_mask | The subnet mask string |
[out] | host | The 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_mask | The 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
-
| addr | The in_addr encoded IP |
[out] | ip | The 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
-
NULL | on 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
-
| addr | The in6_addr encoded IP |
[out] | ip | The 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
-
NULL | on error (see errno). |
◆ ip4_2_buf()
int ip4_2_buf |
( |
const char * |
ip, |
|
|
uint8_t |
buf[static IP_ALEN] |
|
) |
| |
IP string to buffer.
- Parameters
-
| ip | The IP address string |
[out] | buf | The 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
-
| ip | The IP address string |
| subnetMask | The IP address subnet mask |
[out] | addr | The 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
-
ip | The IP in fromat x.y.z.q |
- Returns
- true if the string is an IP, false otherwise