libtins
4.0
|
Represents a range of addresses. More...
#include <address_range.h>
Public Types | |
typedef Address | address_type |
typedef AddressRangeIterator< address_type > | const_iterator |
typedef const_iterator | iterator |
The iterator type. More... | |
Public Member Functions | |
AddressRange (const address_type &first, const address_type &last, bool only_hosts=false) | |
Constructs an address range from two addresses. More... | |
bool | contains (const address_type &addr) const |
Indicates whether an address is included in this range. More... | |
const_iterator | begin () const |
Returns an interator to the beginning of this range. More... | |
const_iterator | end () const |
Returns an interator to the end of this range. More... | |
bool | is_iterable () const |
Indicates whether this range is iterable. More... | |
Static Public Member Functions | |
static AddressRange | from_mask (const address_type &first, const address_type &mask) |
Creates an address range from a base address and a network mask. More... | |
Represents a range of addresses.
This class provides a begin()/end() interface which allows iterating through every address stored in it.
Note that when iterating a range that was created using operator/(IPv4Address, int) and the analog for IPv6, the network and broadcast addresses are discarded:
Ranges created using AddressRange(address_type, address_type) will allow the iteration over the entire range:
typedef Address Tins::AddressRange< Address >::address_type |
The type of addresses stored in the range.
typedef AddressRangeIterator<address_type> Tins::AddressRange< Address >::const_iterator |
The iterator type.
typedef const_iterator Tins::AddressRange< Address >::iterator |
The iterator type.
This is the same type as const_iterator, since the addresses stored in this range are read only.
|
inline |
Constructs an address range from two addresses.
The range will consist of the addresses [first, last].
If only_hosts is true, then the network and broadcast addresses will not be available when iterating the range.
If last < first, an std::runtime_error exception is thrown.
first | The first address in the range. |
last | The last address(inclusive) in the range. |
only_hosts | Indicates whether only host addresses should be accessed when using iterators. |
|
inline |
Returns an interator to the beginning of this range.
const_iterator pointing to the beginning of this range.
|
inline |
Indicates whether an address is included in this range.
addr | The address to test. |
|
inline |
Returns an interator to the end of this range.
const_iterator pointing to the end of this range.
|
inlinestatic |
Creates an address range from a base address and a network mask.
first | The base address. |
mask | The network mask to be used. |
|
inline |
Indicates whether this range is iterable.
Iterable ranges are those for which there is at least one address that could represent a host. For IPv4 ranges, a /31 or /32 ranges does not contain any, therefore it's not iterable. The same is true for /127 and /128 IPv6 ranges.
If is_iterable returns false for a range, then iterating it through the iterators returned by begin() and end() is undefined.