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

IPv4 address value type. More...

Public Member Functions

constexpr ip4_addr () noexcept=default
 Constructs a zero-initialized IPv4 address (0.0.0.0).
 
constexpr ip4_addr (uint32_t addr) noexcept
 Constructs an IPv4 address from a raw network-byte-order value.
 
constexpr ip4_addr (uint8_t a, uint8_t b, uint8_t c, uint8_t d) noexcept
 Constructs an IPv4 address from individual octets.
 
constexpr uint32_t addr () const noexcept
 Returns the raw address value in network byte order.
 
constexpr bool is_any () const noexcept
 Tests whether this is a zero (unset) address.
 
constexpr bool operator== (const ip4_addr &) const noexcept=default
 Compares two IPv4 addresses for equality.
 

Static Public Member Functions

static std::optional< ip4_addrparse (std::string_view s) noexcept
 Parses an IPv4 address from dotted-decimal notation.
 

Detailed Description

IPv4 address value type.

Stores an IPv4 address in network byte order. Provides construction from individual octets and conversion to string representation.

auto addr = idfxx::net::ip4_addr(192, 168, 1, 1);
auto s = idfxx::to_string(addr); // "192.168.1.1"
IPv4 address value type.
Definition net.hpp:40
constexpr uint32_t addr() const noexcept
Returns the raw address value in network byte order.
Definition net.hpp:92
std::string to_string(core_id c)
Returns a string representation of a CPU core identifier.
Definition cpu.hpp:52
std::expected< T, std::error_code > result
result type wrapping a value or error code.
Definition error.hpp:120

Definition at line 40 of file net.hpp.

Constructor & Destructor Documentation

◆ ip4_addr() [1/3]

constexpr idfxx::net::ip4_addr::ip4_addr ( )
constexprdefaultnoexcept

Constructs a zero-initialized IPv4 address (0.0.0.0).

◆ ip4_addr() [2/3]

constexpr idfxx::net::ip4_addr::ip4_addr ( uint32_t  addr)
inlineexplicitconstexprnoexcept

Constructs an IPv4 address from a raw network-byte-order value.

Parameters
addrThe IPv4 address in network byte order.

Definition at line 70 of file net.hpp.

◆ ip4_addr() [3/3]

constexpr idfxx::net::ip4_addr::ip4_addr ( uint8_t  a,
uint8_t  b,
uint8_t  c,
uint8_t  d 
)
inlineconstexprnoexcept

Constructs an IPv4 address from individual octets.

Parameters
aFirst octet (most significant).
bSecond octet.
cThird octet.
dFourth octet (least significant).

Definition at line 81 of file net.hpp.

Member Function Documentation

◆ addr()

constexpr uint32_t idfxx::net::ip4_addr::addr ( ) const
inlineconstexprnoexcept

Returns the raw address value in network byte order.

Returns
The IPv4 address as a 32-bit integer in network byte order.

Definition at line 92 of file net.hpp.

◆ is_any()

constexpr bool idfxx::net::ip4_addr::is_any ( ) const
inlineconstexprnoexcept

Tests whether this is a zero (unset) address.

Returns
True if the address is 0.0.0.0.

Definition at line 99 of file net.hpp.

◆ operator==()

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

Compares two IPv4 addresses for equality.

◆ parse()

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

Parses an IPv4 address from dotted-decimal notation.

Accepts addresses in the form "a.b.c.d" where each octet is a decimal value from 0 to 255 with no leading zeros.

Parameters
sThe string to parse (e.g. "192.168.1.1").
Returns
The parsed address, or std::nullopt if the string is not valid.
auto addr = idfxx::net::ip4_addr::parse("192.168.1.1");
if (addr) {
// use *addr
}
static std::optional< ip4_addr > parse(std::string_view s) noexcept
Parses an IPv4 address from dotted-decimal notation.

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