4#ifndef GREM_NETWORKING_ENDPOINT_HPP
5#define GREM_NETWORKING_ENDPOINT_HPP
25#include <system_error>
32inline constexpr in6_addr IPV6_ADDRESS_ANY = IN6ADDR_ANY_INIT;
33inline constexpr in6_addr IPV6_ADDRESS_LOOPBACK = IN6ADDR_LOOPBACK_INIT;
197 : sin_addr(sin_addr) {}
208 constexpr IPv4Address(uint8_t byte0, uint8_t byte1, uint8_t byte2, uint8_t byte3)
noexcept
210 : sin_addr{.S_un{.S_addr = (
static_cast<uint32_t
>(byte3) << 24) |
211 (
static_cast<uint32_t
>(byte2) << 16) |
212 (
static_cast<uint32_t
>(byte1) << 8) |
213 (
static_cast<uint32_t
>(byte0) << 0)}}
215 : sin_addr{.s_addr = (
static_cast<uint32_t
>(byte3) << 24) |
216 (
static_cast<uint32_t
>(byte2) << 16) |
217 (
static_cast<uint32_t
>(byte1) << 8) |
218 (
static_cast<uint32_t
>(byte0) << 0)}
229 const uint8_t byte0 =
static_cast<uint8_t
>((
static_cast<uint32_t
>(sin_addr.s_addr) >> 0) & 0xFF);
230 const uint8_t byte1 =
static_cast<uint8_t
>((
static_cast<uint32_t
>(sin_addr.s_addr) >> 8) & 0xFF);
231 const uint8_t byte2 =
static_cast<uint8_t
>((
static_cast<uint32_t
>(sin_addr.s_addr) >> 16) & 0xFF);
232 const uint8_t byte3 =
static_cast<uint8_t
>((
static_cast<uint32_t
>(sin_addr.s_addr) >> 24) & 0xFF);
233 return {byte0, byte1, byte2, byte3};
242 [[nodiscard]]
constexpr bool isAny() const noexcept {
254 const uint8_t byte0 =
static_cast<uint8_t
>((
static_cast<uint32_t
>(sin_addr.s_addr) >> 0) & 0xFF);
268 [[nodiscard]]
constexpr bool isPrivate() const noexcept {
269 const uint8_t byte0 =
static_cast<uint8_t
>((
static_cast<uint32_t
>(sin_addr.s_addr) >> 0) & 0xFF);
270 const uint8_t byte1 =
static_cast<uint8_t
>((
static_cast<uint32_t
>(sin_addr.s_addr) >> 8) & 0xFF);
271 return byte0 == 10 || (byte0 == 172 && byte1 >= 16 && byte1 < 32) || (byte0 == 192 && byte1 == 168);
280 [[nodiscard]]
constexpr in_addr*
get() noexcept {
291 [[nodiscard]]
constexpr const in_addr*
get() const noexcept {
319 constexpr explicit IPv4Address(uint32_t address) noexcept
321 sin_addr.s_addr = (
static_cast<uint32_t
>(address << 24) & uint32_t{0xFF000000}) |
322 (
static_cast<uint32_t
>(address << 8) & uint32_t{0x00FF0000}) |
323 (
static_cast<uint32_t
>(address >> 8) & uint32_t{0x0000FF00}) |
324 (
static_cast<uint32_t
>(address >> 24) & uint32_t{0x000000FF});
471 constexpr explicit IPv6Address(
const in6_addr& sin6_addr) noexcept
472 : sin6_addr(sin6_addr) {}
495 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,
496 uint8_t byte10, uint8_t byte11, uint8_t byte12, uint8_t byte13, uint8_t byte14, uint8_t byte15) noexcept
497 : sin6_addr(bit_cast<in6_addr>(
Array<uint8_t, 16>{byte0, byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8, byte9, byte10, byte11, byte12, byte13, byte14, byte15})) {}
505 return bit_cast<Array<uint8_t, 16>>(sin6_addr);
513 [[nodiscard]]
constexpr bool isAny() const noexcept {
516 return *
this ==
IPv6Address{detail::IPV6_ADDRESS_ANY};
527 return *
this ==
IPv6Address{detail::IPV6_ADDRESS_LOOPBACK};
536 [[nodiscard]]
constexpr in6_addr*
get() noexcept {
547 [[nodiscard]]
constexpr const in6_addr*
get() const noexcept {
755 addr.sin_family = AF_INET;
757 addr.sin_len =
sizeof(addr);
759 addr.sin_addr = *address.get();
777 addr.sin_addr = *newAddress.get();
849 [[nodiscard]]
constexpr sockaddr_in*
get() noexcept {
860 [[nodiscard]]
constexpr const sockaddr_in*
get() const noexcept {
1068 addr.sin6_family = AF_INET6;
1070 addr.sin_len =
sizeof(addr);
1072 addr.sin6_addr = *address.get();
1074 addr.sin6_scope_id = scopeID;
1091 addr.sin6_addr = *newAddress.get();
1109 addr.sin6_scope_id = newScopeID;
1136 return addr.sin6_scope_id;
1165 [[nodiscard]]
constexpr sockaddr_in6*
get() noexcept {
1176 [[nodiscard]]
constexpr const sockaddr_in6*
get() const noexcept {
1301 std::error_code& errorCode)
noexcept;
1580 template <
typename SockAddr>
1586 memcpy(storage, addrStorage,
static_cast<size_t>(
length));
1595 memcpy(storage, endpoint.get(),
sizeof(*endpoint.get()));
1604 memcpy(storage, endpoint.get(),
sizeof(*endpoint.get()));
1647 memcpy(storage, other.storage,
sizeof(other.storage));
1656 memcpy(storage, other.storage,
sizeof(other.storage));
1662 return *
this = other;
1684 memcpy(&family, storage,
sizeof(family));
1806 [[nodiscard]] sockaddr*
get() noexcept {
1807 return reinterpret_cast<sockaddr*
>(storage);
1816 [[nodiscard]]
const sockaddr*
get() const noexcept {
1817 return reinterpret_cast<const sockaddr*
>(storage);
1830 if (family == otherFamily) {
1850 if (family == otherFamily) {
1855 return std::strong_ordering::equal;
1857 return family <=> otherFamily;
1861 alignas(sockaddr_storage)
byte storage[
sizeof(sockaddr_storage)];
1867struct std::hash<
grem::networking::IPv4Address> {
1874struct std::hash<
grem::networking::IPv6Address> {
1882struct std::hash<
grem::networking::IPv4Endpoint> {
1889struct std::hash<
grem::networking::IPv6Endpoint> {
1896struct std::hash<
grem::networking::Endpoint> {
1909 std::error_code errorCode{};
1916 const char*
string = inet_ntop(AF_INET, value.
get(), buffer.
data(),
static_cast<socklen_t
>(buffer.
size()));
1927 std::error_code errorCode{};
1934 const char*
string = inet_ntop(AF_INET6, value.
get(), buffer.
data(),
static_cast<socklen_t
>(buffer.
size()));
#define GREM_ASSERT(expression)
Definition assertions.hpp:77
Optional value type that holds either a value or no value.
Definition Optional.hpp:58
Combined network address and port number (and potentially other info) that identifies a host,...
Definition Endpoint.hpp:1215
static Optional< Endpoint > resolve(const char *hostName, const char *service, std::error_code &errorCode)
Resolve the endpoint address and port number of a host through the Domain Name System (DNS) using a g...
static Endpoint parse(AddressFamily family, CStringView string)
Parse an endpoint address of a specific address family type from an ASCII string representation with ...
static Endpoint resolve(AddressFamily family, CStringView host)
Resolve the endpoint address and port number of a host with a specific address family type through th...
static Endpoint loopback(AddressFamily family, PortNumber portNumber=0) noexcept
Create an endpoint with the LOOPBACK address (0.0.0.0 or ::) for a given address family.
Definition Endpoint.hpp:1246
socklen_t getLength() const noexcept
Get the size of the endpoint's underlying native address structure.
Definition Endpoint.hpp:1693
bool isAddressAny() const noexcept
Check if the value of this endpoint's address is equal to the ANY address (0.0.0.0 or ::).
Definition Endpoint.hpp:1779
Endpoint(const SockAddr *addrStorage, socklen_t length)
Construct an endpoint from a native sockaddr_storage buffer.
Definition Endpoint.hpp:1581
static Optional< Endpoint > parse(CStringView string, std::error_code &errorCode) noexcept
Parse an endpoint address from an ASCII string representation with an optional decimal port number.
Endpoint(const Endpoint &other) noexcept
Copy constructor.
Definition Endpoint.hpp:1646
static Optional< Endpoint > getLocalEndpoint(AddressFamily family, std::error_code &errorCode)
Get the endpoint address and port of the local host by calling connect() on a temporary connectionles...
Endpoint(const IPv6Address &address, PortNumber port=0, ScopeID scopeID=0) noexcept
Construct an endpoint from an IPv4 address and port number.
Definition Endpoint.hpp:1623
static Endpoint getLocalEndpoint(AddressFamily family)
Get the endpoint address and port of the local host by calling connect() on a temporary connectionles...
Endpoint(Endpoint &&other) noexcept
Move constructor.
Definition Endpoint.hpp:1651
bool operator==(const Endpoint &other) const noexcept
Compare this endpoint to another for equality.
Definition Endpoint.hpp:1827
void setPortNumber(PortNumber newPortNumber) noexcept
Set the port number of the endpoint.
Definition Endpoint.hpp:1670
std::strong_ordering operator<=>(const Endpoint &other) const noexcept
Compare this endpoint to another.
Definition Endpoint.hpp:1847
Endpoint(const sockaddr_in6 &addr) noexcept
Construct an IPv6 endpoint from a native sockaddr_in6 structure.
Definition Endpoint.hpp:1639
static Optional< Endpoint > resolve(AddressFamily family, CStringView host, std::error_code &errorCode)
Resolve the endpoint address and port number of a host with a specific address family type through th...
static Optional< Endpoint > parse(AddressFamily family, CStringView string, std::error_code &errorCode) noexcept
Parse an endpoint address of a specific address family type from an ASCII string representation with ...
Endpoint(const IPv4Address &address, PortNumber port=0) noexcept
Construct an endpoint from an IPv4 address and port number.
Definition Endpoint.hpp:1613
static Optional< Endpoint > parse(CStringView addressString, CStringView portNumberString, std::error_code &errorCode) noexcept
Parse an endpoint address from an ASCII string representation, and a port number from a decimal ASCII...
static Optional< Endpoint > parse(AddressFamily family, CStringView addressString, CStringView portNumberString, std::error_code &errorCode) noexcept
Parse an endpoint address of a specific address family type from an ASCII string representation,...
Endpoint(const sockaddr_in &addr) noexcept
Construct an IPv4 endpoint from a native sockaddr_in structure.
Definition Endpoint.hpp:1631
static Endpoint resolve(CStringView host)
Resolve the endpoint address and port number of a host through the Domain Name System (DNS) using a g...
~Endpoint()=default
Destructor.
Endpoint(const IPv4Endpoint &endpoint) noexcept
Implicitly convert or construct a generic endpoint from an IPv4 endpoint.
Definition Endpoint.hpp:1594
Optional< IPv6Address > getIPv6Address() const noexcept
Get the IPv6 address of this endpoint.
Definition Endpoint.hpp:1741
sockaddr * get() noexcept
Get a pointer to the underlying native address structure of the endpoint.
Definition Endpoint.hpp:1806
Endpoint & operator=(const Endpoint &other) noexcept
Copy assignment.
Definition Endpoint.hpp:1655
AddressFamily getAddressFamily() const noexcept
Get the address family of the endpoint.
Definition Endpoint.hpp:1682
ScopeID getScopeID() const noexcept
Get the scope/zone ID of the endpoint.
Definition Endpoint.hpp:1765
Endpoint(const IPv6Endpoint &endpoint) noexcept
Implicitly convert or construct a generic endpoint from an IPv6 endpoint.
Definition Endpoint.hpp:1603
static Optional< Endpoint > resolve(AddressFamily family, const char *hostName, const char *service, std::error_code &errorCode)
Resolve the endpoint address and port number of a host with a specific address family type through th...
Endpoint & operator=(Endpoint &&other) noexcept
Move assignment.
Definition Endpoint.hpp:1661
static Endpoint resolve(AddressFamily family, const char *hostName, const char *service)
Resolve the endpoint address and port number of a host with a specific address family type through th...
static Endpoint parse(CStringView string)
Parse an endpoint address from an ASCII string representation with an optional decimal port number,...
static Endpoint resolve(const char *hostName, const char *service)
Resolve the endpoint address and port number of a host through the Domain Name System (DNS) using a g...
const sockaddr * get() const noexcept
Get a pointer to the underlying native address structure of the endpoint.
Definition Endpoint.hpp:1816
static Optional< Endpoint > resolve(CStringView host, std::error_code &errorCode)
Resolve the endpoint address and port number of a host through the Domain Name System (DNS) using a g...
static Endpoint parse(CStringView addressString, CStringView portNumberString)
Parse an endpoint address from an ASCII string representation, and a port number from a decimal ASCII...
static Endpoint parse(AddressFamily family, CStringView addressString, CStringView portNumberString)
Parse an endpoint address of a specific address family type from an ASCII string representation,...
bool isAddressLoopback() const noexcept
Check if the value of this endpoint's address is a loopback address (127.X.X.X or ::1).
Definition Endpoint.hpp:1793
Optional< IPv4Address > getIPv4Address() const noexcept
Get the IPv4 address of this endpoint.
Definition Endpoint.hpp:1731
Optional< IPv4Endpoint > getIPv4Endpoint() const noexcept
Get the IPv4 endpoint stored by this endpoint.
Definition Endpoint.hpp:1707
PortNumber getPortNumber() const noexcept
Get the port number of the endpoint.
Definition Endpoint.hpp:1751
Optional< IPv6Endpoint > getIPv6Endpoint() const noexcept
Get the IPv6 endpoint stored by this endpoint.
Definition Endpoint.hpp:1719
static Endpoint any(AddressFamily family, PortNumber portNumber=0) noexcept
Create an endpoint with the ANY address (0.0.0.0 or ::) for a given address family.
Definition Endpoint.hpp:1227
32-bit IP address of an IPv4 endpoint.
Definition Endpoint.hpp:60
constexpr IPv4Address(uint8_t byte0, uint8_t byte1, uint8_t byte2, uint8_t byte3) noexcept
Construct an IPv4 address from its 4 constituent bytes, specified in the same order as in a dot-decim...
Definition Endpoint.hpp:208
constexpr bool isPrivate() const noexcept
Check if this IPv4 address is in a private address range.
Definition Endpoint.hpp:268
constexpr IPv4Address(const in_addr &sin_addr) noexcept
Construct an IPv4 address from a native in_addr structure.
Definition Endpoint.hpp:196
static Optional< IPv4Address > getLocalAddress(std::error_code &errorCode)
Get the IPv4 address of the local host on the local network by calling connect() on a temporary conne...
constexpr bool isLoopback() const noexcept
Check if this IPv4 address is a loopback address (starts with 127).
Definition Endpoint.hpp:253
static IPv4Address resolve(const char *hostName, const char *service)
Resolve the IPv4 address of a host through the Domain Name System (DNS) using a getaddrinfo() lookup,...
constexpr in_addr * get() noexcept
Get a pointer to the underlying native in_addr structure of the IPv4 address.
Definition Endpoint.hpp:280
static const IPv4Address ANY
Value representing any IPv4 address (0.0.0.0).
Definition Endpoint.hpp:62
static Optional< IPv4Address > resolve(CStringView host, std::error_code &errorCode)
Resolve the IPv4 address of a host through the Domain Name System (DNS) using a getaddrinfo() lookup.
constexpr const in_addr * get() const noexcept
Get a pointer to the underlying native in_addr structure of the IPv4 address.
Definition Endpoint.hpp:291
static const IPv4Address NONE
Value representing no IPv4 address (255.255.255.255).
Definition Endpoint.hpp:64
static const IPv4Address BROADCAST
Value of the IPv4 broadcast address (255.255.255.255).
Definition Endpoint.hpp:63
constexpr bool isAny() const noexcept
Check if the value of this IPv4 address is equal to the ANY address (0.0.0.0).
Definition Endpoint.hpp:242
constexpr Array< uint8_t, 4 > toBigEndianBytes() const noexcept
Convert this IPv4 address to an array of 4 bytes in network byte order.
Definition Endpoint.hpp:228
static Optional< IPv4Address > parse(CStringView string, std::error_code &errorCode) noexcept
Parse an IPv4 address from an ASCII string in dot-decimal notation.
static Optional< IPv4Address > resolve(const char *hostName, const char *service, std::error_code &errorCode)
Resolve the IPv4 address of a host through the Domain Name System (DNS) using a getaddrinfo() lookup.
static const IPv4Address LOOPBACK
Value of the standard IPv4 loopback address (127.0.0.1).
Definition Endpoint.hpp:65
constexpr bool operator==(IPv4Address other) const noexcept
Compare this address to another for equality.
Definition Endpoint.hpp:302
static IPv4Address parse(CStringView string)
Parse an IPv4 address from an ASCII string in dot-decimal notation, throwing an exception on failure.
static IPv4Address resolve(CStringView host)
Resolve the IPv4 address of a host through the Domain Name System (DNS) using a getaddrinfo() lookup,...
static IPv4Address getLocalAddress()
Get the IPv4 address of the local host on the local network by calling connect() on a temporary conne...
constexpr std::strong_ordering operator<=>(IPv4Address other) const noexcept
Compare this address to another.
Definition Endpoint.hpp:314
Combined IPv4Address and PortNumber.
Definition Endpoint.hpp:584
static IPv4Endpoint getLocalEndpoint()
Get the IPv4 address and port of the local host on the local network by calling connect() on a tempor...
constexpr IPv4Endpoint(IPv4Address address, PortNumber port=0) noexcept
Construct an IPv4 endpoint from an IPv4 address and port number.
Definition Endpoint.hpp:753
constexpr IPv4Address getAddress() const noexcept
Get the address of the endpoint.
Definition Endpoint.hpp:794
constexpr IPv4Endpoint(const sockaddr_in &addr) noexcept
Construct an IPv4 endpoint from a native sockaddr_in structure.
Definition Endpoint.hpp:768
constexpr PortNumber getPortNumber() const noexcept
Get the port number of the endpoint.
Definition Endpoint.hpp:803
constexpr const sockaddr_in * get() const noexcept
Get a pointer to the underlying native sockaddr_in structure of the IPv4 endpoint.
Definition Endpoint.hpp:860
static Optional< IPv4Endpoint > getLocalEndpoint(std::error_code &errorCode)
Get the IPv4 address and port of the local host on the local network by calling connect() on a tempor...
static Optional< IPv4Endpoint > resolve(CStringView host, std::error_code &errorCode)
Resolve the IPv4 address and port number of a host through the Domain Name System (DNS) using a getad...
static Optional< IPv4Endpoint > parse(CStringView addressString, CStringView portNumberString, std::error_code &errorCode) noexcept
Parse an IPv4 address from an ASCII string in dot-decimal notation, and a port number from a decimal ...
constexpr void setPortNumber(PortNumber newPortNumber) noexcept
Set the port number of the endpoint.
Definition Endpoint.hpp:785
constexpr void setAddress(IPv4Address newAddress) noexcept
Set the address of the endpoint.
Definition Endpoint.hpp:776
constexpr sockaddr_in * get() noexcept
Get a pointer to the underlying native sockaddr_in structure of the IPv4 endpoint.
Definition Endpoint.hpp:849
constexpr bool isAddressPrivate() const noexcept
Check if this endpoint's IPv4 address is in a private address range.
Definition Endpoint.hpp:839
static Optional< IPv4Endpoint > resolve(const char *hostName, const char *service, std::error_code &errorCode)
Resolve the IPv4 address and port number of a host through the Domain Name System (DNS) using a getad...
constexpr std::strong_ordering operator<=>(IPv4Endpoint other) const noexcept
Compare this endpoint to another.
Definition Endpoint.hpp:884
static IPv4Endpoint resolve(CStringView host)
Resolve the IPv4 address and port number of a host through the Domain Name System (DNS) using a getad...
constexpr bool isAddressAny() const noexcept
Check if the value of this endpoint's IPv4 address is equal to the ANY address (0....
Definition Endpoint.hpp:813
constexpr bool isAddressLoopback() const noexcept
Check if this endpoint's IPv4 address is a loopback address (starts with 127).
Definition Endpoint.hpp:824
static IPv4Endpoint resolve(const char *hostName, const char *service)
Resolve the IPv4 address and port number of a host through the Domain Name System (DNS) using a getad...
constexpr bool operator==(IPv4Endpoint other) const noexcept
Compare this endpoint to another for equality.
Definition Endpoint.hpp:871
static IPv4Endpoint parse(CStringView string)
Parse an IPv4 address from an ASCII string in dot-decimal notation with an optional decimal port numb...
static IPv4Endpoint parse(CStringView addressString, CStringView portNumberString)
Parse an IPv4 address from an ASCII string in dot-decimal notation, and a port number from a decimal ...
static Optional< IPv4Endpoint > parse(CStringView string, std::error_code &errorCode) noexcept
Parse an IPv4 address from an ASCII string in dot-decimal notation with an optional decimal port numb...
128-bit IP address of an IPv6 endpoint.
Definition Endpoint.hpp:338
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 r...
Definition Endpoint.hpp:495
static const IPv6Address ANY
Value representing any IPv6 address (::).
Definition Endpoint.hpp:340
constexpr std::strong_ordering operator<=>(const IPv6Address &other) const noexcept
Compare this address to another.
Definition Endpoint.hpp:570
constexpr bool isLoopback() const noexcept
Check if this IPv6 address is equal to the LOOPBACK address (::1).
Definition Endpoint.hpp:524
constexpr IPv6Address(const in6_addr &sin6_addr) noexcept
Construct an IPv6 address from a native in6_addr structure.
Definition Endpoint.hpp:471
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 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 const IPv6Address LOOPBACK
Value of the IPv6 loopback address (::1).
Definition Endpoint.hpp:341
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,...
constexpr bool operator==(const IPv6Address &other) const noexcept
Compare this address to another for equality.
Definition Endpoint.hpp:558
static IPv6Address getLocalAddress()
Get the IPv6 address of the local host by calling connect() on a temporary connectionless socket to t...
static IPv6Address resolve(CStringView host)
Resolve the IPv6 address of a host through the Domain Name System (DNS) using a getaddrinfo() lookup,...
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 t...
constexpr Array< uint8_t, 16 > toBigEndianBytes() const noexcept
Convert this IPv6 address to an array of 16 bytes in network byte order.
Definition Endpoint.hpp:504
constexpr const in6_addr * get() const noexcept
Get a pointer to the underlying native in6_addr structure of the IPv6 address.
Definition Endpoint.hpp:547
static IPv6Address parse(CStringView string)
Parse an IPv6 address from an ASCII string representation, throwing an exception on failure.
constexpr in6_addr * get() noexcept
Get a pointer to the underlying native in6_addr structure of the IPv6 address.
Definition Endpoint.hpp:536
static Optional< IPv6Address > parse(CStringView string, std::error_code &errorCode) noexcept
Parse an IPv6 address from an ASCII string representation.
constexpr bool isAny() const noexcept
Check if the value of this IPv4 address is equal to the ANY address (::).
Definition Endpoint.hpp:513
Combined IPv6Address, PortNumber and ScopeID.
Definition Endpoint.hpp:895
constexpr std::strong_ordering operator<=>(const IPv6Endpoint &other) const noexcept
Compare this endpoint to another.
Definition Endpoint.hpp:1202
static IPv6Endpoint getLocalEndpoint()
Get the IPv6 address and port of the local host by calling connect() on a temporary connectionless so...
constexpr void setAddress(const IPv6Address &newAddress) noexcept
Set the address of the endpoint.
Definition Endpoint.hpp:1090
constexpr PortNumber getPortNumber() const noexcept
Get the port number of the endpoint.
Definition Endpoint.hpp:1126
static IPv6Endpoint resolve(CStringView host)
Resolve the IPv6 address and port number of a host through the Domain Name System (DNS) using a getad...
static IPv6Endpoint resolve(const char *hostName, const char *service)
Resolve the IPv6 address and port number of a host through the Domain Name System (DNS) using a getad...
constexpr bool isAddressLoopback() const noexcept
Check if the value of this endpoint's IPv6 address is equal to the LOOPBACK address (::1).
Definition Endpoint.hpp:1155
constexpr void setPortNumber(PortNumber newPortNumber) noexcept
Set the port number of the endpoint.
Definition Endpoint.hpp:1099
static Optional< IPv6Endpoint > resolve(CStringView host, std::error_code &errorCode)
Resolve the IPv6 address and port number of a host through the Domain Name System (DNS) using a getad...
constexpr const sockaddr_in6 * get() const noexcept
Get a pointer to the underlying native sockaddr_in6 structure of the IPv6 endpoint.
Definition Endpoint.hpp:1176
constexpr sockaddr_in6 * get() noexcept
Get a pointer to the underlying native sockaddr_in6 structure of the IPv6 endpoint.
Definition Endpoint.hpp:1165
static Optional< IPv6Endpoint > parse(CStringView addressString, CStringView portNumberString, std::error_code &errorCode) noexcept
Parse an IPv6 address from an ASCII string representation, and a port number from a decimal ASCII str...
constexpr bool isAddressAny() const noexcept
Check if the value of this endpoint's IPv6 address is equal to the ANY address (::).
Definition Endpoint.hpp:1145
static IPv6Endpoint parse(CStringView addressString, CStringView portNumberString)
Parse an IPv6 address from an ASCII string representation, and a port number from a decimal ASCII str...
static IPv6Endpoint parse(CStringView string)
Parse an IPv6 address from an ASCII string representation with an optional decimal port number,...
constexpr IPv6Endpoint(const sockaddr_in6 &addr) noexcept
Construct an IPv6 endpoint from a native sockaddr_in6 structure.
Definition Endpoint.hpp:1082
constexpr void setScopeID(ScopeID newScopeID) noexcept
Set the scope/zone ID of the endpoint.
Definition Endpoint.hpp:1108
constexpr IPv6Address getAddress() const noexcept
Get the address of the endpoint.
Definition Endpoint.hpp:1117
constexpr IPv6Endpoint(const IPv6Address &address, PortNumber port=0, ScopeID scopeID=0) noexcept
Construct an IPv6 endpoint from an IPv6 address, port number and scope/zone ID.
Definition Endpoint.hpp:1066
constexpr ScopeID getScopeID() const noexcept
Get the scope/zone ID of the endpoint.
Definition Endpoint.hpp:1135
constexpr bool operator==(const IPv6Endpoint &other) const noexcept
Compare this endpoint to another for equality.
Definition Endpoint.hpp:1188
static Optional< IPv6Endpoint > parse(CStringView string, std::error_code &errorCode) noexcept
Parse an IPv6 address from an ASCII string representation with an optional decimal port number.
static Optional< IPv6Endpoint > resolve(const char *hostName, const char *service, std::error_code &errorCode)
Resolve the IPv6 address and port number of a host through the Domain Name System (DNS) using a getad...
static Optional< IPv6Endpoint > getLocalEndpoint(std::error_code &errorCode)
Get the IPv6 address and port of the local host by calling connect() on a temporary connectionless so...
Definition concepts.hpp:47
Definition concepts.hpp:35
Definition Endpoint.hpp:28
void ensurePlatformInitialized(std::error_code &errorCode)
Initialize the underlying platform of the native socket API if it has not already been initialized.
AddressFamily
Address family of an IP endpoint.
Definition Endpoint.hpp:52
@ IPv4
IPv4.
Definition Endpoint.hpp:53
@ IPv6
IPv6.
Definition Endpoint.hpp:54
uint32_t ScopeID
IPv6 scope/zone ID.
Definition Endpoint.hpp:47
uint16_t PortNumber
IP port number (0-65535).
Definition Endpoint.hpp:42
GREM_ALWAYS_INLINE constexpr T convertHostEndianToBigEndian(T value)
Convert a value in host-endian byte order to the corresponding value in big-endian byte order.
Definition fundamentals.hpp:486
GREM_ALWAYS_INLINE constexpr T convertBigEndianToHostEndian(T value)
Convert a value in big-endian byte order to the corresponding value in host-endian byte order.
Definition fundamentals.hpp:523
void unreachable()
Definition assertions.hpp:125
constexpr std::size_t getRangeHash(input_range auto &&range)
Definition algorithms.hpp:151
constexpr std::size_t getHash(const T &value, const Ts &... otherValues)
Definition algorithms.hpp:147
GREM_ALWAYS_INLINE constexpr T GREM_VECTORCALL length(T a)
Definition math.hpp:2001
CStringViewBase< char, std::char_traits< char > > CStringView
Definition CStringView.hpp:635
constexpr size_type size() const noexcept
Definition Array.hpp:139
constexpr pointer data() noexcept
Definition Array.hpp:79
Exception type for domain-specific errors originating from the grem::networking module.
Definition Error.hpp:22
static std::error_code getLastErrorCode() noexcept
std::size_t operator()(const grem::networking::Endpoint &endpoint) const
Definition Endpoint.hpp:1897
std::size_t operator()(const grem::networking::IPv4Address &address) const
Definition Endpoint.hpp:1868
std::size_t operator()(const grem::networking::IPv4Endpoint &endpoint) const
Definition Endpoint.hpp:1883
std::size_t operator()(const grem::networking::IPv6Address &address) const
Definition Endpoint.hpp:1875
std::size_t operator()(const grem::networking::IPv6Endpoint &endpoint) const
Definition Endpoint.hpp:1890