GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::networking::IPv6Address Class Reference

128-bit IP address of an IPv6 endpoint. More...

#include <GREM/networking/Endpoint.hpp>

Public Member Functions

constexpr IPv6Address (const in6_addr &sin6_addr) noexcept
 Construct an IPv6 address from a native in6_addr structure.
constexpr IPv6Address (uint8_t byte0, uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4, uint8_t byte5, uint8_t byte6, uint8_t byte7, uint8_t byte8, uint8_t byte9, uint8_t byte10, uint8_t byte11, uint8_t byte12, uint8_t byte13, uint8_t byte14, uint8_t byte15) noexcept
 Construct an IPv6 address from its 16 constituent bytes, specified in the same order as in a string representation.
constexpr Array< uint8_t, 16 > toBigEndianBytes () const noexcept
 Convert this IPv6 address to an array of 16 bytes in network byte order.
constexpr bool isAny () const noexcept
 Check if the value of this IPv4 address is equal to the ANY address (::).
constexpr bool isLoopback () const noexcept
 Check if this IPv6 address is equal to the LOOPBACK address (::1).
constexpr in6_addr * get () noexcept
 Get a pointer to the underlying native in6_addr structure of the IPv6 address.
constexpr const in6_addr * get () const noexcept
 Get a pointer to the underlying native in6_addr structure of the IPv6 address.
constexpr bool operator== (const IPv6Address &other) const noexcept
 Compare this address to another for equality.
constexpr std::strong_ordering operator<=> (const IPv6Address &other) const noexcept
 Compare this address to another.

Static Public Member Functions

static Optional< IPv6Address > parse (CStringView string, std::error_code &errorCode) noexcept
 Parse an IPv6 address from an ASCII string representation.
static IPv6Address parse (CStringView string)
 Parse an IPv6 address from an ASCII string representation, throwing an exception on failure.
static Optional< IPv6Address > resolve (const char *hostName, const char *service, std::error_code &errorCode)
 Resolve the IPv6 address of a host through the Domain Name System (DNS) using a getaddrinfo() lookup.
static IPv6Address resolve (const char *hostName, const char *service)
 Resolve the IPv6 address of a host through the Domain Name System (DNS) using a getaddrinfo() lookup, throwing an exception on failure.
static Optional< IPv6Address > resolve (CStringView host, std::error_code &errorCode)
 Resolve the IPv6 address of a host through the Domain Name System (DNS) using a getaddrinfo() lookup.
static IPv6Address resolve (CStringView host)
 Resolve the IPv6 address of a host through the Domain Name System (DNS) using a getaddrinfo() lookup, throwing an exception on failure.
static Optional< IPv6Address > getLocalAddress (std::error_code &errorCode)
 Get the IPv6 address of the local host by calling connect() on a temporary connectionless socket to the loopback address on port 9 (the "Discard" service) and querying its local address with getsockname().
static IPv6Address getLocalAddress ()
 Get the IPv6 address of the local host by calling connect() on a temporary connectionless socket to the loopback address on port 9 (the "Discard" service) and querying its local address with getsockname(), throwing an exception on failure.

Static Public Attributes

static const IPv6Address ANY {detail::IPV6_ADDRESS_ANY}
 Value representing any IPv6 address (::).
static const IPv6Address LOOPBACK {detail::IPV6_ADDRESS_LOOPBACK}
 Value of the IPv6 loopback address (::1).

Detailed Description

128-bit IP address of an IPv6 endpoint.

Constructor & Destructor Documentation

◆ IPv6Address() [1/2]

grem::networking::IPv6Address::IPv6Address ( const in6_addr & sin6_addr)
inlineexplicitconstexprnoexcept

Construct an IPv6 address from a native in6_addr structure.

Parameters
sin6_addrin6_addr structure to construct the IPv6 address from.

◆ IPv6Address() [2/2]

