|
constexpr | Address () noexcept=default |
| Default constructor. Constructs an object for family AF_UNSPEC.
|
|
template<SockaddrCompatible Sockaddr, tools::OneOf< SocketType, Protocol >... Options> |
| Address (const Sockaddr &nativeAddress, Options... options) |
| Constructor that copies a native address.
|
|
template<tools::OneOf< SocketType, Protocol >... Options> |
| Address (const sockaddr *data, size_type size, Options... options) |
| Constructor that copies a native address with non-standardy size.
|
|
| operator bool () const noexcept |
| Checks whether the object contains a valid address.
|
|
constexpr auto | addressFamily () const noexcept -> int |
| Gets the address family of the address.
|
|
template<tools::OneOf< AddressFamily, SocketType, Protocol >... Criteria> |
auto | supports (Criteria... criteria) const noexcept -> bool |
| Determines whether the address supports a certain set of socket criteria.
|
|
constexpr auto | size () const noexcept -> size_type |
| Gets the size of the underlying sockkaddr structure.
|
|
constexpr auto | data () const noexcept -> const sockaddr * |
| Returns a pointer to the underlying sockkaddr structure.
|
|
constexpr auto | data () noexcept -> sockaddr * |
| Returns a pointer to the underlying sockkaddr structure.
|
|
auto | resize (size_type size) -> void |
| Resets the address to a specific size.
|
|
auto | toString () const -> std::string |
| Gets the numeric representation of the address as a string.
|
|
|
template<tools::OneOf< WithPort, Protocol, SocketType, AddressFamily >... Options> |
static auto | loopback (Options... options) -> Address |
| Creates a loopback address.
|
|
template<tools::OneOf< Protocol, SocketType, AddressFamily >... Options> |
static auto | any (PortNumber portNumber, Options... options) -> Address |
| get a local address suitable for binding to all local interfaces
|
|
template<tools::OneOf< WithPort, RequirePortTag, DefaultPort, Protocol, SocketType, AddressFamily >... Options> |
static auto | resolve (std::string_view hostName, Options... options) -> std::vector< Address > |
| Resolve a host name, returning all suitable addresses.
|
|
template<tools::OneOf< WithPort, RequirePortTag, DefaultPort, Protocol, SocketType, AddressFamily >... Options> |
static auto | resolveSingleAddress (std::string_view hostName, Options... options) -> Address |
| Resolve a host name, returning the first suitable address.
|
|
template<tools::OneOf< WithPort, RequirePortTag, DefaultPort, Protocol, SocketType, AddressFamily >... Options> |
static auto | fromString (std::string_view string, Options... options) -> Address |
| Parse a numeric address string.
|
|
static auto | canonicalName (std::string_view hostName) -> std::string |
| Get the canonical name for a host.
|
|
static auto | join (std::string_view hostName, PortNumber portNumber) -> std::string |
| Joins a host name and a port number.
|
|
static auto | join (std::string_view hostName, std::optional< PortNumber > portNumber) -> std::string |
| Joins a host name and a port number, if necessary.
|
|
static auto | split (std::string_view string) -> std::pair< std::string, std::optional< PortNumber > > |
| Splits a string into a host name and a port number.
|
|
Joins a host name and a port number.
If the host name is a numeric IPv6 address, it is wrapped in square brackets, like in URIs. This is necessary because IPv6 addresses contain colons, and so the port number cannot readily be distinguished from the individual parts of the address itself. For example, the IPv6 loopback address with port number 8080 is represented as "[::1]:8080" to avoid confusion with "::1:8080", which is the abbreviated form of the address "0000:0000:0000:0000:0000:0000:0001:8080"
- Parameters
-
hostName | The host name. The function also supports numeric address strings. |
portNumber | The port number |
- Returns
- the joined string
Joins a host name and a port number, if necessary.
If a port number is specified, and the host name is a numeric IPv6 address, then the address is wrapped in square brackets, like in URIs. This is necessary because IPv6 addresses contain colons, and so the port number cannot readily be distinguished from the individual parts of the address itself. For example, the IPv6 loopback address with port number 8080 is represented as "[::1]:8080" to distinguish it from "::1:8080", which is the abbreviated form of the address "0000:0000:0000:0000:0000:0000:0001:8080"
- Parameters
-
hostName | The host name. The function also supports numeric address strings. |
portNumber | The port number |
- Returns
- the joined string
Resolve a host name, returning all suitable addresses.
Normally, hostName must be a host name or address string, and may not contain a port number, and the returned address will have a port number of 0. You can pass the options xentara::utils::network::WithPort, xentara::utils::network::kRequirePort, or xentara::utils::network::DefaultPort in the options parameter pack to allow or require a port number to be present in hostName, or to change the port number returned in the address. See Option Parameters below for a description of these options.
Depending on the platform, this function may return the same address multiple times if it supports multiple protocols and/or socket types. For each copy of that address, supports() will return true for a different set of criteria. For best results, pass the protocol you wish to use the address for using the xentara::utils::network::Protocol option. If you plan to use the address to establish a TCP/IP connection, for example, pass xentara::utils::network::Protocol(IPPROTO_TCP) as part if the options parameter.
- Note
- This function allows you to specify a number of options for the address lookup, described under Option Parameters below. Just pass the options in the options parameter pack. To resolve a host name for use in a TCP connection with a default port of 8080, for example, use the following call:
static auto resolve(std::string_view hostName, Options... options) -> std::vector< Address >
Resolve a host name, returning all suitable addresses.
- Parameters
-
hostName | The host name. The function also supports numeric address strings. Depending on the options passed in the options parameter pack, hostName may also contain a port number. |
options | The Options to use for the lookup. See Option Parameters below.
- Option Parameters
xentara::utils::network::WithPort(portNumber) | Specifies that the returned address should have the port number portNumber instead of port number 0. This option Cannot be combined with xentara::utils::network::kRequirePort or xentara::utils::network::DefaultPort. |
xentara::utils::network::kRequirePort | Specifies that hostName must contain a port number. Cannot be combined with xentara::utils::network::WithPort or xentara::utils::network::DefaultPort. |
xentara::utils::network::DefaultPort(portNumber) | Specifies that hostName may contain an optional port number. If hostName does not contain a port number, portNumber will be used instead. Cannot be combined with xentara::utils::network::WithPort or xentara::utils::network::kRequirePort. |
xentara::utils::network::Protocol(protocol) | Specifies that the returned addresses should support the protocol protocol. protocol can be any of the XXXPROTO_YYY protocol defines, like IPPROTO_TCP or IPPROTO_UDP. If you do not specify this option, or if you specify 0 for the protocol, then addresses for any protocol will be returned. |
xentara::utils::network::SocketType(socketType) | Specifies that the returned addresses should support the socket type socketType. socketType can be any of the SOCK_XXX socket type defines, like SOCK_STREAM or SOCK_DGRAM. If you do not specify this option, or if you specify 0 for the socket type, then addresses for any socket type will be returned. |
xentara::utils::network::AddressFamily(addressFamily) | Specifies a that only addresses with the address family addressFamily should be returned. addressFamily can be any of the AF_XXX address family defines, like AF_INET or AF_INET6. If you do not specify this option, or if you specify AF_UNSPEC for the address family, then addresses of all families will be returned. You should usually not use this option, to allow communication over both IPv4 and IPv6. Only use this option if you are planning to communicate with legacy software that does not support IPv6. |
|
- Returns
- A list of all suitable addresses listed for the host. This list well never be empty.
- Exceptions
-
static auto xentara::utils::network::Address::resolveSingleAddress |
( |
std::string_view |
hostName, |
|
|
Options... |
options |
|
) |
| -> Address |
|
static |
Resolve a host name, returning the first suitable address.
You should not use this function when trying to establish a connection to a remote host. Instead, use resolve(), and try to connect to all returned addresses in turn.
Normally, hostName must be a host name or address string, and may not contain a port number, and the returned address will have a port number of 0. You can pass the options xentara::utils::network::WithPort, xentara::utils::network::kRequirePort, or xentara::utils::network::DefaultPort in the options parameter pack to allow or require a port number to be present in hostName, or to change the port number returned in the address. See Option Parameters below for a description of these options.
- Note
- This function allows you to specify a number of options for the address lookup, described under Option Parameters below. Just pass the options in the options parameter pack. To resolve a host name for use in a TCP connection with a default port of 8080, for example, use the following call:
static auto resolveSingleAddress(std::string_view hostName, Options... options) -> Address
Resolve a host name, returning the first suitable address.
- Parameters
-
hostName | The host name. The function also supports numeric address strings. Depending on the options passed in the options parameter pack, hostName may also contain a port number. |
options | The Options to use for the lookup. See Option Parameters below.
- Option Parameters
xentara::utils::network::WithPort(portNumber) | Specifies that the returned address should have the port number portNumber instead of port number 0. This option Cannot be combined with xentara::utils::network::kRequirePort or xentara::utils::network::DefaultPort. |
xentara::utils::network::kRequirePort | Specifies that hostName must contain a port number. Cannot be combined with xentara::utils::network::WithPort or xentara::utils::network::DefaultPort. |
xentara::utils::network::DefaultPort(portNumber) | Specifies that hostName may contain an optional port number. If hostName does not contain a port number, portNumber will be used instead. Cannot be combined with xentara::utils::network::WithPort or xentara::utils::network::kRequirePort. |
xentara::utils::network::Protocol(protocol) | Specifies that the returned addresses should support the protocol protocol. protocol can be any of the XXXPROTO_YYY protocol defines, like IPPROTO_TCP or IPPROTO_UDP. If you do not specify this option, or if you specify 0 for the protocol, then addresses for any protocol will be returned. |
xentara::utils::network::SocketType(socketType) | Specifies that the returned addresses should support the socket type socketType. socketType can be any of the SOCK_XXX socket type defines, like SOCK_STREAM or SOCK_DGRAM. If you do not specify this option, or if you specify 0 for the socket type, then addresses for any socket type will be returned. |
xentara::utils::network::AddressFamily(addressFamily) | Specifies a that only addresses with the address family addressFamily should be returned. addressFamily can be any of the AF_XXX address family defines, like AF_INET or AF_INET6. If you do not specify this option, or if you specify AF_UNSPEC for the address family, then addresses of all families will be returned. You should usually not use this option, to allow communication over both IPv4 and IPv6. Only use this option if you are planning to communicate with legacy software that does not support IPv6. |
|
- Returns
- The first suitable address listed for the host.
- Exceptions
-