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

#include <IPAddr.h>

Collaboration diagram for swoc::IPMask:
Collaboration graph

Public Types

using raw_type = uint8_t
 Storage for mask width.
 

Public Member Functions

 IPMask ()=default
 Default construct to invalid mask.
 
 IPMask (raw_type width)
 
bool is_valid () const
 
bool load (string_view const &text)
 
self_typeclear ()
 Change to default constructed state (invalid).
 
raw_type width () const
 The width of the mask.
 
self_typeoperator<<= (raw_type n)
 
self_typeoperator>>= (raw_type n)
 
IP4Addr as_ip4 () const
 
IP6Addr as_ip6 () const
 

Static Public Member Functions

static self_type mask_for (IPAddr const &addr)
 
static self_type mask_for (IP4Addr const &addr)
 
static self_type mask_for (IP6Addr const &addr)
 

Static Protected Member Functions

static raw_type mask_for_quad (IP6Addr::quad_type q)
 Compute a partial IPv6 mask, sized for the basic storage type.
 

Protected Attributes

raw_type _cidr = INVALID
 Mask width in bits.
 

Static Protected Attributes

static constexpr auto INVALID = std::numeric_limits<raw_type>::max()
 Marker value for an invalid mask.
 

Friends

class IP4Addr
 
class IP6Addr
 

Detailed Description

An IP address mask.

This is essentially a width for a bit mask.

Definition at line 666 of file IPAddr.h.

Member Typedef Documentation

◆ raw_type

using swoc::IPMask::raw_type = uint8_t

Storage for mask width.

Definition at line 673 of file IPAddr.h.

Constructor & Destructor Documentation

◆ IPMask()

swoc::IPMask::IPMask ( raw_type width)
inlineexplicit

Construct a mask of width.

Parameters
widthNumber of bits in the mask.
Note
Because this is a network mask, it is always left justified.

Definition at line 1135 of file IPAddr.h.

Member Function Documentation

◆ as_ip4()

IP4Addr swoc::IPMask::as_ip4 ( ) const
inline

The mask as an IPv4 address.

Returns
An IPv4 address that is the mask.

If the mask is wider than an IPv4 address, the maximum mask is returned.

Definition at line 1163 of file IPAddr.h.

◆ as_ip6()

IP6Addr swoc::IPMask::as_ip6 ( ) const

The mask as an IPv6 address.

Returns
An IPv6 address that is the mask.

If the mask is wider than an IPv6 address, the maximum mask is returned.

Definition at line 724 of file swoc_ip.cc.

◆ clear()

auto swoc::IPMask::clear ( )
inline

Change to default constructed state (invalid).

Definition at line 1175 of file IPAddr.h.

◆ is_valid()

bool swoc::IPMask::is_valid ( ) const
inline
Returns
true if the mask is valid, false if not.

Definition at line 1138 of file IPAddr.h.

◆ load()

bool swoc::IPMask::load ( string_view const & text)

Parse mask from text.

Parameters
textA number in string format.
Returns
true if a valid CIDR value, false if not.

Definition at line 663 of file swoc_ip.cc.

◆ mask_for() [1/3]

IPMask swoc::IPMask::mask_for ( IP4Addr const & addr)
static

Copmute a mask for the network at addr.

Parameters
addrLower bound of network.
Returns
A mask with the width of the largest network starting at addr.

Definition at line 698 of file swoc_ip.cc.

◆ mask_for() [2/3]

IPMask swoc::IPMask::mask_for ( IP6Addr const & addr)
static

Copmute a mask for the network at addr.

Parameters
addrLower bound of network.
Returns
A mask with the width of the largest network starting at addr.

Definition at line 710 of file swoc_ip.cc.

◆ mask_for() [3/3]

IPMask swoc::IPMask::mask_for ( IPAddr const & addr)
static

Copmute a mask for the network at addr.

Parameters
addrLower bound of network.
Returns
A mask with the width of the largest network starting at addr.

Definition at line 674 of file swoc_ip.cc.

◆ mask_for_quad()

auto swoc::IPMask::mask_for_quad ( IP6Addr::quad_type q)
staticprotected

Compute a partial IPv6 mask, sized for the basic storage type.

Definition at line 684 of file swoc_ip.cc.

◆ operator<<=()

auto swoc::IPMask::operator<<= ( raw_type n)
inline

Extend the mask (cover more addresses).

Parameters
nNumber of bits to extend.
Returns
this

Effectively shifts the mask left, bringing in 0 bits on the right.

Definition at line 1180 of file IPAddr.h.

◆ operator>>=()

auto swoc::IPMask::operator>>= ( IPMask::raw_type n)
inline

Narrow the mask (cover fewer addresses).

Parameters
nNumber of bits to narrow.
Returns
this

Effectively shift the mask right, bringing in 1 bits on the left.

Definition at line 1187 of file IPAddr.h.

◆ width()

auto swoc::IPMask::width ( ) const
inline

The width of the mask.

Definition at line 1143 of file IPAddr.h.

Friends And Related Symbol Documentation

◆ IP4Addr

friend class IP4Addr
friend

Definition at line 669 of file IPAddr.h.

◆ IP6Addr

friend class IP6Addr
friend

Definition at line 670 of file IPAddr.h.

Member Data Documentation

◆ _cidr

raw_type swoc::IPMask::_cidr = INVALID
protected

Mask width in bits.

Definition at line 757 of file IPAddr.h.

◆ INVALID

auto swoc::IPMask::INVALID = std::numeric_limits<raw_type>::max()
staticconstexprprotected

Marker value for an invalid mask.

Definition at line 755 of file IPAddr.h.


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