ipaddress 1.1.0
|
A template base class for IP address representations. More...
#include <ip-address-base.hpp>
Public Types | |
using | base_type = typename Base::base_type |
Type alias for the base storage type. | |
using | uint_type = typename Base::uint_type |
Type alias for the underlying unsigned integer type. | |
Public Member Functions | |
constexpr inline | ip_address_base () noexcept |
Default constructor. | |
constexpr inline | ip_address_base (const base_type &bytes) noexcept |
Constructs an IP address object from a byte array. | |
constexpr inline const uint8_t * | data () const noexcept |
Retrieves the raw data representing the IP address in network byte order (big-endian). | |
constexpr inline bool | is_multicast () const noexcept |
Checks if the IP address is a multicast address. | |
constexpr inline bool | is_private () const noexcept |
Checks if the IP address is a private address. | |
constexpr inline bool | is_global () const noexcept |
Checks if the IP address is a global address. | |
constexpr inline bool | is_reserved () const noexcept |
Checks if the IP address is a reserved address. | |
constexpr inline bool | is_loopback () const noexcept |
Checks if the IP address is a loopback address. | |
constexpr inline bool | is_link_local () const noexcept |
Checks if the IP address is a link-local address. | |
constexpr inline bool | is_unspecified () const noexcept |
Checks if the IP address is unspecified. | |
inline std::string | to_string (format fmt=format::compressed) const |
Converts the IP address to a string representation. | |
inline std::wstring | to_wstring (format fmt=format::compressed) const |
Converts the IP address to a string representation. | |
inline std::u16string | to_u16string (format fmt=format::compressed) const |
Converts the IP address to a string representation. | |
inline std::u32string | to_u32string (format fmt=format::compressed) const |
Converts the IP address to a string representation. | |
inline std::u8string | to_u8string (format fmt=format::compressed) const |
Converts the IP address to a string representation. | |
constexpr inline void | swap (ip_address_base &ip) noexcept |
Swaps the contents of this IP address with another IP address. | |
constexpr inline size_t | hash () const noexcept |
Computes a hash value for the IP address. | |
inline std::string | reverse_pointer () const |
Generates a reverse DNS lookup pointer for the IP address. | |
constexpr inline | operator uint_type () const noexcept |
Converts the IP address to an unsigned integer type. | |
template<typename T > | |
inline | operator std::basic_string< T, std::char_traits< T >, std::allocator< T > > () const |
Converts the IP address to a string. | |
constexpr inline bool | operator== (const ip_address_base &rhs) const noexcept |
Checks if two IP addresses are equal. | |
constexpr inline bool | operator!= (const ip_address_base &rhs) const noexcept |
Checks if two IP addresses are not equal. | |
constexpr inline bool | operator< (const ip_address_base &rhs) const noexcept |
Checks if one IP address is less than another. | |
constexpr inline bool | operator> (const ip_address_base &rhs) const noexcept |
Checks if one IP address is greater than another. | |
constexpr inline bool | operator<= (const ip_address_base &rhs) const noexcept |
Checks if one IP address is less than or equal to another. | |
constexpr inline bool | operator>= (const ip_address_base &rhs) const noexcept |
Checks if one IP address is greater than or equal to another. | |
Static Public Member Functions | |
static constexpr inline ip_address_base | from_bytes (const base_type &bytes) noexcept |
Static factory method to create an IP address object from a byte array. | |
static constexpr inline ip_address_base | from_bytes (const uint8_t *bytes, size_t byte_count) noexcept |
Static factory method to create an IP address object from a raw byte buffer. | |
template<fixed_string FixedString> | |
static consteval inline ip_address_base< Base > | parse () noexcept |
Static method template to parse an IP address from a fixed string at compile time. | |
static constexpr inline ip_address_base | parse (std::string_view address) |
Parses an IP address from a string view. | |
static constexpr inline ip_address_base | parse (std::wstring_view address) |
Parses an IP address from a wide string view. | |
static constexpr inline ip_address_base | parse (std::u8string_view address) |
Parses an IP address from a UTF-8 string view. | |
static constexpr inline ip_address_base | parse (std::u16string_view address) |
Parses an IP address from a UTF-16 string view. | |
static constexpr inline ip_address_base | parse (std::u32string_view address) |
Parses an IP address from a UTF-32 string view. | |
static constexpr inline ip_address_base | parse (std::string_view address, error_code &code) noexcept |
Parses an IP address from a string view and reports errors through an error code. | |
static constexpr inline ip_address_base | parse (std::wstring_view address, error_code &code) noexcept |
Parses an IP address from a wide string view and reports errors through an error code. | |
static constexpr inline ip_address_base | parse (std::u8string_view address, error_code &code) noexcept |
Parses an IP address from a UTF-8 string view and reports errors through an error code. | |
static constexpr inline ip_address_base | parse (std::u16string_view address, error_code &code) noexcept |
Parses an IP address from a UTF-16 string view and reports errors through an error code. | |
static constexpr inline ip_address_base | parse (std::u32string_view address, error_code &code) noexcept |
Parses an IP address from a UTF-32 string view and reports errors through an error code. | |
template<typename T , size_t N> | |
static constexpr inline ip_address_base | parse (const T(&address)[N]) |
Parses an IP address from a character array. | |
template<typename T , size_t N> | |
static constexpr inline ip_address_base | parse (const T(&address)[N], error_code &code) noexcept |
Parses an IP address from a character array and reports errors through an error code. | |
A template base class for IP address representations.
This class template serves as a base for creating IP address objects. It inherits from a base class that provides the necessary functionality, and it is extended by more specific IP address classes.
Base | The base class providing storage and low-level IP address functionalities. |
|
inlinenoexcept |
Default constructor.
Constructs an empty IP address object.
|
inlineexplicitnoexcept |
Constructs an IP address object from a byte array.
[in] | bytes | The byte array representing an IP address. |
|
inlinestaticnoexcept |
Static factory method to create an IP address object from a byte array.
[in] | bytes | The byte array representing an IP address. |
|
inlinestaticnoexcept |
Static factory method to create an IP address object from a raw byte buffer.
[in] | bytes | Pointer to the raw byte buffer representing an IP address. |
[in] | byte_count | The number of bytes in the buffer to use. |
|
inlinestaticnoexcept |
Static method template to parse an IP address from a fixed string at compile time.
FixedString | A non-type template parameter that holds the string representation of the IP address. |
|
inlinestatic |
Parses an IP address from a string view.
This method provides a way to parse an IP address from a string view, which is a non-owning reference to a sequence of characters.
[in] | address | The string view containing the IP address to parse. |
parse_error | Exception caused by invalid input string. |
std::string
and C-strings will be used instead.
|
inlinestatic |
Parses an IP address from a wide string view.
This method allows for parsing an IP address from a wide string view, which is typically used for wide character strings.
[in] | address | The wide string view containing the IP address to parse. |
parse_error | Exception caused by invalid input string. |
std::wstring
and C-strings will be used instead.
|
inlinestatic |
Parses an IP address from a UTF-8 string view.
This method parses an IP address from a given UTF-8 string view. It leverages the char8_t
type introduced in C++20 to handle UTF-8 strings natively.
[in] | address | A UTF-8 string view containing the IP address to parse. |
parse_error | Exception caused by invalid input string. |
char8_t
is supported.
|
inlinestatic |
Parses an IP address from a UTF-16 string view.
This method is designed to parse an IP address from a UTF-16 string view, which is a sequence of 16-bit characters.
[in] | address | The UTF-16 string view containing the IP address to parse. |
parse_error | Exception caused by invalid input string. |
std::u16string
and C-strings will be used instead.
|
inlinestatic |
Parses an IP address from a UTF-32 string view.
This method allows for parsing an IP address from a UTF-32 string view, which is a sequence of 32-bit characters.
[in] | address | The UTF-32 string view containing the IP address to parse. |
parse_error | Exception caused by invalid input string. |
std::u32string
and C-strings will be used instead.
|
inlinestaticnoexcept |
Parses an IP address from a string view and reports errors through an error code.
This method parses an IP address from a string view and provides an error code if the parsing fails.
[in] | address | The string view containing the IP address to parse. |
[out] | code | A reference to an error_code object that will be set if an error occurs during parsing. |
std::string
and C-strings will be used instead.
|
inlinestaticnoexcept |
Parses an IP address from a wide string view and reports errors through an error code.
This method parses an IP address from a wide string view and provides an error code if the parsing fails.
[in] | address | The wide string view containing the IP address to parse. |
[out] | code | A reference to an error_code object that will be set if an error occurs during parsing. |
std::wstring
and C-strings will be used instead.
|
inlinestaticnoexcept |
Parses an IP address from a UTF-8 string view and reports errors through an error code.
This method parses an IP address from a UTF-8 string view and provides an error code if the parsing fails.
[in] | address | The UTF-8 string view containing the IP address to parse. |
[out] | code | A reference to an error_code object that will be set if an error occurs during parsing. |
char8_t
is supported.
|
inlinestaticnoexcept |
Parses an IP address from a UTF-16 string view and reports errors through an error code.
This method parses an IP address from a UTF-16 string view and provides an error code if the parsing fails.
[in] | address | The UTF-16 string view containing the IP address to parse. |
[out] | code | A reference to an error_code object that will be set if an error occurs during parsing. |
std::u16string
and C-strings will be used instead.
|
inlinestaticnoexcept |
Parses an IP address from a UTF-32 string view and reports errors through an error code.
This method parses an IP address from a UTF-32 string view and provides an error code if the parsing fails.
[in] | address | The UTF-32 string view containing the IP address to parse. |
[out] | code | A reference to an error_code object that will be set if an error occurs during parsing. |
std::u32string
and C-strings will be used instead.
|
inlinestatic |
Parses an IP address from a character array.
This method template parses an IP address from a character array of a specified size. Can check and get the result at compile time.
T | The character type of the array. |
N | The size of the character array. |
[in] | address | The character array containing the IP address to parse. |
|
inlinestaticnoexcept |
Parses an IP address from a character array and reports errors through an error code.
This method template parses an IP address from a character array of a specified size and provides an error code if the parsing fails.
T | The character type of the array. |
N | The size of the character array. |
[in] | address | The character array containing the IP address to parse. |
[out] | code | A reference to an error_code object that will be set if an error occurs during parsing. |
|
inlinenoexcept |
Retrieves the raw data representing the IP address in network byte order (big-endian).
This method returns a pointer to the underlying byte array that stores the IP address.
|
noexcept |
|
noexcept |
Checks if the IP address is a private address.
true
if the IP address is allocated for private networks, false
otherwise.
|
noexcept |
Checks if the IP address is a global address.
true
if the IP address is allocated for public networks, false
otherwise.
|
noexcept |
Checks if the IP address is a reserved address.
true
if the IP address is otherwise IETF reserved, false
otherwise.
|
noexcept |
|
noexcept |
Checks if the IP address is a link-local address.
true
if the IP address is reserved for link-local usage, false
otherwise.
|
inlinenoexcept |
Checks if the IP address is unspecified.
An unspecified IP address is an address with all bits set to zero. In IPv4, this is represented as 0.0.0.0, and in IPv6, as ::. This type of address is used to indicate the absence of an address.
true
if the IP address is unspecified (all bits are zero), false
otherwise.
|
inline |
Converts the IP address to a string representation.
The function converts the binary representation of the IP address to a string. The format of the output string can be adjusted by passing the desired format as an argument. The default format is 'compressed'.
[in] | fmt | The format to use for the string representation. Defaults to format::compressed . |
std::string
representing the IP address in the specified format.
|
inline |
Converts the IP address to a string representation.
The function converts the binary representation of the IP address to a string. The format of the output string can be adjusted by passing the desired format as an argument. The default format is 'compressed'.
[in] | fmt | The format to use for the string representation. Defaults to format::compressed . |
std::wstring
representing the IP address in the specified format.
|
inline |
Converts the IP address to a string representation.
The function converts the binary representation of the IP address to a string. The format of the output string can be adjusted by passing the desired format as an argument. The default format is 'compressed'.
[in] | fmt | The format to use for the string representation. Defaults to format::compressed . |
std::u16string
representing the IP address in the specified format.
|
inline |
Converts the IP address to a string representation.
The function converts the binary representation of the IP address to a string. The format of the output string can be adjusted by passing the desired format as an argument. The default format is 'compressed'.
[in] | fmt | The format to use for the string representation. Defaults to format::compressed . |
std::u32string
representing the IP address in the specified format.
|
inline |
Converts the IP address to a string representation.
The function converts the binary representation of the IP address to a string. The format of the output string can be adjusted by passing the desired format as an argument. The default format is 'compressed'.
[in] | fmt | The format to use for the string representation. Defaults to format::compressed . |
std::u8string
representing the IP address in the specified format.
|
inlinenoexcept |
Swaps the contents of this IP address with another IP address.
This function swaps the underlying bytes representing the IP address with those of another IP address.
[in] | ip | The other IP address to swap with. |
|
inlinenoexcept |
Computes a hash value for the IP address.
This function generates a hash value that can be used to uniquely identify the IP address. It can be useful when IP addresses are used as keys in hash tables.
size_t
hash value of the IP address.
|
inline |
Generates a reverse DNS lookup pointer for the IP address.
This function creates a string that is the reverse DNS lookup pointer of the IP address. It is commonly used in reverse DNS lookups, where the IP address is reversed and appended with .in-addr.arpa
for IPv4, or .ip6.arpa
for IPv6, to form a domain name that can be looked up in the DNS system.
The name of the reverse DNS PTR record for the IP address, e.g.:
std::string
that is the reverse DNS lookup pointer of the IP address.
|
inlineexplicitnoexcept |
Converts the IP address to an unsigned integer type.
This operator allows the IP address to be used as an unsigned integer type. It can be useful when a numerical representation of the IP address is needed.
|
inlineexplicit |
Converts the IP address to a string.
This operator allows the IP address to be converted to a string.
T | The character type of the string. |
|
inlinenoexcept |
Checks if two IP addresses are equal.
This operator compares the binary representation of two IP addresses to determine if they are equal.
[in] | rhs | The right-hand side IP address for comparison. |
true
if both IP addresses are equal, false
otherwise.
|
inlinenoexcept |
Checks if two IP addresses are not equal.
This operator compares the binary representation of two IP addresses to determine if they are not equal.
[in] | rhs | The right-hand side IP address for comparison. |
true
if both IP addresses are not equal, false
otherwise.
|
inlinenoexcept |
Checks if one IP address is less than another.
This operator compares the binary representation of two IP addresses to determine if the left-hand side is less than the right-hand side.
[in] | rhs | The right-hand side IP address for comparison. |
true
if the left-hand side IP address is less than the right-hand side, false
otherwise.
|
inlinenoexcept |
Checks if one IP address is greater than another.
This operator compares the binary representation of two IP addresses to determine if the left-hand side is greater than the right-hand side.
[in] | rhs | The right-hand side IP address for comparison. |
true
if the left-hand side IP address is greater than the right-hand side, false
otherwise.
|
inlinenoexcept |
Checks if one IP address is less than or equal to another.
This operator compares the binary representation of two IP addresses to determine if the left-hand side is less than or equal to the right-hand side.
[in] | rhs | The right-hand side IP address for comparison. |
true
if the left-hand side IP address is less than or equal to the right-hand side, false
otherwise.
|
inlinenoexcept |
Checks if one IP address is greater than or equal to another.
This operator compares the binary representation of two IP addresses to determine if the left-hand side is greater than or equal to the right-hand side.
[in] | rhs | The right-hand side IP address for comparison. |
true
if the left-hand side IP address is greater than or equal to the right-hand side, false
otherwise.