grem::networking::IPv6Address::IPv6Address ( uint8_t byte0,
uint8_t byte1,
uint8_t byte2,
uint8_t byte3,
uint8_t byte4,
uint8_t byte5,
uint8_t byte6,
uint8_t byte7,
uint8_t byte8,
uint8_t byte9,
uint8_t byte10,
uint8_t byte11,
uint8_t byte12,
uint8_t byte13,
uint8_t byte14,
uint8_t byte15 )
inlineconstexprnoexcept

Construct an IPv6 address from its 16 constituent bytes, specified in the same order as in a string representation.

Parameters
byte0first byte value.
byte1second byte value.
byte2third byte value.
byte3fourth byte value.
byte4fifth byte value.
byte5sixth byte value.
byte6seventh byte value.
byte7eighth byte value.
byte8ninth byte value.
byte9tenth byte value.
byte10eleventh byte value.
byte11twelvth byte value.
byte12thirteenth byte value.
byte13fourteenth byte value.
byte14fifteenth byte value.
byte15sixteenth byte value.

Member Function Documentation

◆ parse() [1/2]

Optional< IPv6Address > grem::networking::IPv6Address::parse ( CStringView string,
std::error_code & errorCode )
staticnodiscardnoexcept

Parse an IPv6 address from an ASCII string representation.

Parameters
stringstring containing the IPv6 address representation to parse.
errorCodeerror code that is filled in on failure to parse a valid IPv6 address, or cleared on success.
Returns
the parsed IPv6 address, or an empty optional if parsing failed.

◆ parse() [2/2]

IPv6Address grem::networking::IPv6Address::parse ( CStringView string)
staticnodiscard

Parse an IPv6 address from an ASCII string representation, throwing an exception on failure.

Parameters
stringstring containing the IPv6 address representation to parse.
Returns
the parsed IPv6 address.
Exceptions
networking::Erroron failure to parse a valid IPv6 address.
std::bad_allocon allocation failure.

◆ resolve() [1/4]

Optional< IPv6Address > grem::networking::IPv6Address::resolve ( const char * hostName,
const char * service,
std::error_code & errorCode )
staticnodiscard

Resolve the IPv6 address of a host through the Domain Name System (DNS) using a getaddrinfo() lookup.

Parameters
hostNamenull-terminated domain name or address string of the host to look up, e.g. "example.com" or "::1", or nullptr to look up by service only. Must not be nullptr if service is nullptr.
servicenull-terminated service or port string of the host to look up, e.g. "http" or "80", or nullptr to look up by host name only. Must not be nullptr if hostName is nullptr.
errorCodeerror code that is filled in on failure to resolve the host, or cleared on success.
Returns
the resolved IPv6 address, or an empty optional if resolution failed.

◆ resolve() [2/4]

IPv6Address grem::networking::IPv6Address::resolve ( const char * hostName,
const char * service )
staticnodiscard

Resolve the IPv6 address of a host through the Domain Name System (DNS) using a getaddrinfo() lookup, throwing an exception on failure.

Parameters
hostNamenull-terminated domain name or address string of the host to look up, e.g. "example.com" or "::1", or nullptr to look up by service only. Must not be nullptr if service is nullptr.
servicenull-terminated service or port string of the host to look up, e.g. "http" or "80", or nullptr to look up by host name only. Must not be nullptr if hostName is nullptr.
Returns
the resolved IPv6 address.
Exceptions
networking::Erroron failure to resolve the host.
std::bad_allocon allocation failure.

◆ resolve() [3/4]

Optional< IPv6Address > grem::networking::IPv6Address::resolve ( CStringView host,
std::error_code & errorCode )
staticnodiscard

Resolve the IPv6 address of a host through the Domain Name System (DNS) using a getaddrinfo() lookup.

Parameters
hostcombined host name and service string separated by a colon, with the host enclosed in square brackets if it's an IPv6 address, e.g. "example.com:http" or "[::1]:80", or a host name-only string with no colon or no square brackets, e.g. "example.com" or "::1".
errorCodeerror code that is filled in on failure to resolve the host, or cleared on success.
Returns
the resolved IPv6 address, or an empty optional if resolution failed.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.

