libfly  6.2.2
C++20 utility library for Linux, macOS, and Windows
fly::net::IPv4Address Class Reference

#include <ipv4_address.hpp>

Public Types

using address_type = std::array< std::uint8_t, 4 >
 
using int_type = std::uint32_t
 

Public Member Functions

 IPv4Address ()=default
 
constexpr IPv4Address (const address_type &address) noexcept
 
constexpr IPv4Address (int_type address) noexcept
 
 IPv4Address (const IPv4Address &)=default
 
 IPv4Address (IPv4Address &&)=default
 
IPv4Addressoperator= (const IPv4Address &)=default
 
IPv4Addressoperator= (IPv4Address &&)=default
 
constexpr int_type network_order () const
 
constexpr int_type host_order () const
 
auto operator<=> (const IPv4Address &) const =default
 

Static Public Member Functions

static constexpr IPv4Address in_addr_any ()
 
static constexpr IPv4Address in_addr_broadcast ()
 
static constexpr IPv4Address in_addr_loopback ()
 
static constexpr std::optional< IPv4Addressfrom_string (std::string_view address)
 

Detailed Description

Class to store an IPv4 address in network order, and to provide convenient access to its data as required by various network APIs.

Author
Timothy Flynn (trfly.nosp@m.nn89.nosp@m.@pm.m.nosp@m.e)
Version
February 13, 2021

Constructor & Destructor Documentation

◆ IPv4Address() [1/3]

fly::net::IPv4Address::IPv4Address ( )
default

Default constructor. Initializes the IPv4 address to 0.0.0.0.

◆ IPv4Address() [2/3]

constexpr fly::net::IPv4Address::IPv4Address ( const address_type &  address)
explicitconstexprnoexcept

Constructor. Create an IPv4 address from a 4-part array of octets in decimal format. The array should be ordered such that index 0 is the first octet and index 3 is the fourth octet.

Parameters
addressThe 4-part array of octets to initialize the IPv4 address from.

◆ IPv4Address() [3/3]

constexpr fly::net::IPv4Address::IPv4Address ( int_type  address)
explicitconstexprnoexcept

Constructor. Create an IPv4 address from a network-order 32-bit value.

Parameters
addressThe network-order address to initialize the IPv4 address from.

Member Function Documentation

◆ from_string()

constexpr std::optional< IPv4Address > fly::net::IPv4Address::from_string ( std::string_view  address)
staticconstexpr

Construct an IPv4 address from a string in dot-decimal notation.

The provided string must betwen one and four octets, inclusive. If the string contains less than four octets, the last octet is treated as an integer of as many bytes as are required to fill out the address to four octets. Thus, the string "127.65530" is converted to the IPv4 address 127.0.255.250.

Parameters
addressThe string in dot-decimal notation to initialize the IPv4 address from.
Returns
If successful, the constructed IPv4 address. Otherwise, an uninitialized value.

◆ host_order()

constexpr auto fly::net::IPv4Address::host_order ( ) const
constexpr
Returns
The IPv4 address as an integer in host order.

◆ in_addr_any()

constexpr IPv4Address fly::net::IPv4Address::in_addr_any ( )
staticconstexpr
Returns
An IPv4 address representing INADDR_ANY.

◆ in_addr_broadcast()

constexpr IPv4Address fly::net::IPv4Address::in_addr_broadcast ( )
staticconstexpr
Returns
An IPv4 address representing INADDR_BROADCAST.

◆ in_addr_loopback()

constexpr IPv4Address fly::net::IPv4Address::in_addr_loopback ( )
staticconstexpr
Returns
An IPv4 address representing INADDR_LOOPBACK.

◆ network_order()

constexpr auto fly::net::IPv4Address::network_order ( ) const
constexpr
Returns
The IPv4 address as an integer in network order.

◆ operator<=>()

auto fly::net::IPv4Address::operator<=> ( const IPv4Address ) const
default

Three-way-comparison operator. Defaulted to perform the comparison on the network-order IPv4 address.


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