ipaddress 1.1.0
Loading...
Searching...
No Matches
ipv6_address_base Class Reference

Represents the base class for IPv6 address manipulation. More...

#include <ipv6-address.hpp>

Inheritance diagram for ipv6_address_base:

Public Types

using base_type = typename base_v6<ipv6_address_base>::base_type
 The base type for the IPv6 address.
 
using uint_type = typename base_v6<ipv6_address_base>::uint_type
 The unsigned integer type for the IPv6 address.
 

Public Member Functions

constexpr inline scope get_scope_id () const noexcept
 Retrieves the scope identifier of the IPv6 address.
 
template<typename T , size_t N>
constexpr inline void set_scope_id (const T(&scope_id)[N])
 Sets the scope identifier of the IPv6 address.
 
template<typename T , size_t N>
constexpr inline void set_scope_id (const T(&scope_id)[N], error_code &code) noexcept
 Sets the scope identifier of the IPv6 address and reports any errors encountered.
 
constexpr inline void set_scope_id (std::string_view scope_id)
 Sets the scope identifier of the IPv6 address using a string view.
 
constexpr inline void set_scope_id (std::wstring_view scope_id)
 Sets the scope identifier of the IPv6 address using a wide string view.
 
constexpr inline void set_scope_id (std::u8string_view scope_id)
 Sets the scope identifier of the IPv6 address using UTF-8 string view.
 
constexpr inline void set_scope_id (std::u16string_view scope_id)
 Sets the scope identifier of the IPv6 address using UTF-16 string view.
 
constexpr inline void set_scope_id (std::u32string_view scope_id)
 Sets the scope identifier of the IPv6 address using UTF-32 string view.
 
constexpr inline void set_scope_id (std::string_view scope_id, error_code &code) noexcept
 Sets the scope identifier of the IPv6 address using a string view and reports any errors encountered.
 
constexpr inline void set_scope_id (std::wstring_view scope_id, error_code &code) noexcept
 Sets the scope identifier of the IPv6 address using a wide string view and reports any errors encountered.
 
constexpr inline void set_scope_id (std::u8string_view scope_id, error_code &code) noexcept
 Sets the scope identifier of the IPv6 address using a UTF-8 string view and reports any errors encountered.
 
constexpr inline void set_scope_id (std::u16string_view scope_id, error_code &code) noexcept
 Sets the scope identifier of the IPv6 address using a UTF-16 string view and reports any errors encountered.
 
constexpr inline void set_scope_id (std::u32string_view scope_id, error_code &code) noexcept
 Sets the scope identifier of the IPv6 address using a UTF-32 string view and reports any errors encountered.
 
constexpr inline uint_type to_uint () const noexcept
 Converts the IPv6 address to an unsigned integer.
 
constexpr inline const base_typebytes () const noexcept
 Provides access to the underlying bytes of the IPv6 address.
 
constexpr inline optional< ipv4_addressipv4_mapped () const noexcept
 Determines if the IPv6 address is an IPv4-mapped address.
 
constexpr inline optional< ipv4_addresssixtofour () const noexcept
 Determines if the IPv6 address is a 6to4 address.
 
constexpr inline optional< std::pair< ipv4_address, ipv4_address > > teredo () const noexcept
 Determines if the IPv6 address is a Teredo address.
 
constexpr inline bool is_site_local () const noexcept
 Checks if the IPv6 address is a site-local address.
 
constexpr inline ip_version version () const noexcept
 Retrieves the IP version of the address.
 
constexpr inline size_t size () const noexcept
 Retrieves the size of the IPv6 address.
 

Static Public Member Functions

static constexpr inline ip_address_base< ipv6_address_basefrom_uint (uint_type ip) noexcept
 Creates an IPv6 address from an unsigned integer using a template parameter.
 

Detailed Description

Represents the base class for IPv6 address manipulation.

This class provides the basic functionalities required for handling IPv6 addresses, including conversion to and from numeric representations, access to the underlying bytes, and utility functions that are common across different representations of IPv6 addresses.

Member Function Documentation

◆ get_scope_id()

