Class IPv6Address#

Class Documentation#

class IPv6Address#

TRAP::Network::IPv6Address is a utility class for manipulating network addresses. It provides a set of implicit constructors and conversion functions to easily build or transform an IPv6 address from/to various representations.

Public Functions

constexpr IPv6Address() noexcept = default#

This constructor creates an empty (invalid) address.

explicit IPv6Address(const std::string &address)#

Construct the address from a string.

Here address can be either a hex address (ex: “2001:0db8:85a3:0000:0000:8a2e:0370:7334”) or a network name (ex: “localhost”).

Parameters:

address – IPv6 address or network name.

explicit IPv6Address(const char *address)#

Construct the address from a string.

Here address can either be a hex address (ex: “2001:0db8:85a3:0000:0000:8a2e:0370:7334”) or a network name (ex: “localhost”). This is equivalent to the constructor taking a std::string parameter, it is defined for convenience so that the implicit conversion from literal strings to IPv6Address work.

Parameters:

address – IPv6 address or network name.

explicit constexpr IPv6Address(const std::array<u8, 16> &addressBytes) noexcept#

Construct the address from 16 bytes array.

Parameters:

addressBytes – Array containing 16 bytes address.

constexpr IPv6Address(const IPv6Address&) = default#

Copy constructor.

constexpr IPv6Address &operator=(const IPv6Address&) = default#

Copy assignment operator.

constexpr IPv6Address(IPv6Address&&) noexcept = default#

Move constructor.

constexpr IPv6Address &operator=(IPv6Address&&) noexcept = default#

Move assignment operator.

constexpr ~IPv6Address() = default#

Destructor.

std::string ToString() const#

Get a string representation of the address.

The returned string is the hex representation of the IPv6 address (like “2001:0db8:85a3:0000:0000:8a2e:0370:7334”), even if it was constructed from a host name.

Returns:

String representation of the address.

constexpr std::array<u8, 16> ToArray() const noexcept#

Get a byte representation of the address.

The returned array is the byte representation of the IPv6 address, event if it was constructed from a host name.

Returns:

Byte representation of the address.

Public Static Functions

static IPv6Address GetLocalAddress()#

Get the computer’s local address.

The local address is the address of the computer from the LAN point of view, i.e. something like 2001:0db8:85a3:0000:0000:8a2e:0370:7334. It is meaningful only for communications over the local network. Unlike GetPublicAddress, this function is fast and may be used safely anywhere.

Returns:

Local IPv6 address of the computer.

static IPv6Address GetPublicAddress(Utils::TimeStep timeout = Utils::TimeStep(0.0f))#

Get the computer’s public address.

The public address is the address of the computer from the internet point of view, i.e. something like 2001:0db8:85a3:0000:0000:8a2e:0370:7334. It is necessary for communications over the world wide web. The only way to get a public address is to ask it to a distant website; as a consequence, this function depends on both your network connection and the server, and may be very slow. You should use it as few as possible. Because this function depends on the network connection and on a distant sever, you may use a time limit if you don’t want your program to be possibly stuck waiting in case there is a problem; this limit is deactivated by default.

Parameters:

timeout – Maximum time to wait.

Returns:

Public IP address of the computer.

Public Static Attributes

static const IPv6Address None#
static const IPv6Address Any#
static const IPv6Address LocalHost#

Friends

inline friend constexpr auto operator<=>(const IPv6Address &lhs, const IPv6Address &rhs)#
inline friend constexpr bool operator==(const IPv6Address &lhs, const IPv6Address &rhs)#