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

#include <IPRange.h>

Collaboration diagram for swoc::IPRange:
Collaboration graph

Classes

class  NetSource
 

Public Member Functions

 IPRange ()=default
 Default constructor - construct invalid range.
 
 IPRange (IPAddr const &min, IPAddr const &max)
 
 IPRange (IP4Addr const &min, IP4Addr const &max)
 
 IPRange (IP6Addr const &min, IP6Addr const &max)
 
 IPRange (IPAddr const &addr)
 
 IPRange (IP4Addr addr)
 
 IPRange (IP6Addr const &addr)
 
 IPRange (IP4Range const &range)
 Construct from an IPv4 range.
 
 IPRange (IP6Range const &range)
 Construct from an IPv6 range.
 
 IPRange (IPRangeView const &view)
 Construct from view.
 
 IPRange (string_view const &text)
 
self_typeassign (IP4Addr const &min, IP4Addr const &max)
 
self_typeassign (IP6Addr const &min, IP6Addr const &max)
 
self_typeoperator= (IPRangeView const &rv)
 Assign from view.
 
bool operator== (self_type const &that) const
 Equality.
 
bool operator!= (self_type const &that) const
 Inequality.
 
bool is_ip4 () const
 
bool is_ip6 () const
 
bool is (sa_family_t family) const
 
bool load (std::string_view const &text)
 
bool contains (IPAddr const &addr) const
 
bool contains (IP6Addr const &addr) const
 
bool contains (IP4Addr const &addr) const
 
IPAddr min () const
 
IPAddr max () const
 
bool empty () const
 
self_typeclear ()
 Make the range empty / invalid.
 
IP4Range const & ip4 () const
 
IP6Range const & ip6 () const
 
sa_family_t family () const
 
IPMask network_mask () const
 
NetSource networks () const
 

Protected Attributes

union { 
 
   std::monostate   _nil 
 Make constructor easier to implement. More...
 
   IP4Range   _ip4 
 IPv4 range. More...
 