constexpr inline scope get_scope_id ( ) const
inlinenoexcept

Retrieves the scope identifier of the IPv6 address.

The scope identifier is used to determine the context in which the address is valid. It is particularly relevant for link-local and site-local addresses.

Returns
A scope object representing the scope identifier of the IPv6 address.
Remarks
If the scope is disabled in the settings (IPADDRESS_IPV6_SCOPE_MAX_LENGTH == 0), then an empty scope will be returned.

◆ set_scope_id() [1/12]

template<typename T , size_t N>
constexpr inline void set_scope_id ( const T(&) scope_id[N])
inline

Sets the scope identifier of the IPv6 address.

This function sets the scope identifier using a character array. The length of the array should not exceed IPADDRESS_IPV6_SCOPE_MAX_LENGTH + 1.

Template Parameters
TThe character type of the scope identifier.
NThe size of the scope identifier array.
Parameters
[in]scope_idThe character array representing the scope identifier.
Remarks
If scope is disabled in settings (IPADDRESS_IPV6_SCOPE_MAX_LENGTH == 0) then this call will have no effect.

◆ set_scope_id() [2/12]

template<typename T , size_t N>
constexpr inline void set_scope_id ( const T(&) scope_id[N],
error_code & code )
inlinenoexcept

Sets the scope identifier of the IPv6 address and reports any errors encountered.

This function sets the scope identifier using a character array. The length of the array should not exceed IPADDRESS_IPV6_SCOPE_MAX_LENGTH + 1.

Template Parameters
TThe character type of the scope identifier.
NThe size of the scope identifier array.
Parameters
[in]scope_idThe character array representing the scope identifier.
[out]codeAn error_code object that will be set to the error that occurred, if any.
Remarks
If scope is disabled in settings (IPADDRESS_IPV6_SCOPE_MAX_LENGTH == 0) then this call will have no effect.

◆ set_scope_id() [3/12]

constexpr inline void set_scope_id ( std::string_view scope_id)
inline

Sets the scope identifier of the IPv6 address using a string view.

This function sets the scope identifier using a string view, which allows for a more efficient way to handle strings without copying them.

Parameters
[in]scope_idThe string view representing the scope identifier.
Exceptions
parse_errorException caused by invalid input string.
Note
This method is available for C++17 and later versions.
Remarks
For C++ versions prior to C++17, member functions with std::string and C-strings will be used instead.
Remarks
If scope is disabled in settings (IPADDRESS_IPV6_SCOPE_MAX_LENGTH == 0) then this call will have no effect.

◆ set_scope_id() [4/12]

constexpr inline void set_scope_id ( std::wstring_view scope_id)
inline

Sets the scope identifier of the IPv6 address using a wide string view.

This function sets the scope identifier using a wide string view, which allows for a more efficient way to handle strings without copying them.

Parameters
[in]scope_idThe wide string view representing the scope identifier.
Exceptions
parse_errorException caused by invalid input string.
Note
This method is available for C++17 and later versions.
Remarks
For C++ versions prior to C++17, member functions with std::wstring and C-strings will be used instead.
Remarks
If scope is disabled in settings (IPADDRESS_IPV6_SCOPE_MAX_LENGTH == 0) then this call will have no effect.

◆ set_scope_id() [5/12]

constexpr inline void set_scope_id ( std::u8string_view scope_id)
inline

Sets the scope identifier of the IPv6 address using UTF-8 string view.

This function sets the scope identifier using UTF-8 string view, which allows for a more efficient way to handle strings without copying them.

Parameters
[in]scope_idThe UTF-8 string view representing the scope identifier.
Exceptions
parse_errorException caused by invalid input string.
Note
This method is available for C++20 and later versions where char8_t is supported.
Remarks
If scope is disabled in settings (IPADDRESS_IPV6_SCOPE_MAX_LENGTH == 0) then this call will have no effect.

◆ set_scope_id() [6/12]

constexpr inline void set_scope_id ( std::u16string_view scope_id)
inline

Sets the scope identifier of the IPv6 address using UTF-16 string view.

