mbgtools-lx
4.2.8
|
#include <mbg_tgt.h>
#include <gpsdefs.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <ifaddrs.h>
Go to the source code of this file.
Macros | |
#define | _ext extern |
#define | MAC_SEP_CHAR ':' |
#define | MAC_SEP_CHAR_ALT '-' |
#define | MAX_IP4_BITS ( 8 * (int) sizeof( IP4_ADDR ) ) |
#define | IP4_MSB_MASK ( 1UL << ( MAX_IP4_BITS - 1 ) ) |
#define | MIN_IP4_CIDR_NETMASK_BITS 0 |
#define | MAX_IP4_CIDR_NETMASK_BITS MAX_IP4_BITS |
#define | IP6_MSB_MASK ( 1UL << ( 8 - 1 ) ) |
#define | MIN_IP6_CIDR_NETMASK_BITS 0 |
#define | MAX_IP6_CIDR_NETMASK_BITS IP6_ADDR_BITS |
#define | _ip4_addr_to_str(_s, _a) snprint_ip4_addr( _s, sizeof( _s ), _a, NULL ) |
#define | _mac_addr_to_str(_s, _a) snprint_mac_addr( _s, sizeof( _s ), _a ) |
Functions | |
static __mbg_inline IP4_ADDR | ip4_net_mask_from_cidr (int netmask_bits) |
Compute an IP4 net mask according to the number of CIDR netmask bits. More... | |
static __mbg_inline IP4_ADDR | ip4_broad_addr_from_addr (const IP4_ADDR *p_addr, const IP4_ADDR *p_mask) |
Determine the broadcast address for an IP4 address plus net mask. More... | |
static __mbg_inline IP4_ADDR | ip4_net_part_from_addr (const IP4_ADDR *p_addr, const IP4_ADDR *p_mask) |
Determine the network part of an IP4 address based on the net mask. More... | |
static __mbg_inline int | ip4_net_part_matches (const IP4_ADDR *p_addr1, const IP4_ADDR *p_addr2, const IP4_ADDR *p_mask) |
Check if two IP4 addresses have the same network part. More... | |
int | get_ip4_net_mask_bits (const IP4_ADDR *p_mask) |
Count the number of sequential bits in an IPv4 net mask. More... | |
size_t | snprint_ip4_addr (char *s, size_t max_len, const IP4_ADDR *p_addr, const char *info) |
Print an IPv4 address to a dotted quad formatted string. More... | |
size_t | snprint_ip4_cidr_addr (char *s, size_t max_len, const IP4_ADDR *p_addr, const IP4_ADDR *p_mask, const char *info) |
Print an IPv4 address plus net mask in CIDR notation to a string. More... | |
int | str_to_ip4_addr (IP4_ADDR *p_addr, const char *s) |
Convert a string to an IP4_ADDR. More... | |
int | cidr_str_to_ip4_addr_and_net_mask (IP4_ADDR *p_addr, IP4_ADDR *p_mask, const char *cidr_str) |
Convert a string in CIDR notation to an IP4_ADDR and net mask. More... | |
int | get_ip6_net_mask_bits (const IP6_ADDR *p_mask) |
Count the number of sequential bits in an IPv6 net mask. More... | |
size_t | snprint_ip6_addr (char *s, size_t max_len, const IP6_ADDR *p_addr, const char *info) |
Print an IPv6 address in optimized format to a string. More... | |
size_t | snprint_ip6_cidr_addr (char *s, size_t max_len, const IP6_ADDR *p_addr, const IP6_ADDR *p_mask, const char *info) |
Print an IPv6 address plus net mask to string in CIDR notation. More... | |
size_t | snprint_ip6_cidr_mask_addr (char *s, size_t max_len, const IP6_ADDR *p_addr, const int cidr_mask_bits, const char *info) |
Print an IPv6 address plus number of net mask bits to string in CIDR notation. More... | |
int | str_to_ip6_addr (IP6_ADDR *p_addr, const char *s) |
Convert a string to an IP6_ADDR. More... | |
int | cidr_str_to_ip6_addr_and_net_mask (IP6_ADDR *p_addr, IP6_ADDR *p_mask, const char *cidr_str) |
Convert a string in CIDR notation to an IP6_ADDR and net mask. More... | |
int | cidr_str_to_ip6_addr_and_cidr_bits (IP6_ADDR *p_addr, int *p_cidr, const char *cidr_str) |
Convert a string in CIDR notation to an IP6_ADDR and net mask bits. More... | |
void | ip6_net_mask_from_cidr (IP6_ADDR *p_mask, int netmask_bits) |
Compute an IPv6 net mask according to the number of CIDR netmask bits. More... | |
void | ip6_net_part_from_addr (IP6_ADDR *p_net_part, const IP6_ADDR *p_addr, const IP6_ADDR *p_mask) |
Determine the network part of an IPv6 address based on the net mask. More... | |
size_t | snprint_octets (char *s, size_t max_len, const uint8_t *octets, int num_octets, char sep, const char *info) |
Print a MAC ID or similar array of octets to a string. More... | |
size_t | snprint_ptp_clock_id (char *s, size_t max_len, const PTP_CLOCK_ID *p) |
Print a PTP_CLOCK_ID to a string. More... | |
size_t | snprint_mac_addr (char *s, size_t max_len, const MBG_MAC_ADDR *p_mac_addr) |
Print a MAC address to a string. More... | |
int | str_to_octets (uint8_t *octets, int num_octets, const char *s) |
Set a MAC ID or a similar array of octets from a string. More... | |
bool | octets_are_all_zero (const uint8_t *octets, int num_octets) |
Check if an array of octets is all zero. More... | |
bool | mac_addr_is_all_zero (const MBG_MAC_ADDR *p_addr) |
Check if a MAC address is all zero. More... | |
int | do_siocg_ioctl (const char *if_name, int ioctl_code, struct ifreq *p_ifreq) |
Do a SIOCGxxx IOCTL call to read specific information from a LAN interface. More... | |
int | get_port_intf_idx (const char *if_name, int *p_intf_idx) |
Retrieve the index of a specific network interface. More... | |
int | get_port_mac_addr (const char *if_name, MBG_MAC_ADDR *p_mac_addr) |
Retrieve the MAC address of a network interface. More... | |
int | check_port_link (const char *if_name) |
Check the link state of a network interface. More... | |
int | check_port_status (const char *if_name, int *p_speed, int *p_duplex) |
Check the state of a network interface. More... | |
int | get_port_ip4_addr (const char *if_name, IP4_ADDR *p_addr) |
Retrieve the IPv4 address of a network interface. More... | |
int | get_port_ip4_netmask (const char *if_name, IP4_ADDR *p_addr) |
Retrieve the IPv4 net mask of a network interface. More... | |
int | get_port_ip4_broad_addr (const char *if_name, IP4_ADDR *p_addr) |
Retrieve the IPv4 broadcast address of a network interface. More... | |
int | get_ip4_gateway (IP4_ADDR *p_addr) |
Retrieve the IPv4 gateway (default route) More... | |
int | get_port_ip4_addr_str (const char *if_name, char *p_addr_buf, int buf_size) |
Retrieve the IPv4 address of a network interface as string. More... | |
int | get_port_ip4_netmask_str (const char *if_name, char *p_addr_buf, int buf_size) |
Retrieve the IPv4 net mask of a network interface as string. More... | |
int | get_port_ip4_broad_addr_str (const char *if_name, char *p_addr_buf, int buf_size) |
Retrieve the IPv4 broadcast address of a network interface as string. More... | |
int | get_port_ip4_settings (const char *if_name, IP4_SETTINGS *p) |
Retrieve the current IPv4 settings of a network interface. More... | |
#define _ext extern |
Definition at line 77 of file lan_util.h.
#define _ip4_addr_to_str | ( | _s, | |
_a | |||
) | snprint_ip4_addr( _s, sizeof( _s ), _a, NULL ) |
Definition at line 200 of file lan_util.h.
#define _mac_addr_to_str | ( | _s, | |
_a | |||
) | snprint_mac_addr( _s, sizeof( _s ), _a ) |
Definition at line 203 of file lan_util.h.
#define IP4_MSB_MASK ( 1UL << ( MAX_IP4_BITS - 1 ) ) |
Definition at line 104 of file lan_util.h.
Referenced by get_ip4_net_mask_bits().
#define IP6_MSB_MASK ( 1UL << ( 8 - 1 ) ) |
Definition at line 110 of file lan_util.h.
Referenced by get_ip6_net_mask_bits().
#define MAC_SEP_CHAR ':' |
Definition at line 94 of file lan_util.h.
Referenced by set_ptp_cfg(), show_ptp_cfg(), snprint_mac_addr(), and str_to_octets().
#define MAC_SEP_CHAR_ALT '-' |
Definition at line 98 of file lan_util.h.
Referenced by show_ptp_state(), and str_to_octets().
#define MAX_IP4_BITS ( 8 * (int) sizeof( IP4_ADDR ) ) |
Definition at line 102 of file lan_util.h.
Referenced by get_ip4_net_mask_bits(), and ip4_net_mask_from_cidr().
#define MAX_IP4_CIDR_NETMASK_BITS MAX_IP4_BITS |
Definition at line 107 of file lan_util.h.
Referenced by cidr_str_to_ip4_addr_and_net_mask(), and snprint_ip4_cidr_addr().
#define MAX_IP6_CIDR_NETMASK_BITS IP6_ADDR_BITS |
Definition at line 113 of file lan_util.h.
Referenced by cidr_str_to_ip6_addr_and_cidr_bits(), get_ip6_net_mask_bits(), snprint_ip6_cidr_addr(), and snprint_ip6_cidr_mask_addr().
#define MIN_IP4_CIDR_NETMASK_BITS 0 |
Definition at line 106 of file lan_util.h.
Referenced by cidr_str_to_ip4_addr_and_net_mask(), and snprint_ip4_cidr_addr().
#define MIN_IP6_CIDR_NETMASK_BITS 0 |
Definition at line 112 of file lan_util.h.
Referenced by cidr_str_to_ip6_addr_and_cidr_bits(), snprint_ip6_cidr_addr(), and snprint_ip6_cidr_mask_addr().
int check_port_link | ( | const char * | if_name | ) |
Check the link state of a network interface.
[in] | if_name | Name of the interface |
Definition at line 1267 of file lan_util.c.
References do_siocg_ioctl(), MBG_ERR_NOT_SUPP_ON_OS, and mbg_rc_is_success.
Referenced by get_port_ip4_settings().
int check_port_status | ( | const char * | if_name, |
int * | p_speed, | ||
int * | p_duplex | ||
) |
Check the state of a network interface.
[in] | if_name | Name of the interface to check |
[out] | p_speed | Optional pointer to a variable to take up the link speed, may be NULL |
[out] | p_duplex | Optional pointer to a variable to take up the duplex state, may be NULL |
Definition at line 1302 of file lan_util.c.
References do_siocg_ioctl(), MBG_ERR_NOT_SUPP_ON_OS, and mbg_rc_is_success.
int cidr_str_to_ip4_addr_and_net_mask | ( | IP4_ADDR * | p_addr, |
IP4_ADDR * | p_mask, | ||
const char * | cidr_str | ||
) |
Convert a string in CIDR notation to an IP4_ADDR and net mask.
If output parameters are specified as NULL then this function can be used to check if the CIDR string is formally correct.
[out] | p_addr | Pointer to an IP4_ADDR variable to be filled with the IPv4 address, or NULL |
[out] | p_mask | Pointer to an IP4_ADDR variable to be filled with the IPv4 net mask, or NULL |
[in] | cidr_str | The string to be converted, in CIDR format, e.g. "172.16.3.250/24" |
Definition at line 349 of file lan_util.c.
References ip4_net_mask_from_cidr(), MAX_IP4_CIDR_NETMASK_BITS, MBG_ERR_PARM_FMT, MBG_ERR_RANGE, mbg_rc_is_error, MIN_IP4_CIDR_NETMASK_BITS, and str_to_ip4_addr().
int cidr_str_to_ip6_addr_and_cidr_bits | ( | IP6_ADDR * | p_addr, |
int * | p_cidr, | ||
const char * | cidr_str | ||
) |
Convert a string in CIDR notation to an IP6_ADDR and net mask bits.
If output parameters are specified as NULL then this function can be used to check if the CIDR string is formally correct.
[out] | p_addr | Pointer to an IP6_ADDR variable for the IPv6 address, or NULL |
[out] | p_cidr | Pointer to an int variable for the net mask bits, or NULL |
[in] | cidr_str | The string to be converted, in CIDR format, e.g. "2001:0DB8:0:CD30::/64" |
Definition at line 859 of file lan_util.c.
References MAX_IP6_CIDR_NETMASK_BITS, MBG_ERR_PARM_FMT, MBG_ERR_RANGE, mbg_rc_is_error, MIN_IP6_CIDR_NETMASK_BITS, and str_to_ip6_addr().
Referenced by cidr_str_to_ip6_addr_and_net_mask().
int cidr_str_to_ip6_addr_and_net_mask | ( | IP6_ADDR * | p_addr, |
IP6_ADDR * | p_mask, | ||
const char * | cidr_str | ||
) |
Convert a string in CIDR notation to an IP6_ADDR and net mask.
If output parameters are specified as NULL then this function can be used to check if the CIDR string is formally correct.
[out] | p_addr | Pointer to an IP6_ADDR variable to be filled up with the IPv6 address, or NULL |
[out] | p_mask | Pointer to an IP6_ADDR variable to be filled up with the net mask bits, or NULL |
[in] | cidr_str | The string to be converted, in CIDR format, e.g. "2001:0DB8:0:CD30::/64" |
Definition at line 823 of file lan_util.c.
References cidr_str_to_ip6_addr_and_cidr_bits(), ip6_net_mask_from_cidr(), and mbg_rc_is_error.
int do_siocg_ioctl | ( | const char * | if_name, |
int | ioctl_code, | ||
struct ifreq * | p_ifreq | ||
) |
Do a SIOCGxxx IOCTL call to read specific information from a LAN interface.
[in] | if_name | Name of the interface |
[in] | ioctl_code | One of the predefined system SIOCGxxx IOCTL codes |
[out] | p_ifreq | Pointer to a request buffer |
Definition at line 1155 of file lan_util.c.
References MBG_ERR_PARM_FMT, mbg_get_last_socket_error(), MBG_SUCCESS, and strncpy_safe().
Referenced by check_port_link(), check_port_status(), get_port_intf_idx(), get_port_mac_addr(), and get_specific_port_ip4_addr().
int get_ip4_gateway | ( | IP4_ADDR * | p_addr | ) |
Retrieve the IPv4 gateway (default route)
[out] | p_addr | Pointer to address field to be filled up |
Definition at line 1679 of file lan_util.c.
References route_info::dstAddr, route_info::gateWay, route_info::ifName, MBG_ERR_NOT_SUPP_ON_OS, mbg_get_last_socket_error(), mbg_rc_is_error, mbg_strerror(), MBG_SUCCESS, nl_parse_routes(), nl_read(), snprintf_safe(), and route_info::srcAddr.
Referenced by get_port_ip4_settings().
int get_ip4_net_mask_bits | ( | const IP4_ADDR * | p_mask | ) |
Count the number of sequential bits in an IPv4 net mask.
Counting starts from MSB, i.e. for 0xC0 and 0xC1 the results are both 2 since only the 2 MSBs are sequentially set.
[in] | p_mask | The IPv4 net mask to be evaluated |
Definition at line 183 of file lan_util.c.
References IP4_MSB_MASK, and MAX_IP4_BITS.
Referenced by mbg_get_all_net_cfg_info(), mbg_get_all_net_status_info(), and snprint_ip4_cidr_addr().
int get_ip6_net_mask_bits | ( | const IP6_ADDR * | p_mask | ) |
Count the number of sequential bits in an IPv6 net mask.
Counting starts from MSB, i.e. for 0xC0 and 0xC1 the results are both 2 since only the 2 MSBs are sequentially set.
[in] | p_mask | The IPv6 net mask to be evaluated |
Definition at line 417 of file lan_util.c.
References IP6_ADDR::b, IP6_ADDR_BYTES, IP6_MSB_MASK, and MAX_IP6_CIDR_NETMASK_BITS.
Referenced by snprint_ip6_cidr_addr().
int get_port_intf_idx | ( | const char * | if_name, |
int * | p_intf_idx | ||
) |
Retrieve the index of a specific network interface.
[in] | if_name | Name of the interface |
[out] | p_intf_idx | Pointer to a variable to be filled up |
Definition at line 1197 of file lan_util.c.
References do_siocg_ioctl(), MBG_ERR_NOT_SUPP_ON_OS, and mbg_rc_is_success.
int get_port_ip4_addr | ( | const char * | if_name, |
IP4_ADDR * | p_addr | ||
) |
Retrieve the IPv4 address of a network interface.
[in] | if_name | Name of the interface |
[out] | p_addr | Pointer to address field to be filled up |
Definition at line 1404 of file lan_util.c.
References get_specific_port_ip4_addr().
Referenced by get_port_ip4_addr_str(), and get_port_ip4_settings().
int get_port_ip4_addr_str | ( | const char * | if_name, |
char * | p_addr_buf, | ||
int | buf_size | ||
) |
Retrieve the IPv4 address of a network interface as string.
[in] | if_name | Name of the interface |
[out] | p_addr_buf | Pointer to the string buffer to be filled up |
[in] | buf_size | size of the string buffer |
Definition at line 1826 of file lan_util.c.
References get_port_ip4_addr(), and snprint_ip4_addr().
int get_port_ip4_broad_addr | ( | const char * | if_name, |
IP4_ADDR * | p_addr | ||
) |
Retrieve the IPv4 broadcast address of a network interface.
[in] | if_name | Name of the interface |
[out] | p_addr | Pointer to address field to be filled up |
Definition at line 1456 of file lan_util.c.
References get_specific_port_ip4_addr().
Referenced by get_port_ip4_broad_addr_str(), and get_port_ip4_settings().
int get_port_ip4_broad_addr_str | ( | const char * | if_name, |
char * | p_addr_buf, | ||
int | buf_size | ||
) |
Retrieve the IPv4 broadcast address of a network interface as string.
[in] | if_name | Name of the interface |
[out] | p_addr_buf | Pointer to the string buffer to be filled up |
[in] | buf_size | size of the string buffer |
Definition at line 1892 of file lan_util.c.
References get_port_ip4_broad_addr(), and snprint_ip4_addr().
int get_port_ip4_netmask | ( | const char * | if_name, |
IP4_ADDR * | p_addr | ||
) |
Retrieve the IPv4 net mask of a network interface.
[in] | if_name | Name of the interface |
[out] | p_addr | Pointer to address field to be filled up |
Definition at line 1430 of file lan_util.c.
References get_specific_port_ip4_addr().
Referenced by get_port_ip4_netmask_str(), and get_port_ip4_settings().
int get_port_ip4_netmask_str | ( | const char * | if_name, |
char * | p_addr_buf, | ||
int | buf_size | ||
) |
Retrieve the IPv4 net mask of a network interface as string.
[in] | if_name | Name of the interface |
[out] | p_addr_buf | Pointer to the string buffer to be filled up |
[in] | buf_size | size of the string buffer |
Definition at line 1859 of file lan_util.c.
References get_port_ip4_netmask(), and snprint_ip4_addr().
int get_port_ip4_settings | ( | const char * | if_name, |
IP4_SETTINGS * | p | ||
) |
Retrieve the current IPv4 settings of a network interface.
[in] | if_name | Name of the interface |
[out] | p | Pointer to a IP4_SETTINGS structure to be filled up |
Definition at line 1923 of file lan_util.c.
References IP4_SETTINGS::broad_addr, check_port_link(), IP4_SETTINGS::flags, IP4_SETTINGS::gateway, get_ip4_gateway(), get_port_ip4_addr(), get_port_ip4_broad_addr(), get_port_ip4_netmask(), IP4_MSK_DHCP, IP4_MSK_LINK, IP4_MSK_VLAN, IP4_SETTINGS::ip_addr, mbg_rc_is_error, IP4_SETTINGS::netmask, and IP4_SETTINGS::vlan_cfg.
int get_port_mac_addr | ( | const char * | if_name, |
MBG_MAC_ADDR * | p_mac_addr | ||
) |
Retrieve the MAC address of a network interface.
[in] | if_name | Name of the interface |
[out] | p_mac_addr | Pointer to the MAC address buffer to be filled up |
Definition at line 1232 of file lan_util.c.
References do_siocg_ioctl(), MBG_ERR_NOT_SUPP_ON_OS, and mbg_rc_is_success.
|
static |
Determine the broadcast address for an IP4 address plus net mask.
E.g. IP 0xAC1003FA, net mask 0xFFFFFF00 yields broadcast addr 0xAC1003FF. In dotted quad notation, IP 172.16.3.250 with net mask 255.255.255.0 result in broadcast address 172.16.3.255.
p_addr | The full IP4 address |
p_mask | The IP4 net mask |
Definition at line 151 of file lan_util.h.
Referenced by mbg_save_all_net_cfg_info().
|
static |
Compute an IP4 net mask according to the number of CIDR netmask bits.
E.g. the 24 bits mentioned in "172.16.3.250/24" result in 0xFFFFFF00, corresponding to 255.255.255.0 in dotted quad notation.
netmask_bits | Number of netmask bits from CIDR notation |
Definition at line 130 of file lan_util.h.
References MAX_IP4_BITS.
Referenced by cidr_str_to_ip4_addr_and_net_mask(), and mbg_save_all_net_cfg_info().
|
static |
Determine the network part of an IP4 address based on the net mask.
E.g. IP 0xAC1003FA, net mask 0xFFFFFF00 yields network part 0xAC100300. In dotted quad notation, IP 172.16.3.250 with net mask 255.255.255.0 results in network part 172.16.3.0.
p_addr | The full IP4 address |
p_mask | The IP4 net mask |
Definition at line 172 of file lan_util.h.
Referenced by ip4_net_part_matches().
|
static |
Check if two IP4 addresses have the same network part.
p_addr1 | The first IP4 address to check |
p_addr2 | The second IP4 address to check |
p_mask | The IP4 net mask |
Definition at line 190 of file lan_util.h.
References ip4_net_part_from_addr().
void ip6_net_mask_from_cidr | ( | IP6_ADDR * | p_mask, |
int | netmask_bits | ||
) |
Compute an IPv6 net mask according to the number of CIDR netmask bits.
E.g. the 64 bits mentioned in "2001:0DB8:0:CD30::/64" result in 2^64, corresponding to FFFF:FFFF:FFFF:FFFF:: in IPv6 notation.
[out] | p_mask | Pointer to an IP6_ADDR variable for the IPv6 netmask |
[in] | netmask_bits | Number of netmask bits from CIDR notation |
Definition at line 918 of file lan_util.c.
References IP6_ADDR::b, IP6_ADDR_BITS, and IP6_ADDR_BYTES.
Referenced by cidr_str_to_ip6_addr_and_net_mask(), and snprint_ip6_cidr_mask_addr().
void ip6_net_part_from_addr | ( | IP6_ADDR * | p_net_part, |
const IP6_ADDR * | p_addr, | ||
const IP6_ADDR * | p_mask | ||
) |
Determine the network part of an IPv6 address based on the net mask.
E.g. IP "2001:0DB8:0:CD30::", net mask "FFFF:FFFF::" yields network part "2001:0DB8::".
[out] | p_net_part | The extracted network part of the IPv6 address |
[in] | p_addr | The IPv6 address to be evaluated |
[in] | p_mask | The associated IPv6 net mask |
Definition at line 961 of file lan_util.c.
References IP6_ADDR::b, and IP6_ADDR_BYTES.
bool mac_addr_is_all_zero | ( | const MBG_MAC_ADDR * | p_addr | ) |
Check if a MAC address is all zero.
[in] | p_addr | Pointer to a MAC address to be checked |
Definition at line 1135 of file lan_util.c.
References MBG_MAC_ADDR::b, and octets_are_all_zero().
Check if an array of octets is all zero.
[in] | octets | Pointer to the array of octets |
[in] | num_octets | Number of octets |
Definition at line 1110 of file lan_util.c.
Referenced by mac_addr_is_all_zero().
size_t snprint_ip4_addr | ( | char * | s, |
size_t | max_len, | ||
const IP4_ADDR * | p_addr, | ||
const char * | info | ||
) |
Print an IPv4 address to a dotted quad formatted string.
[out] | s | The string buffer to be filled |
[in] | max_len | Size of the output buffer for 0-terminated string |
[in] | p_addr | The IPv4 address to be evaluated |
[in] | info | An optional string which is prepended to the string, or NULL |
Definition at line 217 of file lan_util.c.
References BYTE_0, BYTE_1, BYTE_2, BYTE_3, and snprintf_safe().
Referenced by get_port_ip4_addr_str(), get_port_ip4_broad_addr_str(), get_port_ip4_netmask_str(), set_lan_intf(), set_ptp_cfg(), show_lan_intf(), show_lan_intf_state(), and snprint_ip4_cidr_addr().
size_t snprint_ip4_cidr_addr | ( | char * | s, |
size_t | max_len, | ||
const IP4_ADDR * | p_addr, | ||
const IP4_ADDR * | p_mask, | ||
const char * | info | ||
) |
Print an IPv4 address plus net mask in CIDR notation to a string.
The printed CIDR string is something like "172.16.3.250/24"
[out] | s | The string buffer to be filled |
[in] | max_len | Size of the output buffer for 0-terminated string |
[in] | p_addr | The IPv4 address to be evaluated |
[in] | p_mask | The associated IPv4 net mask |
[in] | info | An optional string which is prepended to the string, or NULL |
Definition at line 255 of file lan_util.c.
References get_ip4_net_mask_bits(), MAX_IP4_CIDR_NETMASK_BITS, MIN_IP4_CIDR_NETMASK_BITS, snprint_ip4_addr(), and snprintf_safe().
size_t snprint_ip6_addr | ( | char * | s, |
size_t | max_len, | ||
const IP6_ADDR * | p_addr, | ||
const char * | info | ||
) |
Print an IPv6 address in optimized format to a string.
[out] | s | The string buffer to be filled |
[in] | max_len | Size of the output buffer for 0-terminated string |
[in] | p_addr | The IPv6 address to be evaluated |
[in] | info | An optional string which is prepended to the string, or NULL |
Definition at line 463 of file lan_util.c.
References IP6_ADDR::b, IP6_ADDR_BYTES, MBG_ERR_INV_PARM, MBG_ERR_OVERFLOW, NUM_WORDS, and snprintf_safe().
Referenced by snprint_ip6_cidr_addr(), and snprint_ip6_cidr_mask_addr().
size_t snprint_ip6_cidr_addr | ( | char * | s, |
size_t | max_len, | ||
const IP6_ADDR * | p_addr, | ||
const IP6_ADDR * | p_mask, | ||
const char * | info | ||
) |
Print an IPv6 address plus net mask to string in CIDR notation.
The printed CIDR string is something like "2001:0DB8:0:CD30:EF45::/64"
[out] | s | The string buffer to be filled |
[in] | max_len | Size of the output buffer for 0-terminated string |
[in] | p_addr | The IPv6 address to be evaluated |
[in] | p_mask | The associated IPv6 net mask |
[in] | info | An optional string which is prepended to the string, or NULL |
Definition at line 592 of file lan_util.c.
References get_ip6_net_mask_bits(), MAX_IP6_CIDR_NETMASK_BITS, MIN_IP6_CIDR_NETMASK_BITS, snprint_ip6_addr(), and snprintf_safe().
size_t snprint_ip6_cidr_mask_addr | ( | char * | s, |
size_t | max_len, | ||
const IP6_ADDR * | p_addr, | ||
const int | cidr_mask_bits, | ||
const char * | info | ||
) |
Print an IPv6 address plus number of net mask bits to string in CIDR notation.
The printed CIDR string is something like "2001:0DB8:0:CD30:EF45::/64"
[out] | s | The string buffer to be filled |
[in] | max_len | Size of the output buffer for 0-terminated string |
[in] | p_addr | The IPv6 address to be evaluated |
[in] | cidr_mask_bits | The CIDR number of bits specifying the IPv6 net mask |
[in] | info | An optional string which is prepended to the string, or NULL |
Definition at line 629 of file lan_util.c.
References ip6_net_mask_from_cidr(), MAX_IP6_CIDR_NETMASK_BITS, MIN_IP6_CIDR_NETMASK_BITS, snprint_ip6_addr(), and snprintf_safe().
size_t snprint_mac_addr | ( | char * | s, |
size_t | max_len, | ||
const MBG_MAC_ADDR * | p_mac_addr | ||
) |
Print a MAC address to a string.
[out] | s | The string buffer to be filled |
[in] | max_len | Maximum length of the string, i.e. size of the buffer |
[in] | p_mac_addr | The MAC address to be printed |
Definition at line 1049 of file lan_util.c.
References MBG_MAC_ADDR::b, MAC_SEP_CHAR, and snprint_octets().
Referenced by show_lan_intf_state().
size_t snprint_octets | ( | char * | s, |
size_t | max_len, | ||
const uint8_t * | octets, | ||
int | num_octets, | ||
char | sep, | ||
const char * | info | ||
) |
Print a MAC ID or similar array of octets to a string.
[out] | s | The string buffer to be filled |
[in] | max_len | Maximum length of the string, i.e. size of the buffer |
[in] | octets | An array of octets |
[in] | num_octets | The number of octets to be printed from the array |
[in] | sep | The separator printed between the bytes, or 0 |
[in] | info | An optional string which is prepended to the output, or NULL |
Definition at line 990 of file lan_util.c.
References snprintf_safe().
Referenced by set_ptp_cfg(), show_ptp_cfg(), show_ptp_state(), snprint_mac_addr(), and snprint_ptp_clock_id().
size_t snprint_ptp_clock_id | ( | char * | s, |
size_t | max_len, | ||
const PTP_CLOCK_ID * | p | ||
) |
Print a PTP_CLOCK_ID to a string.
[out] | s | The string buffer to be filled |
[in] | max_len | Maximum length of the string, i.e. size of the buffer |
[in] | p | The PTP_CLOCK_ID to be printed |
[out] | s | The string buffer to be filled |
[in] | max_len | Maximum length of the string, i.e. size of the buffer |
[in] | p | The PTP_CLOCK_ID to be printed |
Definition at line 1027 of file lan_util.c.
References PTP_CLOCK_ID::b, and snprint_octets().
int str_to_ip4_addr | ( | IP4_ADDR * | p_addr, |
const char * | s | ||
) |
Convert a string to an IP4_ADDR.
If output parameter is specified as NULL then this function can be used to check if the IPv4 address string is formally correct.
[out] | p_addr | Pointer to an IP4_ADDR variable to be filled, or NULL |
[in] | s | An IPv4 address string to be converted |
Definition at line 291 of file lan_util.c.
References MBG_ERR_PARM_FMT.
Referenced by cidr_str_to_ip4_addr_and_net_mask(), ip4_check_parm(), and set_ptp_cfg().
int str_to_ip6_addr | ( | IP6_ADDR * | p_addr, |
const char * | s | ||
) |
Convert a string to an IP6_ADDR.
If the output parameter is specified as NULL then this function can be used to check if the string is formally correct.
On success IP6_ADDR variable contains the IPv6 address in little endian byte order.
[out] | p_addr | Pointer to the IP6_ADDR variable, or NULL |
[in] | s | A string containing an IPv6 address |
Definition at line 673 of file lan_util.c.
References IP6_ADDR::b, and MBG_ERR_PARM_FMT.
Referenced by cidr_str_to_ip6_addr_and_cidr_bits().
int str_to_octets | ( | uint8_t * | octets, |
int | num_octets, | ||
const char * | s | ||
) |
Set a MAC ID or a similar array of octets from a string.
[out] | octets | An array of octets to be set up |
[in] | num_octets | The number of octets which can be stored |
[in] | s | The string to be converted |
Definition at line 1071 of file lan_util.c.
References MAC_SEP_CHAR, and MAC_SEP_CHAR_ALT.
Referenced by set_ptp_cfg().