Back to Site
Loading...
Searching...
No Matches
librats::network_utils Namespace Reference

Functions

std::string resolve_hostname (const std::string &hostname)
 Resolve hostname to IP address.
 
std::string resolve_hostname_v6 (const std::string &hostname)
 Resolve hostname to IPv6 address.
 
bool is_valid_ipv4 (const std::string &ip_str)
 Check if a string is a valid IPv4 address.
 
bool is_valid_ipv6 (const std::string &ip_str)
 Check if a string is a valid IPv6 address.
 
bool is_hostname (const std::string &str)
 Check if a string is a hostname (not an IP address)
 
std::string to_ip_address (const std::string &host)
 Convert hostname or IP to IP address (alias for resolve_hostname)
 
std::vector< std::string > resolve_all_addresses (const std::string &hostname)
 Get all IP addresses for a hostname.
 
std::vector< std::string > resolve_all_addresses_v6 (const std::string &hostname)
 Get all IPv6 addresses for a hostname.
 
std::vector< std::string > resolve_all_addresses_dual (const std::string &hostname)
 Get all IP addresses (both IPv4 and IPv6) for a hostname.
 
std::vector< std::string > get_local_interface_addresses ()
 Get all local network interface addresses (IPv4 and IPv6)
 
std::vector< std::string > get_local_interface_addresses_v4 ()
 Get all local IPv4 network interface addresses.
 
std::vector< std::string > get_local_interface_addresses_v6 ()
 Get all local IPv6 network interface addresses.
 
bool is_local_interface_address (const std::string &ip_address)
 Check if an IP address is a local interface address.
 

Function Documentation

◆ get_local_interface_addresses()

std::vector< std::string > librats::network_utils::get_local_interface_addresses ( )

Get all local network interface addresses (IPv4 and IPv6)

Returns
Vector of local IP addresses from all network interfaces

Example usage: auto local_ips = network_utils::get_local_interface_addresses(); for (const auto& ip : local_ips) { std::cout << "Local IP: " << ip << std::endl; }

◆ get_local_interface_addresses_v4()

std::vector< std::string > librats::network_utils::get_local_interface_addresses_v4 ( )

Get all local IPv4 network interface addresses.

Returns
Vector of local IPv4 addresses from all network interfaces

Example usage: auto local_ipv4s = network_utils::get_local_interface_addresses_v4(); for (const auto& ip : local_ipv4s) { std::cout << "Local IPv4: " << ip << std::endl; }

◆ get_local_interface_addresses_v6()

std::vector< std::string > librats::network_utils::get_local_interface_addresses_v6 ( )

Get all local IPv6 network interface addresses.

Returns
Vector of local IPv6 addresses from all network interfaces

Example usage: auto local_ipv6s = network_utils::get_local_interface_addresses_v6(); for (const auto& ip : local_ipv6s) { std::cout << "Local IPv6: " << ip << std::endl; }

◆ is_hostname()

bool librats::network_utils::is_hostname ( const std::string &  str)

Check if a string is a hostname (not an IP address)

Parameters
strThe string to check
Returns
true if it's a hostname, false if it's an IP address

Example usage: bool is_host = network_utils::is_hostname("google.com"); // true bool is_ip = network_utils::is_hostname("192.168.1.1"); // false bool is_ipv6 = network_utils::is_hostname("::1"); // false

◆ is_local_interface_address()

bool librats::network_utils::is_local_interface_address ( const std::string &  ip_address)

Check if an IP address is a local interface address.

Parameters
ip_addressThe IP address to check
Returns
true if the IP address belongs to a local network interface

Example usage: bool is_local = network_utils::is_local_interface_address("192.168.1.100");

◆ is_valid_ipv4()

bool librats::network_utils::is_valid_ipv4 ( const std::string &  ip_str)

Check if a string is a valid IPv4 address.

Parameters
ip_strThe string to validate
Returns
true if valid IPv4 address, false otherwise

Example usage: bool valid = network_utils::is_valid_ipv4("192.168.1.1"); // true bool invalid = network_utils::is_valid_ipv4("invalid.ip"); // false

◆ is_valid_ipv6()

bool librats::network_utils::is_valid_ipv6 ( const std::string &  ip_str)

Check if a string is a valid IPv6 address.

Parameters
ip_strThe string to validate
Returns
true if valid IPv6 address, false otherwise

Example usage: bool valid = network_utils::is_valid_ipv6("::1"); // true bool valid2 = network_utils::is_valid_ipv6("2001:db8::1"); // true bool invalid = network_utils::is_valid_ipv6("invalid.ip"); // false

◆ resolve_all_addresses()

std::vector< std::string > librats::network_utils::resolve_all_addresses ( const std::string &  hostname)

Get all IP addresses for a hostname.

Parameters
hostnameThe hostname to resolve
Returns
Vector of IP addresses, empty if resolution fails

Example usage: auto ips = network_utils::resolve_all_addresses("google.com"); for (const auto& ip : ips) { std::cout << "IP: " << ip << std::endl; }

◆ resolve_all_addresses_dual()

std::vector< std::string > librats::network_utils::resolve_all_addresses_dual ( const std::string &  hostname)

Get all IP addresses (both IPv4 and IPv6) for a hostname.

Parameters
hostnameThe hostname to resolve
Returns
Vector of IP addresses, empty if resolution fails

Example usage: auto ips = network_utils::resolve_all_addresses_dual("google.com"); for (const auto& ip : ips) { std::cout << "IP: " << ip << std::endl; }

◆ resolve_all_addresses_v6()

std::vector< std::string > librats::network_utils::resolve_all_addresses_v6 ( const std::string &  hostname)

Get all IPv6 addresses for a hostname.

Parameters
hostnameThe hostname to resolve
Returns
Vector of IPv6 addresses, empty if resolution fails

Example usage: auto ipv6s = network_utils::resolve_all_addresses_v6("google.com"); for (const auto& ipv6 : ipv6s) { std::cout << "IPv6: " << ipv6 << std::endl; }

◆ resolve_hostname()

std::string librats::network_utils::resolve_hostname ( const std::string &  hostname)

Resolve hostname to IP address.

Parameters
hostnameThe hostname to resolve (can be hostname or IP address)
Returns
IP address string, or empty string on error

Example usage: std::string ip = network_utils::resolve_hostname("google.com"); std::string ip2 = network_utils::resolve_hostname("192.168.1.1"); // returns same IP

◆ resolve_hostname_v6()

std::string librats::network_utils::resolve_hostname_v6 ( const std::string &  hostname)

Resolve hostname to IPv6 address.

Parameters
hostnameThe hostname to resolve (can be hostname or IPv6 address)
Returns
IPv6 address string, or empty string on error

Example usage: std::string ipv6 = network_utils::resolve_hostname_v6("google.com"); std::string ipv6_2 = network_utils::resolve_hostname_v6("::1"); // returns same IPv6

◆ to_ip_address()

std::string librats::network_utils::to_ip_address ( const std::string &  host)

Convert hostname or IP to IP address (alias for resolve_hostname)

Parameters
hostThe hostname or IP address to convert
Returns
IP address string, or empty string on error

Example usage: std::string ip = network_utils::to_ip_address("example.com");