EtcPal  0.4.1
ETC Platform Abstraction Layer (EtcPal)
View other versions:
IpAddr Class Reference

Overview

A wrapper class for the EtcPal IP address type.

Provides C++ syntactic sugar for working with IP addresses.

Public Member Functions

ETCPAL_CONSTEXPR_14 IpAddr () noexcept
 Constructs an invalid IP address by default.
 
constexpr IpAddr (const EtcPalIpAddr &c_ip) noexcept
 Construct an IP address copied from an instance of the C EtcPalIpAddr type.
 
IpAddroperator= (const EtcPalIpAddr &c_ip) noexcept
 Assign an instance of the C EtcPalIpAddr type to an instance of this class.
 
ETCPAL_CONSTEXPR_14 IpAddr (uint32_t v4_data) noexcept
 Construct an IPv4 address from its raw 32-bit representation. More...
 
 IpAddr (const uint8_t *v6_data) noexcept
 Construct an IPv6 address from its raw 16-byte array representation. More...
 
 IpAddr (const uint8_t *v6_data, unsigned long scope_id) noexcept
 Construct an IPv6 address from its raw 16-bytes array representation and scope ID. More...
 
constexpr const EtcPalIpAddrget () const noexcept
 Get a const reference to the underlying C type.
 
ETCPAL_CONSTEXPR_14 EtcPalIpAddrget () noexcept
 Get a mutable reference to the underlying C type.
 
std::string ToString () const
 Convert the IP address to a string representation. More...
 
constexpr uint32_t v4_data () const noexcept
 Get the raw 32-bit representation of an IPv4 address. More...
 
constexpr const uint8_t * v6_data () const noexcept
 Get the raw 16-byte array representation of an IPv6 address. More...
 
std::array< uint8_t, ETCPAL_IPV6_BYTESToV6Array () const
 Get a 16-byte std::array representation of an IPv6 address. More...
 
constexpr unsigned long scope_id () const noexcept
 Get the scope ID of an IPv6 address. More...
 
constexpr bool IsValid () const noexcept
 Whether an IpAddr contains a valid IPv4 or IPv6 address.
 
constexpr IpAddrType type () const noexcept
 Get the type of the IP address.
 
constexpr bool IsV4 () const noexcept
 Whether an IpAddr contains a valid IPv4 address.
 
constexpr bool IsV6 () const noexcept
 Whether an IpAddr contains a valid IPv6 address.
 
bool IsLinkLocal () const noexcept
 Whether an IpAddr contains a link-local address.
 
bool IsLoopback () const noexcept
 Whether an IpAddr contains a loopback address.
 
bool IsMulticast () const noexcept
 Whether an IpAddr contains a multicast address.
 
bool IsWildcard () const noexcept
 Whether an IpAddr contains a wildcard address. More...
 
unsigned int MaskLength () const noexcept
 The number of consecutive set bits in a netmask. More...
 
void SetAddress (uint32_t v4_data) noexcept
 Set the IPv4 address data. More...
 
void SetAddress (const uint8_t *v6_data) noexcept
 Set the IPv6 address data. More...
 
void SetAddress (const uint8_t *v6_data, unsigned long scope_id) noexcept
 Set the IPv6 address data and scope ID. More...
 

Static Public Member Functions

static IpAddr FromString (const char *ip_str) noexcept
 Construct an IpAddr from a string representation. More...
 
static IpAddr FromString (const std::string &ip_str) noexcept
 Construct an IpAddr from a string representation. More...
 
static IpAddr WildcardV4 () noexcept
 Construct a wildcard IPv4 address. More...
 
static IpAddr WildcardV6 () noexcept
 Construct a wildcard IPv6 address. More...
 
static IpAddr Wildcard (IpAddrType type) noexcept
 Construct a wildcard address of the type specified. More...
 
static IpAddr NetmaskV4 (unsigned int mask_length) noexcept
 Construct an IPv4 netmask given a length in bits. More...
 
static IpAddr NetmaskV6 (unsigned int mask_length) noexcept
 Construct an IPv6 netmask given a length in bits. More...
 
static IpAddr Netmask (IpAddrType type, unsigned int mask_length) noexcept
 Construct a netmask of the type specifed given a length in bits. More...
 

Constructor & Destructor Documentation

◆ IpAddr() [1/3]

ETCPAL_CONSTEXPR_14_OR_INLINE IpAddr ( uint32_t  v4_data)
noexcept

Construct an IPv4 address from its raw 32-bit representation.

Parameters
[in]v4_dataThe address data in host byte order.

◆ IpAddr() [2/3]

IpAddr ( const uint8_t *  v6_data)
inlineexplicitnoexcept

Construct an IPv6 address from its raw 16-byte array representation.

Parameters
[in]v6_dataPointer to the address data, an array of length ETCPAL_IPV6_BYTES.