This function sets the scope identifier using UTF-16 string view, which allows for a more efficient way to handle strings without copying them.

Parameters
[in]scope_idThe UTF-16 string view representing the scope identifier.
Exceptions
parse_errorException caused by invalid input string.
Note
This method is available for C++17 and later versions.
Remarks
For C++ versions prior to C++17, member functions with std::u16string and C-strings will be used instead.
Remarks
If scope is disabled in settings (IPADDRESS_IPV6_SCOPE_MAX_LENGTH == 0) then this call will have no effect.

◆ set_scope_id() [7/12]

constexpr inline void set_scope_id ( std::u32string_view scope_id)
inline

Sets the scope identifier of the IPv6 address using UTF-32 string view.

This function sets the scope identifier using UTF-32 string view, which allows for a more efficient way to handle strings without copying them.

Parameters
[in]scope_idThe UTF-32 string view representing the scope identifier.
Exceptions
parse_errorException caused by invalid input string.
Note
This method is available for C++17 and later versions.
Remarks
For C++ versions prior to C++17, member functions with std::u32string and C-strings will be used instead.
Remarks
If scope is disabled in settings (IPADDRESS_IPV6_SCOPE_MAX_LENGTH == 0) then this call will have no effect.

◆ set_scope_id() [8/12]

constexpr inline void set_scope_id ( std::string_view scope_id,
error_code & code )
inlinenoexcept

Sets the scope identifier of the IPv6 address using a string view and reports any errors encountered.

This function sets the scope identifier using a string view and provides an error code parameter to report any issues that occur during the operation.

Parameters
[in]scope_idThe string view representing the scope identifier.
[out]codeAn error_code object that will be set to the error that occurred, if any.
Note
This method is available for C++17 and later versions.
Remarks
For C++ versions prior to C++17, member functions with std::string and C-strings will be used instead.
Remarks
If scope is disabled in settings (IPADDRESS_IPV6_SCOPE_MAX_LENGTH == 0) then this call will have no effect.

◆ set_scope_id() [9/12]

constexpr inline void set_scope_id ( std::wstring_view scope_id,
error_code & code )
inlinenoexcept

Sets the scope identifier of the IPv6 address using a wide string view and reports any errors encountered.

This function sets the scope identifier using a wide string view and provides an error code parameter to report any issues that occur during the operation.

Parameters
[in]scope_idThe wide string view representing the scope identifier.
[out]codeAn error_code object that will be set to the error that occurred, if any.
Note
This method is available for C++17 and later versions.
Remarks
For C++ versions prior to C++17, member functions with std::wstring and C-strings will be used instead.
Remarks
If scope is disabled in settings (IPADDRESS_IPV6_SCOPE_MAX_LENGTH == 0) then this call will have no effect.

◆ set_scope_id() [10/12]

constexpr inline void set_scope_id ( std::u8string_view scope_id,
error_code & code )
inlinenoexcept

Sets the scope identifier of the IPv6 address using a UTF-8 string view and reports any errors encountered.

This function sets the scope identifier using a UTF-8 string view and provides an error code parameter to report any issues that occur during the operation.

Parameters
[in]scope_idThe UTF-8 string view representing the scope identifier.
[out]codeAn error_code object that will be set to the error that occurred, if any.
Note
This method is available for C++20 and later versions.
Remarks
If scope is disabled in settings (IPADDRESS_IPV6_SCOPE_MAX_LENGTH == 0) then this call will have no effect.

◆ set_scope_id() [11/12]

constexpr inline void set_scope_id ( std::u16string_view scope_id,
error_code & code )
inlinenoexcept

Sets the scope identifier of the IPv6 address using a UTF-16 string view and reports any errors encountered.

This function sets the scope identifier using a UTF-16 string view and provides an error code parameter to report any issues that occur during the operation.

Parameters
[in]scope_idThe UTF-16 string view representing the scope identifier.
[out]codeAn error_code object that will be set to the error that occurred, if any.
Note
This method is available for C++17 and later versions.
Remarks
For C++ versions prior to C++17, member functions with std::u16string and C-strings will be used instead.
Remarks
If scope is disabled in settings (IPADDRESS_IPV6_SCOPE_MAX_LENGTH == 0) then this call will have no effect.

