idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
idfxx::net::endpoint Class Reference

Address/port pair identifying a transport endpoint. More...

Public Member Functions

constexpr endpoint (ipv4_addr addr, port_number port) noexcept
 Constructs an IPv4 endpoint.
 
constexpr endpoint (ipv6_addr addr, port_number port) noexcept
 Constructs an IPv6 endpoint.
 
constexpr address_family family () const noexcept
 Returns the address family of this endpoint.
 
constexpr port_number port () const noexcept
 Returns the port number in host byte order.
 
template<ip_address T>
constexpr std::optional< Taddress () const noexcept
 Returns the address held by this endpoint, if it is of the requested type.
 
constexpr bool operator== (const endpoint &) const noexcept=default
 Compares two endpoints for equality.
 

Static Public Member Functions

static std::optional< endpointparse (std::string_view s) noexcept
 Parses an endpoint from a host:port or [host]:port string.
 

Detailed Description

Address/port pair identifying a transport endpoint.

An endpoint carries either an IPv4 or IPv6 address together with a port number. It always holds an address — there is no empty state, so it is not default-constructible.

idfxx::net::endpoint server(idfxx::net::ipv4_addr(192, 168, 1, 10), 8080);
if (auto e = idfxx::net::endpoint::parse("[fe80::1]:80")) {
// *e is a v6 endpoint
}
Address/port pair identifying a transport endpoint.
Definition endpoint.hpp:129
static std::optional< endpoint > parse(std::string_view s) noexcept
Parses an endpoint from a host:port or [host]:port string.
IPv4 address value type.
Definition net.hpp:41
std::expected< T, std::error_code > result
result type wrapping a value or error code.
Definition error.hpp:120

Definition at line 129 of file endpoint.hpp.

Constructor & Destructor Documentation

◆ endpoint() [1/2]

constexpr idfxx::net::endpoint::endpoint ( ipv4_addr  addr,
port_number  port 
)
inlineconstexprnoexcept

Constructs an IPv4 endpoint.

Parameters
addrIPv4 address.
portPort number in host byte order.

Definition at line 137 of file endpoint.hpp.

References port().

◆ endpoint() [2/2]

constexpr idfxx::net::endpoint::endpoint ( ipv6_addr  addr,
port_number  port 
)
inlineconstexprnoexcept

Constructs an IPv6 endpoint.

Parameters
addrIPv6 address.
portPort number in host byte order.

Definition at line 146 of file endpoint.hpp.

References port().

Member Function Documentation

◆ address()

template<ip_address T>
constexpr std::optional< T > idfxx::net::endpoint::address ( ) const
inlineconstexprnoexcept

Returns the address held by this endpoint, if it is of the requested type.

Template Parameters
Tipv4_addr or ipv6_addr.
Returns
The address, or std::nullopt if the endpoint holds an address of a different family.
if (auto v4 = ep.address<idfxx::net::ipv4_addr>()) {
// *v4 is the IPv4 address
}

Definition at line 200 of file endpoint.hpp.

◆ family()

constexpr address_family idfxx::net::endpoint::family ( ) const
inlineconstexprnoexcept

Returns the address family of this endpoint.

Returns
address_family::ipv4 or address_family::ipv6.

Definition at line 169 of file endpoint.hpp.

References idfxx::net::ipv4, and idfxx::net::ipv6.

◆ operator==()

constexpr bool idfxx::net::endpoint::operator== ( const endpoint ) const
constexprdefaultnoexcept

Compares two endpoints for equality.

◆ parse()

static std::optional< endpoint > idfxx::net::endpoint::parse ( std::string_view  s)
staticnoexcept

Parses an endpoint from a host:port or [host]:port string.

Accepts:

  • 1.2.3.4:80 for IPv4
  • [fe80::1]:80 (with bracketed v6 address) for IPv6

The host part is parsed by ipv4_addr::parse or ipv6_addr::parse; names are not resolved.

Parameters
sThe string to parse.
Returns
The parsed endpoint, or std::nullopt on failure.

◆ port()

constexpr port_number idfxx::net::endpoint::port ( ) const
inlineconstexprnoexcept

Returns the port number in host byte order.

Returns
The port number.

Definition at line 181 of file endpoint.hpp.

Referenced by endpoint(), and endpoint().


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