◆ IpAddr() [3/3]

IpAddr ( const uint8_t *  v6_data,
unsigned long  scope_id 
)
inlinenoexcept

Construct an IPv6 address from its raw 16-bytes array representation and scope ID.

See scope_id() for more information.

Parameters
[in]v6_dataPointer to the address data, an array of length ETCPAL_IPV6_BYTES.
[in]scope_idThe address's scope ID.

Member Function Documentation

◆ FromString() [1/2]

IpAddr FromString ( const char *  ip_str)
inlinestaticnoexcept

Construct an IpAddr from a string representation.

See etcpal_string_to_ip() for more information.

◆ FromString() [2/2]

IpAddr FromString ( const std::string &  ip_str)
inlinestaticnoexcept

Construct an IpAddr from a string representation.

See etcpal_string_to_ip() for more information.

◆ IsWildcard()

bool IsWildcard ( ) const
inlinenoexcept

Whether an IpAddr contains a wildcard address.

See etcpal_ip_is_wildcard() for more information.

◆ MaskLength()

unsigned int MaskLength ( ) const
inlinenoexcept

The number of consecutive set bits in a netmask.

See etcpal_ip_mask_length() for more information.

◆ Netmask()

IpAddr Netmask ( IpAddrType  type,
unsigned int  mask_length 
)
inlinestaticnoexcept

Construct a netmask of the type specifed given a length in bits.

See etcpal_ip_mask_from_length() for more information.

◆ NetmaskV4()

IpAddr NetmaskV4 ( unsigned int  mask_length)
inlinestaticnoexcept

Construct an IPv4 netmask given a length in bits.

See etcpal_ip_mask_from_length() for more information.

◆ NetmaskV6()

IpAddr NetmaskV6 ( unsigned int  mask_length)
inlinestaticnoexcept

Construct an IPv6 netmask given a length in bits.

See etcpal_ip_mask_from_length() for more information.

◆ scope_id()

constexpr unsigned long scope_id ( ) const
constexprnoexcept

Get the scope ID of an IPv6 address.

Scope IDs (sometimes referred to as Zone IDs or Zone Indices) are a lightly-documented portion of IPv6 addressing, but one concrete use is to indicate the network interface index of a link-local IPv6 address. See also Network Interface Indexes.

This function will return undefined data if the IpAddr's type is V4 or Invalid.

Returns
The scope ID.

◆ SetAddress() [1/3]

void SetAddress ( const uint8_t *  v6_data)
inlinenoexcept

Set the IPv6 address data.

Automatically converts this address's type to V6.

Parameters
[in]v6_dataPointer to the address data, an array of length ETCPAL_IPV6_BYTES.

◆ SetAddress() [2/3]

void SetAddress ( const uint8_t *  v6_data,
unsigned long  scope_id 
)
inlinenoexcept

Set the IPv6 address data and scope ID.

See scope_id() for more information.

Parameters
[in]v6_dataPointer to the address data, an array of length ETCPAL_IPV6_BYTES.
[in]scope_idThe address's scope ID.

◆ SetAddress() [3/3]

void SetAddress ( uint32_t  v4_data)
inlinenoexcept

Set the IPv4 address data.

Automatically converts this address's type to V4.

Parameters
[in]v4_dataThe address data in host byte order.

◆ ToString()

std::string ToString ( ) const
inline

Convert the IP address to a string representation.

See etcpal_ip_to_string() for more information.

◆ ToV6Array()

std::array< uint8_t, ETCPAL_IPV6_BYTES > ToV6Array ( ) const
inline

Get a 16-byte std::array representation of an IPv6 address.

Copies the data into a new array. This function will return undefined data if the IpAddr's type is V4 or Invalid.

◆ v4_data()

constexpr uint32_t v4_data ( ) const
constexprnoexcept

Get the raw 32-bit representation of an IPv4 address.

This function will return undefined data if the IpAddr's type is V6 or Invalid.

Returns
The address data in host byte order.

◆ v6_data()

constexpr const uint8_t * v6_data ( ) const
constexprnoexcept

Get the raw 16-byte array representation of an IPv6 address.

The returned pointer has the same lifetime as this IpAddr instance. This function will return undefined data if the IpAddr's type is V4 or Invalid.

◆ Wildcard()

IpAddr Wildcard ( IpAddrType  type)
inlinestaticnoexcept

Construct a wildcard address of the type specified.

See etcpal_ip_set_wildcard() for more information.

◆ WildcardV4()

IpAddr WildcardV4 ( )
inlinestaticnoexcept

Construct a wildcard IPv4 address.

See etcpal_ip_set_wildcard() for more information.

◆ WildcardV6()

IpAddr WildcardV6 ( )
inlinestaticnoexcept

Construct a wildcard IPv6 address.

See etcpal_ip_set_wildcard() for more information.


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