   IP6Range   _ip6 
 IPv6 range. More...
 
monostate 
 
sa_family_t _family {AF_UNSPEC}
 Family of _range.
 

Detailed Description

Range of IP addresses. Although this can hold IPv4 or IPv6, any specific instance is one or the other, this can never contain a range of different address families.

Definition at line 325 of file IPRange.h.

Constructor & Destructor Documentation

◆ IPRange() [1/10]

swoc::IPRange::IPRange ( IPAddr const & min,
IPAddr const & max )

Construct an inclusive range.

Parameters
minMinimum range value.
maxMaximum range value.

Definition at line 1102 of file swoc_ip.cc.

◆ IPRange() [2/10]

swoc::IPRange::IPRange ( IP4Addr const & min,
IP4Addr const & max )
inline

Construct an inclusive range.

Parameters
minMinimum range value.
maxMaximum range value.

Definition at line 1918 of file IPRange.h.

◆ IPRange() [3/10]

swoc::IPRange::IPRange ( IP6Addr const & min,
IP6Addr const & max )
inline

Construct an inclusive range.

Parameters
minMinimum range value.
maxMaximum range value.

Definition at line 1922 of file IPRange.h.

◆ IPRange() [4/10]

swoc::IPRange::IPRange ( IPAddr const & addr)
inline

Construct a singleton range.

Parameters
addrAddress of range.

Definition at line 357 of file IPRange.h.

◆ IPRange() [5/10]

swoc::IPRange::IPRange ( IP4Addr addr)
inline

Construct a singleton range.

Parameters
addrAddress of range.

Definition at line 363 of file IPRange.h.

◆ IPRange() [6/10]

swoc::IPRange::IPRange ( IP6Addr const & addr)
inline

Construct a singleton range.

Parameters
addrAddress of range.

Definition at line 369 of file IPRange.h.

◆ IPRange() [7/10]

swoc::IPRange::IPRange ( IP4Range const & range)
inline

Construct from an IPv4 range.

Definition at line 1910 of file IPRange.h.

◆ IPRange() [8/10]

swoc::IPRange::IPRange ( IP6Range const & range)
inline

Construct from an IPv6 range.

Definition at line 1914 of file IPRange.h.

◆ IPRange() [9/10]

swoc::IPRange::IPRange ( IPRangeView const & view)
inline

Construct from view.

Definition at line 1930 of file IPRange.h.

◆ IPRange() [10/10]

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

Construct from a string format.

Parameters
textText form of range.

The string can be a single address, two addresses separated by a dash '-' or a CIDR network.

Definition at line 1926 of file IPRange.h.

Member Function Documentation

◆ assign() [1/2]

auto swoc::IPRange::assign ( IP4Addr const & min,
IP4Addr const & max )
inline

Update with an IPv4 range.

Parameters
minMinimum value.
maxMaximum value.
Returns
this.

Definition at line 1939 of file IPRange.h.

◆ assign() [2/2]

auto swoc::IPRange::assign ( IP6Addr const & min,
IP6Addr const & max )
inline

Update with an IPv6 range.

Parameters
minMinimum address.
maxMaximum address.
Returns
this

Definition at line 1946 of file IPRange.h.

◆ clear()

auto swoc::IPRange::clear ( )
inline

Make the range empty / invalid.

Definition at line 1963 of file IPRange.h.

◆ contains() [1/3]

bool swoc::IPRange::contains ( IP4Addr const & addr) const
inline

Test if an address is in the range.

Parameters
addrAddress to test.
Returns
true if in this range, false if not.

Definition at line 2052 of file IPRange.h.

◆ contains() [2/3]

bool swoc::IPRange::contains ( IP6Addr const & addr) const
inline

Test if an address is in the range.

Parameters
addrAddress to test.
Returns
true if in this range, false if not.

Definition at line 2048 of file IPRange.h.

◆ contains() [3/3]

bool swoc::IPRange::contains ( IPAddr const & addr) const
inline

Test if an address is in the range.

Parameters
addrAddress to test.
Returns
true if in this range, false if not.

Definition at line 2036 of file IPRange.h.

◆ empty()

bool swoc::IPRange::empty ( ) const
Returns
true if there are no addresses in the range.

Definition at line 1152 of file swoc_ip.cc.

◆ family()

sa_family_t swoc::IPRange::family ( ) const
inline
Returns
The range family.

Definition at line 1993 of file IPRange.h.

◆ ip4()

IP4Range const & swoc::IPRange::ip4 ( ) const
inline
Returns
The IPv4 range.

Definition at line 1996 of file IPRange.h.

◆ ip6()

IP6Range const & swoc::IPRange::ip6 ( ) const
inline
Returns
The IPv6 range.

Definition at line 2000 of file IPRange.h.

◆ is()

bool swoc::IPRange::is ( sa_family_t family) const
inline

Check if this range is the IP address family.

Parameters
familyIP address family.
Returns
true if this is family, false if not.

Definition at line 1974 of file IPRange.h.

◆ is_ip4()

bool swoc::IPRange::is_ip4 ( ) const
inline
Returns
true if this is an IPv4 range, false if not.

Definition at line 1984 of file IPRange.h.

◆ is_ip6()

bool swoc::IPRange::is_ip6 ( ) const
inline
Returns
true if this is an IPv6 range, false if not.

Definition at line 1989 of file IPRange.h.

◆ load()

bool swoc::IPRange::load ( std::string_view const & text)

Load the range from text.

Parameters
textRange specifier in text format.
Returns
true if text was successfully parsed, false if not.

A successful parse means this was loaded with the specified range. If not the range is marked as invalid.

Definition at line 1111 of file swoc_ip.cc.

◆ max()

IPAddr swoc::IPRange::max ( ) const
Returns
The maximum address in the range.

Definition at line 1139 of file swoc_ip.cc.

◆ min()

IPAddr swoc::IPRange::min ( ) const
Returns
The minimum address in the range.

Definition at line 1126 of file swoc_ip.cc.

◆ network_mask()

IPMask swoc::IPRange::network_mask ( ) const

Compute the mask for this as a network.

Returns
If this is a network, the mask for that network. Otherwise an invalid mask.
See also
IPMask::is_valid

Definition at line 1165 of file swoc_ip.cc.

◆ networks()

auto swoc::IPRange::networks ( ) const
inline

Generate a list of networks covering this range.

Returns
A network generator.

The returned object can be used as an iterator, or as a container to iterating over the unique minimal set of networks that cover this range.

void (IPRange const& range) {
for ( auto const& net : range ) {
net.addr(); // network address.
net.mask(); // network mask;
}
}
IPRange()=default
Default constructor - construct invalid range.

Definition at line 1969 of file IPRange.h.

◆ operator!=()

bool swoc::IPRange::operator!= ( self_type const & that) const
inline

Inequality.

Definition at line 1979 of file IPRange.h.

◆ operator=()

auto swoc::IPRange::operator= ( IPRangeView const & rv)
inline

Assign from view.

Definition at line 1953 of file IPRange.h.

◆ operator==()

bool swoc::IPRange::operator== ( self_type const & that) const

Equality.

Definition at line 1178 of file swoc_ip.cc.

Member Data Documentation

◆ _family

sa_family_t swoc::IPRange::_family {AF_UNSPEC}
protected

Family of _range.

Definition at line 523 of file IPRange.h.

◆ _ip4

IP4Range swoc::IPRange::_ip4

IPv4 range.

Definition at line 518 of file IPRange.h.

◆ _ip6

IP6Range swoc::IPRange::_ip6

IPv6 range.

Definition at line 519 of file IPRange.h.

◆ _nil

std::monostate swoc::IPRange::_nil

Make constructor easier to implement.

Definition at line 517 of file IPRange.h.

◆ [union]

union { ... } swoc::IPRange::monostate

Range container.


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