LibSWOC++ 1.5.14
Solid Wall of C++
Loading...
Searching...
No Matches
swoc::IP6Addr Class Reference

#include <IPAddr.h>

Collaboration diagram for swoc::IP6Addr:
Collaboration graph

Classes

union  Addr
 

Public Types

using quad_type = uint16_t
 Size of one segment of an IPv6 address.
 
using raw_type = std::array<uint8_t, SIZE>
 

Public Member Functions

 IP6Addr ()=default
 Default constructor - ANY address.
 
 IP6Addr (self_type const &that)=default
 
 IP6Addr (in6_addr const &addr)
 Construct using IPv6 addr.
 
 IP6Addr (sockaddr_in6 const *addr)
 Construct from sockaddr_in.
 
 IP6Addr (string_view const &text)
 
 IP6Addr (IP4Addr addr)
 
self_typeoperator= (self_type const &that)=default
 Self assignment.
 
self_typeoperator<<= (unsigned n)
 
self_typeoperator>>= (unsigned n)
 
self_typeoperator&= (self_type const &that)
 
self_typeoperator|= (self_type const &that)
 
self_typeoperator++ ()
 Increment address.
 
self_typeoperator-- ()
 Decrement address.
 
self_typeoperator= (in6_addr const &addr)
 Assign from IPv6 raw address.
 
self_typeoperator= (sockaddr_in6 const *addr)
 Set to the address in addr.
 
constexpr uint8_t operator[] (int idx) const
 
sockaddr_in6 * copy_to (sockaddr_in6 *sin6) const
 
sockaddr * copy_to (sockaddr *sa) const
 
in6_addr host_order () const
 Return the address in host order.
 
in6_addr & host_order (in6_addr &dst) const
 
in6_addr network_order () const
 Return the address in network order.
 
in6_addr & network_order (in6_addr &dst) const
 
bool load (string_view const &str)
 
int cmp (self_type const &that) const
 Generic three value compare.
 
constexpr sa_family_t family () const
 
bool is_any () const
 
bool is_loopback () const
 
bool is_multicast () const
 
bool is_link_local () const
 
bool is_private () const
 
bool is_mapped_ip4 () const
 
self_typeclear ()
 
self_typeoperator&= (IPMask const &that)
 
self_typeoperator|= (IPMask const &that)
 
template<typename T>
auto as_span () -> std::enable_if_t< swoc::meta::is_any_of_v< T, std::byte, uint8_t, uint16_t, uint32_t, uint64_t >, swoc::MemSpan< T > >
 
template<typename T>
auto as_span () const -> std::enable_if_t< swoc::meta::is_any_of_v< typename std::remove_const_t< T >, std::byte, uint8_t, uint16_t, uint32_t, uint64_t >, swoc::MemSpan< T const > >
 

Static Public Member Functions

static void reorder (in6_addr &dst, raw_type const &src)
 
static void reorder (raw_type &dst, in6_addr const &src)
 

Static Public Attributes

static constexpr size_t WIDTH = 128
 Number of bits in the address.
 
static constexpr size_t SIZE = WIDTH / std::numeric_limits<uint8_t>::digits
 Size of address in bytes.
 
static constexpr sa_family_t AF_value = AF_INET6
 Address family type.
 
static constexpr size_t N_QUADS = SIZE / sizeof(quad_type)
 
static constexpr size_t QUAD_WIDTH = std::numeric_limits<uint8_t>::digits * sizeof(quad_type)
 Number of bits per quad.
 
static const self_type MIN {0, 0}
 Minimum value of an address.
 
static const self_type MAX {std::numeric_limits<uint64_t>::max(), std::numeric_limits<uint64_t>::max()}
 Maximum value of an address.
 

Protected Types

using quad_store_type = std::array<quad_type, N_QUADS>
 
using word_type = uint64_t
 Type used as a "word", the natural working unit of the address.
 
using word_store_type = std::array<word_type, N_STORE>
 Type used to store the address.
 

Protected Member Functions

 IP6Addr (word_store_type::value_type msw, word_store_type::value_type lsw)
 

Static Protected Member Functions

static void reorder (unsigned char dst[WORD_SIZE], unsigned char const src[WORD_SIZE])
 

Protected Attributes

union swoc::IP6Addr::Addr _addr
 

Static Protected Attributes

static constexpr quad_type QUAD_MASK = ~quad_type{0}
 A bit mask of all 1 bits the size of a quad.
 
static constexpr size_t WORD_SIZE = sizeof(word_type)
 
static constexpr size_t WORD_WIDTH = std::numeric_limits<uint8_t>::digits * WORD_SIZE
 Number of bits per word.
 
static constexpr word_type WORD_MASK = ~word_type(0)
 Mask the size of a word.
 
static constexpr size_t N_STORE = SIZE / WORD_SIZE
 Number of words used for basic address storage.
 
static constexpr unsigned LSW = 1
 Least significant word index.
 
static constexpr unsigned MSW = 0
 Most significant word index.
 
static constexpr std::array< unsigned, N_QUADSQUAD_IDX = {3, 2, 1, 0, 7, 6, 5, 4}
 
static constexpr std::array< unsigned, SIZERAW_IDX = {7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8}
 

Friends

class IP6Range
 
class IPMask
 
bool operator== (self_type const &lhs, self_type const &rhs)
 
bool operator!= (self_type const &lhs, self_type const &rhs)
 
bool operator< (self_type const &lhs, self_type const &rhs)
 
bool operator<= (self_type const &lhs, self_type const &rhs)
 
IP6Addr operator& (IP6Addr const &addr, IPMask const &mask)
 
IP6Addr operator| (IP6Addr const &addr, IPMask const &mask)
 

Detailed Description

Storage for an IPv6 address. Internal storage is not necessarily network ordered.

See also
network_order
copy_to

Definition at line 200 of file IPAddr.h.

Member Typedef Documentation

◆ quad_store_type

using swoc::IP6Addr::quad_store_type = std::array<quad_type, N_QUADS>
protected

Direct access type for the address by quads (16 bits). This corresponds to the elements of the text format of the address.

Definition at line 431 of file IPAddr.h.

◆ quad_type

using swoc::IP6Addr::quad_type = uint16_t

Size of one segment of an IPv6 address.

Definition at line 211 of file IPAddr.h.

◆ raw_type

using swoc::IP6Addr::raw_type = std::array<uint8_t, SIZE>

Direct access type for the address. Equivalent to the data type for data member s6_addr in in6_addr.

Definition at line 218 of file IPAddr.h.

◆ word_store_type

using swoc::IP6Addr::word_store_type = std::array<word_type, N_STORE>
protected

Type used to store the address.

Definition at line 451 of file IPAddr.h.

◆ word_type

using swoc::IP6Addr::word_type = uint64_t
protected

Type used as a "word", the natural working unit of the address.

Definition at line 437 of file IPAddr.h.

Constructor & Destructor Documentation

◆ IP6Addr() [1/5]

swoc::IP6Addr::IP6Addr ( in6_addr const & addr)
inlineexplicit

Construct using IPv6 addr.

Definition at line 932 of file IPAddr.h.

◆ IP6Addr() [2/5]

swoc::IP6Addr::IP6Addr ( sockaddr_in6 const * addr)
inlineexplicit

Construct from sockaddr_in.

Definition at line 232 of file IPAddr.h.

◆ IP6Addr() [3/5]

swoc::IP6Addr::IP6Addr ( string_view const & text)
inline

Construct from text representation. If the text is invalid the result is any address.

See also
load

Definition at line 936 of file IPAddr.h.

◆ IP6Addr() [4/5]

swoc::IP6Addr::IP6Addr ( IP4Addr addr)
inlineexplicit

Construct mapped IPv4 address.

Parameters
addrIPv4 address

Definition at line 942 of file IPAddr.h.

◆ IP6Addr() [5/5]

swoc::IP6Addr::IP6Addr ( word_store_type::value_type msw,
word_store_type::value_type lsw )
inlineprotected

Construct from two 64 bit values.

Parameters
mswThe most significant 64 bits, host order.
lswThe least significant 64 bits, host order.

Definition at line 487 of file IPAddr.h.

Member Function Documentation

◆ as_span() [1/2]

template<typename T>
auto swoc::IP6Addr::as_span ( ) -> std::enable_if_t<swoc::meta::is_any_of_v<T, std::byte, uint8_t, uint16_t, uint32_t, uint64_t>, swoc::MemSpan<T>>
inline

Definition at line 408 of file IPAddr.h.

◆ as_span() [2/2]

template<typename T>
auto swoc::IP6Addr::as_span ( ) const -> std::enable_if_t<swoc::meta::is_any_of_v<typename std::remove_const_t<T>, std::byte, uint8_t, uint16_t, uint32_t, uint64_t>, swoc::MemSpan<T const>>
inline

Definition at line 414 of file IPAddr.h.

◆ clear()

auto swoc::IP6Addr::clear ( )
inline

Reset to default constructed state.

Returns
this

Definition at line 1009 of file IPAddr.h.

◆ cmp()

int swoc::IP6Addr::cmp ( self_type const & that) const

Generic three value compare.

Definition at line 369 of file swoc_ip.cc.

◆ copy_to() [1/2]

sockaddr * swoc::IP6Addr::copy_to ( sockaddr * sa) const
inline

Update socket address with this address.

Parameters
saSocket address.
Returns
@sin

sa is assumed to be large enough to hold an IPv6 address.

Definition at line 1096 of file IPAddr.h.

◆ copy_to() [2/2]

sockaddr_in6 * swoc::IP6Addr::copy_to ( sockaddr_in6 * sin6) const

Update socket address with this address.

Parameters
sinIPv6 socket address.
Returns
@sin

Definition at line 361 of file swoc_ip.cc.

◆ family()

sa_family_t swoc::IP6Addr::family ( ) const
inlineconstexpr
Returns
The address family.

Definition at line 928 of file IPAddr.h.

◆ host_order() [1/2]

in6_addr swoc::IP6Addr::host_order ( ) const
inline

Return the address in host order.

Definition at line 981 of file IPAddr.h.

◆ host_order() [2/2]

in6_addr & swoc::IP6Addr::host_order ( in6_addr & dst) const
inline

Copy the address in host order.

Parameters
dstDestination for host order address.
Returns
dst

Definition at line 989 of file IPAddr.h.

◆ is_any()

bool swoc::IP6Addr::is_any ( ) const
inline
Returns
true if this is the "any" address, false if not.

Definition at line 961 of file IPAddr.h.

◆ is_link_local()

bool swoc::IP6Addr::is_link_local ( ) const
inline
Returns
true if this is a link local address, false if not.

Definition at line 971 of file IPAddr.h.

◆ is_loopback()

bool swoc::IP6Addr::is_loopback ( ) const
inline
Returns
true if this is a loopback address, false if not.

Definition at line 951 of file IPAddr.h.

◆ is_mapped_ip4()

bool swoc::IP6Addr::is_mapped_ip4 ( ) const
inline
Returns
true if this is an IPv4 addressed mapped to IPv6, false if not.

Definition at line 966 of file IPAddr.h.

◆ is_multicast()

bool swoc::IP6Addr::is_multicast ( ) const
inline
Returns
true if this is a multicast address, false if not.

Definition at line 956 of file IPAddr.h.

◆ is_private()

bool swoc::IP6Addr::is_private ( ) const
inline
Returns
true if the address is private.

Definition at line 976 of file IPAddr.h.

◆ load()

bool swoc::IP6Addr::load ( std::string_view const & str)

Parse a string for an IP address.

The address resuling from the parse is copied to this object if the conversion is successful, otherwise this object is invalidated.

Returns
true on success, false otherwise.

Definition at line 418 of file swoc_ip.cc.

◆ network_order() [1/2]

in6_addr swoc::IP6Addr::network_order ( ) const
inline

Return the address in network order.

Definition at line 997 of file IPAddr.h.

◆ network_order() [2/2]

in6_addr & swoc::IP6Addr::network_order ( in6_addr & dst) const
inline

Copy the address in network order.

Parameters
dstDestination for network order address.
Returns
dst

Definition at line 1003 of file IPAddr.h.

◆ operator&=() [1/2]

auto swoc::IP6Addr::operator&= ( IPMask const & that)
inline

Bitwise AND.

Parameters
thatSource mask.
Returns
this.

The bits in this are set to the bitwise AND of the corresponding bits in this and that.

Definition at line 1102 of file IPAddr.h.

◆ operator&=() [2/2]

IP6Addr & swoc::IP6Addr::operator&= ( self_type const & that)

Bitwise AND.

Parameters
thatSource address.
Returns
this.

The bits in this are set to the bitwise AND of the corresponding bits in this and that.

Definition at line 404 of file swoc_ip.cc.

◆ operator++()

auto swoc::IP6Addr::operator++ ( )
inline

Increment address.

Definition at line 1031 of file IPAddr.h.

◆ operator--()

auto swoc::IP6Addr::operator-- ( )
inline

Decrement address.

Definition at line 1039 of file IPAddr.h.

◆ operator<<=()

IP6Addr & swoc::IP6Addr::operator<<= ( unsigned n)

Left shift.

Parameters
nNumber of bits to shift left.
Returns
this.

Definition at line 373 of file swoc_ip.cc.

◆ operator=() [1/2]

auto swoc::IP6Addr::operator= ( in6_addr const & addr)
inline

Assign from IPv6 raw address.

Definition at line 1015 of file IPAddr.h.

◆ operator=() [2/2]

auto swoc::IP6Addr::operator= ( sockaddr_in6 const * addr)
inline

Set to the address in addr.

Definition at line 1021 of file IPAddr.h.

◆ operator>>=()

IP6Addr & swoc::IP6Addr::operator>>= ( unsigned n)

Right shift.

Parameters
nNumber of bits to shift right.
Returns
this.

Definition at line 389 of file swoc_ip.cc.

◆ operator[]()

uint8_t swoc::IP6Addr::operator[] ( int idx) const
constexpr

Access a byte in the address.

Parameters
idxByte index.
Returns
The "text order" byte.

Definition at line 1215 of file IPAddr.h.

◆ operator|=() [1/2]

auto swoc::IP6Addr::operator|= ( IPMask const & that)
inline

Bitwise OR.

Parameters
thatSource mask.
Returns
this.

The bits in this are set to the bitwise OR of the corresponding bits in this and that.

Definition at line 1117 of file IPAddr.h.

◆ operator|=() [2/2]

IP6Addr & swoc::IP6Addr::operator|= ( self_type const & that)

Bitwise OR.

Parameters
thatSource address.
Returns
this.

The bits in this are set to the bitwise OR of the corresponding bits in this and that.

Definition at line 411 of file swoc_ip.cc.

◆ reorder() [1/3]

void swoc::IP6Addr::reorder ( in6_addr & dst,
raw_type const & src )
static

Convert between network and host ordering.

Parameters
dstDestination for re-ordered address.
srcOriginal address.

Definition at line 502 of file swoc_ip.cc.

◆ reorder() [2/3]

void swoc::IP6Addr::reorder ( raw_type & dst,
in6_addr const & src )
static

Convert between network and host ordering.

Parameters
dstDestination for re-ordered address.
srcOriginal address.

Definition at line 508 of file swoc_ip.cc.

◆ reorder() [3/3]

void swoc::IP6Addr::reorder ( unsigned char dst[WORD_SIZE],
unsigned char const src[WORD_SIZE] )
inlinestaticprotected

Convert between network and host order. The conversion is symmetric.

Parameters
dstOutput where reordered value is placed.
srcInput value to resorder.

Definition at line 1047 of file IPAddr.h.

Friends And Related Symbol Documentation

◆ IP6Range

friend class IP6Range
friend

Definition at line 203 of file IPAddr.h.

◆ IPMask

friend class IPMask
friend

Definition at line 204 of file IPAddr.h.

◆ operator!=

bool operator!= ( self_type const & lhs,
self_type const & rhs )
friend
Returns
true if lhs is not equal to rhs.

Definition at line 1062 of file IPAddr.h.

◆ operator&

IP6Addr operator& ( IP6Addr const & addr,
IPMask const & mask )
friend

Definition at line 1205 of file IPAddr.h.

◆ operator<

bool operator< ( self_type const & lhs,
self_type const & rhs )
friend
Returns
true if lhs is less than rhs.

Definition at line 1068 of file IPAddr.h.

◆ operator<=

bool operator<= ( self_type const & lhs,
self_type const & rhs )
friend
Returns
true if lhs is less than or equal to rhs.

Definition at line 1082 of file IPAddr.h.

◆ operator==

bool operator== ( self_type const & lhs,
self_type const & rhs )
friend
Returns
true if lhs is equal to rhs.

Definition at line 1055 of file IPAddr.h.

◆ operator|

IP6Addr operator| ( IP6Addr const & addr,
IPMask const & mask )
friend

Definition at line 1210 of file IPAddr.h.

Member Data Documentation

◆ AF_value

sa_family_t swoc::IP6Addr::AF_value = AF_INET6
staticconstexpr

Address family type.

Definition at line 209 of file IPAddr.h.

◆ LSW

unsigned swoc::IP6Addr::LSW = 1
staticconstexprprotected

Least significant word index.

Definition at line 465 of file IPAddr.h.

◆ MAX

IP6Addr const swoc::IP6Addr::MAX {std::numeric_limits<uint64_t>::max(), std::numeric_limits<uint64_t>::max()}
static

Maximum value of an address.

Definition at line 223 of file IPAddr.h.

◆ MIN

IP6Addr const swoc::IP6Addr::MIN {0, 0}
static

Minimum value of an address.

Definition at line 221 of file IPAddr.h.

◆ MSW

unsigned swoc::IP6Addr::MSW = 0
staticconstexprprotected

Most significant word index.

Definition at line 466 of file IPAddr.h.

◆ N_QUADS

size_t swoc::IP6Addr::N_QUADS = SIZE / sizeof(quad_type)
staticconstexpr

of quads in an IPv6 address.

Definition at line 212 of file IPAddr.h.

◆ N_STORE

size_t swoc::IP6Addr::N_STORE = SIZE / WORD_SIZE
staticconstexprprotected

Number of words used for basic address storage.

Definition at line 448 of file IPAddr.h.

◆ QUAD_IDX

std::array<unsigned, N_QUADS> swoc::IP6Addr::QUAD_IDX = {3, 2, 1, 0, 7, 6, 5, 4}
staticconstexprprotected

Index of quads in _addr._quad. This converts from the position in the text format to the quads in the binary format.

Definition at line 470 of file IPAddr.h.

◆ QUAD_MASK

quad_type swoc::IP6Addr::QUAD_MASK = ~quad_type{0}
staticconstexprprotected

A bit mask of all 1 bits the size of a quad.

Definition at line 434 of file IPAddr.h.

◆ QUAD_WIDTH

size_t swoc::IP6Addr::QUAD_WIDTH = std::numeric_limits<uint8_t>::digits * sizeof(quad_type)
staticconstexpr

Number of bits per quad.

Definition at line 214 of file IPAddr.h.

◆ RAW_IDX

std::array<unsigned, SIZE> swoc::IP6Addr::RAW_IDX = {7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8}
staticconstexprprotected

Index of bytes in _addr._raw This converts MSB (0) to LSB (15) indices to the bytes in the binary format.

Definition at line 474 of file IPAddr.h.

◆ SIZE

size_t swoc::IP6Addr::SIZE = WIDTH / std::numeric_limits<uint8_t>::digits
staticconstexpr

Size of address in bytes.

Definition at line 208 of file IPAddr.h.

◆ WIDTH

size_t swoc::IP6Addr::WIDTH = 128
staticconstexpr

Number of bits in the address.

Definition at line 207 of file IPAddr.h.

◆ WORD_MASK

word_type swoc::IP6Addr::WORD_MASK = ~word_type(0)
staticconstexprprotected

Mask the size of a word.

Definition at line 445 of file IPAddr.h.

◆ WORD_SIZE

size_t swoc::IP6Addr::WORD_SIZE = sizeof(word_type)
staticconstexprprotected

Definition at line 439 of file IPAddr.h.

◆ WORD_WIDTH

size_t swoc::IP6Addr::WORD_WIDTH = std::numeric_limits<uint8_t>::digits * WORD_SIZE
staticconstexprprotected

Number of bits per word.

Definition at line 442 of file IPAddr.h.


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