◆ resolve() [4/4]

IPv6Address grem::networking::IPv6Address::resolve ( CStringView host)
staticnodiscard

Resolve the IPv6 address of a host through the Domain Name System (DNS) using a getaddrinfo() lookup, throwing an exception on failure.

Parameters
hostcombined host name and service string separated by a colon, with the host enclosed in square brackets if it's an IPv6 address, e.g. "example.com:http" or "[::1]:80", or a host name-only string with no colon or no square brackets, e.g. "example.com" or "::1".
Returns
the resolved IPv6 address.
Exceptions
networking::Erroron failure to resolve the host.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.

◆ getLocalAddress() [1/2]

Optional< IPv6Address > grem::networking::IPv6Address::getLocalAddress ( std::error_code & errorCode)
staticnodiscard

Get the IPv6 address of the local host by calling connect() on a temporary connectionless socket to the loopback address on port 9 (the "Discard" service) and querying its local address with getsockname().

Parameters
errorCodeerror code that is filled in on failure to get the local address, or cleared on success.
Returns
the local IPv6 address, or an empty optional on failure.

◆ getLocalAddress() [2/2]

IPv6Address grem::networking::IPv6Address::getLocalAddress ( )
staticnodiscard

Get the IPv6 address of the local host by calling connect() on a temporary connectionless socket to the loopback address on port 9 (the "Discard" service) and querying its local address with getsockname(), throwing an exception on failure.

Returns
the local IPv6 address.
Exceptions
networking::Erroron failure to get the local address.
std::bad_allocon allocation failure.

◆ toBigEndianBytes()

Array< uint8_t, 16 > grem::networking::IPv6Address::toBigEndianBytes ( ) const
inlinenodiscardconstexprnoexcept

Convert this IPv6 address to an array of 16 bytes in network byte order.

Returns
a big-endian array of the 16 byte values of the address.

◆ isAny()

bool grem::networking::IPv6Address::isAny ( ) const
inlinenodiscardconstexprnoexcept

Check if the value of this IPv4 address is equal to the ANY address (::).

Returns
*this == IPv6Address::ANY.

◆ isLoopback()

bool grem::networking::IPv6Address::isLoopback ( ) const
inlinenodiscardconstexprnoexcept

Check if this IPv6 address is equal to the LOOPBACK address (::1).

Returns
*this == IPv6Address::LOOPBACK.

◆ get() [1/2]

in6_addr * grem::networking::IPv6Address::get ( )
inlinenodiscardconstexprnoexcept

Get a pointer to the underlying native in6_addr structure of the IPv6 address.

Returns
a non-owning pointer to the underlying in6_addr structure.

◆ get() [2/2]

const in6_addr * grem::networking::IPv6Address::get ( ) const
inlinenodiscardconstexprnoexcept

Get a pointer to the underlying native in6_addr structure of the IPv6 address.

Returns
a non-owning read-only pointer to the underlying in6_addr structure.

◆ operator==()

bool grem::networking::IPv6Address::operator== ( const IPv6Address & other) const
inlinenodiscardconstexprnoexcept

Compare this address to another for equality.

Parameters
otherthe address to compare this one to.
Returns
true if the addresses are equal, false otherwise.

◆ operator<=>()

std::strong_ordering grem::networking::IPv6Address::operator<=> ( const IPv6Address & other) const
inlinenodiscardconstexprnoexcept

Compare this address to another.

Parameters
otherthe address to compare this one to.
Returns
a strong ordering between the two addresses, based on the lexicographical ordering of their big-endian byte value arrays.

Member Data Documentation

◆ ANY

IPv6Address grem::networking::IPv6Address::ANY {detail::IPV6_ADDRESS_ANY}
inlinestaticconstexpr

Value representing any IPv6 address (::).

◆ LOOPBACK

IPv6Address grem::networking::IPv6Address::LOOPBACK {detail::IPV6_ADDRESS_LOOPBACK}
inlinestaticconstexpr

Value of the IPv6 loopback address (::1).


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