◆ set_scope_id() [12/12]

constexpr inline void set_scope_id ( std::u32string_view scope_id,
error_code & code )
inlinenoexcept

Sets the scope identifier of the IPv6 address using a UTF-32 string view and reports any errors encountered.

This function sets the scope identifier using a UTF-32 string view and provides an error code parameter to report any issues that occur during the operation.

Parameters
[in]scope_idThe UTF-32 string view representing the scope identifier.
[out]codeAn error_code object that will be set to the error that occurred, if any.
Note
This method is available for C++17 and later versions.
Remarks
For C++ versions prior to C++17, member functions with std::u32string and C-strings will be used instead.
Remarks
If scope is disabled in settings (IPADDRESS_IPV6_SCOPE_MAX_LENGTH == 0) then this call will have no effect.

◆ from_uint()

static constexpr inline ip_address_base< ipv6_address_base > from_uint ( uint_type ip)
inlinestaticnoexcept

Creates an IPv6 address from an unsigned integer using a template parameter.

Parameters
[in]ipThe unsigned integer representing the IPv6 address.
Returns
An instance of ip address representing the IPv6 address.

◆ to_uint()

constexpr inline uint_type to_uint ( ) const
inlinenoexcept

Converts the IPv6 address to an unsigned integer.

Returns
The unsigned integer representation of the IPv6 address.
Remarks
Bytes in integer are presented in host byte order.

◆ bytes()

constexpr inline const base_type & bytes ( ) const
inlinenoexcept

Provides access to the underlying bytes of the IPv6 address.

Returns
A reference to the base type containing the bytes of the IPv6 address.
Remarks
Retrieves the data representing the IP address in network byte order (big-endian).

◆ ipv4_mapped()

constexpr inline optional< ipv4_address > ipv4_mapped ( ) const
inlinenoexcept

Determines if the IPv6 address is an IPv4-mapped address.

Returns
An optional containing the mapped IPv4 address if the IPv6 address is IPv4-mapped, or an empty optional otherwise.
Remarks
An IPv4-mapped IPv6 address has its first 80 bits set to zero and the next 16 bits set to one (starting with ::FFFF/96).

◆ sixtofour()

constexpr inline optional< ipv4_address > sixtofour ( ) const
inlinenoexcept

Determines if the IPv6 address is a 6to4 address.

Returns
An optional containing the encapsulated IPv4 address if the IPv6 address is a 6to4 address, or an empty optional otherwise.
Remarks
A 6to4 address uses a 2002::/16 prefix and embeds an IPv4 address in the next 32 bits.
See also
RFC 3056.

◆ teredo()

constexpr inline optional< std::pair< ipv4_address, ipv4_address > > teredo ( ) const
inlinenoexcept

Determines if the IPv6 address is a Teredo address.

Returns
An optional containing a pair of IPv4 addresses representing the Teredo server and client if the IPv6 address is a Teredo address, or an empty optional otherwise.
Return values
std::pair::firstThe Teredo server IPv4 address
std::pair::secondThe Teredo client IPv4 address
Remarks
A Teredo address begins with the 2001::/32 prefix and is used for NAT traversal for IPv6.
See also
RFC 4380.

◆ is_site_local()

constexpr inline bool is_site_local ( ) const
noexcept

Checks if the IPv6 address is a site-local address.

Returns
true if the address is site-local, false otherwise.
Note
Site-local addresses are equivalent to private addresses in IPv4 and are not routable on the global internet.
Remarks
These attribute is true for the network as a whole if it is true for both the network address and the broadcast address.

◆ version()

constexpr inline ip_version version ( ) const
inlinenoexceptinherited

Retrieves the IP version of the address.

Returns
The IP version enumeration value for IPv6.

◆ size()

constexpr inline size_t size ( ) const
inlinenoexceptinherited

Retrieves the size of the IPv6 address.

Returns
The size of the IPv6 address in bytes.

The documentation for this class was generated from the following files: