mbgtools-lx
4.2.8
|
#include <lan_util.h>
#include <words.h>
#include <str_util.h>
#include <mbgerror.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <linux/types.h>
#include <linux/sockios.h>
#include <linux/ethtool.h>
#include <linux/rtnetlink.h>
#include <unistd.h>
#include <syslog.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <netinet/in.h>
Go to the source code of this file.
Data Structures | |
struct | route_info |
Macros | |
#define | _LAN_UTIL |
#define | MAX_IP4_ADDR_STR_SIZE 16 |
#define | NUM_WORDS ( (int) ( sizeof( IP6_ADDR_STR ) / sizeof( uint16_t ) ) ) |
Typedefs | |
typedef uint8_t | u8 |
typedef uint16_t | u16 |
typedef uint32_t | u32 |
typedef uint64_t | u64 |
Functions | |
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... | |
static int | get_specific_port_ip4_addr (const char *if_name, IP4_ADDR *p_addr, int sigioc_code) |
Retrieve some IPv4 address-like info from 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... | |
static int | nl_read (int sock_fd, char *buf_ptr, size_t buf_size, int seq_num, int pid) |
Read a requested message from the netlink socket. More... | |
static int | nl_parse_routes (struct nlmsghdr *nl_hdr, struct route_info *rt_info) |
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 _LAN_UTIL |
Definition at line 75 of file lan_util.c.
#define MAX_IP4_ADDR_STR_SIZE 16 |
Definition at line 153 of file lan_util.c.
#define NUM_WORDS ( (int) ( sizeof( IP6_ADDR_STR ) / sizeof( uint16_t ) ) ) |
Referenced by snprint_ip6_addr().
Definition at line 99 of file lan_util.c.
typedef uint32_t u32 |
Definition at line 100 of file lan_util.c.
Definition at line 101 of file lan_util.c.
Definition at line 98 of file lan_util.c.
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 |
Retrieve some IPv4 address-like info from a network interface.
[in] | if_name | Name of the interface |
[out] | p_addr | Pointer to address field to be filled up |
[in] | sigioc_code | The IOCTL code associated with the address |
Definition at line 1361 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_addr(), get_port_ip4_broad_addr(), and get_port_ip4_netmask().
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().
|
static |
Definition at line 1563 of file lan_util.c.
References route_info::dstAddr, route_info::gateWay, route_info::ifName, and route_info::srcAddr.
Referenced by get_ip4_gateway().
|
static |
Read a requested message from the netlink socket.
Definition at line 1472 of file lan_util.c.
References BYTE_OF, MBG_ERR_DATA_FMT, mbg_get_last_socket_error(), mbg_strerror(), and snprintf_safe().
Referenced by get_ip4_gateway().
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 |
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().