50 #if defined( MBG_TGT_POSIX ) 51 #include <sys/types.h> 52 #include <sys/socket.h> 65 #if defined( IFHWADDRLEN ) // usually defined in net/if.h 66 #if ( IFHWADDRLEN != 6 ) 67 #error Warning: IFHWADDRLEN is not 6! 83 #if defined( _USE_PACK ) 84 #pragma pack( 1 ) // set byte alignment 85 #define _USING_BYTE_ALIGNMENT 93 #if !defined( MAC_SEP_CHAR ) 94 #define MAC_SEP_CHAR ':' // character used to separate octets of a MAC ID 97 #if !defined( MAC_SEP_CHAR_ALT ) 98 #define MAC_SEP_CHAR_ALT '-' // alternate character 102 #define MAX_IP4_BITS ( 8 * (int) sizeof( IP4_ADDR ) ) 104 #define IP4_MSB_MASK ( 1UL << ( MAX_IP4_BITS - 1 ) ) 106 #define MIN_IP4_CIDR_NETMASK_BITS 0 107 #define MAX_IP4_CIDR_NETMASK_BITS MAX_IP4_BITS 110 #define IP6_MSB_MASK ( 1UL << ( 8 - 1 ) ) 112 #define MIN_IP6_CIDR_NETMASK_BITS 0 113 #define MAX_IP6_CIDR_NETMASK_BITS IP6_ADDR_BITS 153 return *p_addr | ~(*p_mask);
174 return *p_addr & *p_mask;
200 #define _ip4_addr_to_str( _s, _a ) \ 201 snprint_ip4_addr( _s, sizeof( _s ), _a, NULL ) 203 #define _mac_addr_to_str( _s, _a ) \ 204 snprint_mac_addr( _s, sizeof( _s ), _a ) 484 size_t snprint_octets(
char *s,
size_t max_len,
const uint8_t *octets,
int num_octets,
char sep,
const char *info ) ;
565 int do_siocg_ioctl(
const char *if_name,
int ioctl_code,
struct ifreq *p_ifreq ) ;
766 #if defined( _USING_BYTE_ALIGNMENT ) 767 #pragma pack() // set default alignment 768 #undef _USING_BYTE_ALIGNMENT 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.
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.
int check_port_status(const char *if_name, int *p_speed, int *p_duplex)
Check the state of a network interface.
int get_port_ip4_broad_addr(const char *if_name, IP4_ADDR *p_addr)
Retrieve the IPv4 broadcast address of a network interface.
The MAC address of a network interface.
Settings of an IPv4-only network interface.
uint32_t IP4_ADDR
An IPv4 address.
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.
bool mac_addr_is_all_zero(const MBG_MAC_ADDR *p_addr)
Check if a MAC address is all zero.
int check_port_link(const char *if_name)
Check the link state of a network interface.
int get_ip6_net_mask_bits(const IP6_ADDR *p_mask)
Count the number of sequential bits in an IPv6 net mask.
int get_port_intf_idx(const char *if_name, int *p_intf_idx)
Retrieve the index of a specific network interface.
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.
int str_to_ip6_addr(IP6_ADDR *p_addr, const char *s)
Convert a string to an IP6_ADDR.
int get_ip4_gateway(IP4_ADDR *p_addr)
Retrieve the IPv4 gateway (default route)
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.
int get_port_ip4_settings(const char *if_name, IP4_SETTINGS *p)
Retrieve the current IPv4 settings of a network interface.
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.
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.
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.
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.
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.
int get_port_mac_addr(const char *if_name, MBG_MAC_ADDR *p_mac_addr)
Retrieve the MAC address of a network interface.
int get_port_ip4_addr(const char *if_name, IP4_ADDR *p_addr)
Retrieve the IPv4 address of a network interface.
int get_port_ip4_netmask(const char *if_name, IP4_ADDR *p_addr)
Retrieve the IPv4 net mask of a network interface.
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.
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.
int str_to_ip4_addr(IP4_ADDR *p_addr, const char *s)
Convert a string to an IP4_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.
int get_ip4_net_mask_bits(const IP4_ADDR *p_mask)
Count the number of sequential bits in an IPv4 net mask.
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.
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.
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.
bool octets_are_all_zero(const uint8_t *octets, int num_octets)
Check if an array of octets is all zero.
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.
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.
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.
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.
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.
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.