MySQL 9.1.0
Source Code Documentation
gcs_xcom_networking.cc File Reference

Functions

bool is_ipv4_address (const std::string &possible_ip)
 Check if it contains an attempt of having an IP v4 address. More...
 
bool is_ipv6_address (const std::string &possible_ip)
 Check if it contains an attempt of having an IP v6 address. More...
 
static bool is_address_localhost (const std::string &address)
 Determines if a given address is an IP localhost address. More...
 
bool get_local_addresses (Gcs_sock_probe_interface &sock_probe_if, std::map< std::string, int > &addr_to_cidr_bits, bool filter_out_inactive)
 This function gets all network addresses on this host and their subnet masks as a string. More...
 
bool get_local_private_addresses (std::map< std::string, int > &out, bool filter_out_inactive)
 This function gets all private network addresses and their subnet masks as a string. More...
 
bool resolve_ip_addr_from_hostname (std::string name, std::vector< std::string > &ip)
 This function translates hostname to all possible IP addresses. More...
 
bool resolve_all_ip_addr_from_hostname (std::string name, std::vector< std::pair< sa_family_t, std::string > > &ips)
 This function translates hostnames to all possible IP addresses. More...
 
bool string_to_sockaddr (const std::string &addr, struct sockaddr_storage *sa)
 Given the address as a string, gets the IP encoded as an integer. More...
 
static bool sock_descriptor_to_sockaddr (int fd, struct sockaddr_storage *sa)
 Returns the address in unsigned integer. More...
 
static bool sock_descriptor_to_string (int fd, std::string &out)
 This function is a frontend function to inet_ntop. More...
 
bool get_address_for_allowlist (std::string addr, std::string mask, std::pair< std::vector< unsigned char >, std::vector< unsigned char > > &out_pair)
 Converts an address in string format (X.X.X.X/XX) into network octet format. More...
 

Function Documentation

◆ get_address_for_allowlist()

bool get_address_for_allowlist ( std::string  addr,
std::string  mask,
std::pair< std::vector< unsigned char >, std::vector< unsigned char > > &  out_pair 
)

Converts an address in string format (X.X.X.X/XX) into network octet format.

Parameters
[in]addrIP address in X.X.X.X format
[in]maskNetwork mask associated with the address
[out]out_pairIP address and netmask, in binary format (network byte order)
Returns
false on success, true otherwise.

◆ get_local_addresses()

bool get_local_addresses ( Gcs_sock_probe_interface sock_probe,
std::map< std::string, int > &  out,
bool  filter_out_inactive = false 
)

This function gets all network addresses on this host and their subnet masks as a string.

Parameters
[out]sock_probeSocket probe interface
[out]outmaps IP addresses to subnetmasks
filter_out_inactiveIf set to true, only active interfaces will be added to out
Returns
false on success, true otherwise.

◆ get_local_private_addresses()

bool get_local_private_addresses ( std::map< std::string, int > &  out,
bool  filter_out_inactive 
)

This function gets all private network addresses and their subnet masks as a string.

In the Internet addressing architecture, a private network is a network that uses private IP address space. Both, the IPv4 and the IPv6 specifications define private addressing ranges. These addresses are commonly used for local area networks (LANs) in residential, office, and enterprise environments. Private IP address spaces were originally defined in an effort to delay IPv4 address exhaustion.

◆ is_address_localhost()

static bool is_address_localhost ( const std::string &  address)
static

Determines if a given address is an IP localhost address.

Parameters
[in]addressa reference to a string containing the address to test
Returns
true if localhost, false otherwise.

◆ is_ipv4_address()

bool is_ipv4_address ( const std::string &  possible_ip)

Check if it contains an attempt of having an IP v4 address.

It does not check for its validity, but only if it contains all authorized characters: numbers and dots.

Returns
true if it exclusively contains all authorized characters.

◆ is_ipv6_address()

bool is_ipv6_address ( const std::string &  possible_ip)

Check if it contains an attempt of having an IP v6 address.

It does not check for its validity, but it checks if it contains : character

Returns
true if it contains the : character.

◆ resolve_all_ip_addr_from_hostname()

bool resolve_all_ip_addr_from_hostname ( std::string  name,
std::vector< std::pair< sa_family_t, std::string > > &  ips 
)

This function translates hostnames to all possible IP addresses.

Parameters
[in]nameThe hostname to translate.
[out]ipsThe IP addresses after translation.
Returns
false on success, true otherwise.

◆ resolve_ip_addr_from_hostname()

bool resolve_ip_addr_from_hostname ( std::string  name,
std::vector< std::string > &  ip 
)

This function translates hostname to all possible IP addresses.

Parameters
[in]nameThe hostname to translate.
[out]ipThe IP addresses after translation.
Returns
false on success, true otherwise.

◆ sock_descriptor_to_sockaddr()

static bool sock_descriptor_to_sockaddr ( int  fd,
struct sockaddr_storage *  sa 
)
static

Returns the address in unsigned integer.

◆ sock_descriptor_to_string()

static bool sock_descriptor_to_string ( int  fd,
std::string &  out 
)
static

This function is a frontend function to inet_ntop.

◆ string_to_sockaddr()

bool string_to_sockaddr ( const std::string &  addr,
struct sockaddr_storage *  sa 
)

Given the address as a string, gets the IP encoded as an integer.

Try IPv4 first.

Try IPv6.