30#ifndef TINS_ADDRESS_RANGE
31#define TINS_ADDRESS_RANGE
34#include <tins/endianness.h>
35#include <tins/exceptions.h>
36#include <tins/detail/address_helpers.h>
42template<
typename Address>
45 typedef std::forward_iterator_tag iterator_category;
46 typedef const Address value_type;
47 typedef std::ptrdiff_t difference_type;
48 typedef const Address* pointer;
49 typedef const Address& reference;
61 : address_(address), reached_end_(false) {
72 reached_end_ = Internals::increment(address_);
95 return reached_end_ == rhs.reached_end_ && address_ == rhs.address_;
104 return !(*
this == rhs);
111 reached_end_ = Internals::increment(address_);
166template<
typename Address>
203 : first_(first), last_(last), only_hosts_(only_hosts){
204 if (last_ < first_) {
219 Internals::last_address_from_mask(first, mask),
230 return (first_ < addr && addr < last_) || addr == first_ || addr == last_;
240 Internals::increment(addr);
252 Internals::decrement(addr);
278 for (
int i = 0; i < 3; ++i) {
280 if (Internals::increment(addr) && i != 2) {
285 return addr < last_ || addr == last_;
310 throw std::logic_error(
"Prefix length cannot exceed 48");
319 *it = 0xff << (8 - mask);
AddressRange iterator class.
Definition address_range.h:43
AddressRangeIterator operator++(int)
Definition address_range.h:118
const value_type & operator*() const
Definition address_range.h:78
bool operator!=(const AddressRangeIterator &rhs) const
Definition address_range.h:103
const value_type * operator->() const
Definition address_range.h:85
AddressRangeIterator & operator++()
Definition address_range.h:110
AddressRangeIterator(const value_type &address, end_iterator)
Definition address_range.h:70
bool operator==(const AddressRangeIterator &rhs) const
Definition address_range.h:94
AddressRangeIterator(const value_type &address)
Definition address_range.h:60
Represents a range of addresses.
Definition address_range.h:167
const_iterator end() const
Returns an interator to the end of this range.
Definition address_range.h:249
const_iterator begin() const
Returns an interator to the beginning of this range.
Definition address_range.h:237
const_iterator iterator
The iterator type.
Definition address_range.h:185
bool contains(const address_type &addr) const
Indicates whether an address is included in this range.
Definition address_range.h:229
static AddressRange from_mask(const address_type &first, const address_type &mask)
Creates an address range from a base address and a network mask.
Definition address_range.h:216
AddressRangeIterator< address_type > const_iterator
Definition address_range.h:177
bool is_iterable() const
Indicates whether this range is iterable.
Definition address_range.h:271
Address address_type
Definition address_range.h:172
AddressRange(const address_type &first, const address_type &last, bool only_hosts=false)
Constructs an address range from two addresses.
Definition address_range.h:202
Represents a hardware address.
Definition resolve_utils.h:43
storage_type * iterator
The random access iterator type.
Definition hw_address.h:101
iterator begin()
Retrieves an iterator pointing to the begining of the address.
Definition hw_address.h:207
Base class for all libtins exceptions.
Definition exceptions.h:41
The Tins namespace.
Definition address_range.h:38
AddressRange< IPv4Address > IPv4Range
Definition address_range.h:295
AddressRange< IPv6Address > IPv6Range
Definition address_range.h:300
AddressRange< HWAddress< n > > operator/(const HWAddress< n > &addr, int mask)
Constructs an AddressRange from a base address and a mask.
Definition address_range.h:308
Definition address_range.h:51