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> 42 template<
typename Address>
45 typedef typename std::iterator<std::forward_iterator_tag, const Address>::value_type value_type;
57 : address_(address), reached_end_(false) {
68 reached_end_ = Internals::increment(address_);
91 return reached_end_ == rhs.reached_end_ && address_ == rhs.address_;
100 return !(*
this == rhs);
107 reached_end_ = Internals::increment(address_);
162 template<
typename Address>
198 AddressRange(
const address_type& first,
const address_type& last,
bool only_hosts =
false)
199 : first_(first), last_(last), only_hosts_(only_hosts){
200 if (last_ < first_) {
215 Internals::last_address_from_mask(first, mask),
226 return (first_ < addr && addr < last_) || addr == first_ || addr == last_;
234 address_type addr = first_;
236 Internals::increment(addr);
238 return const_iterator(addr);
245 const_iterator
end()
const {
246 address_type addr = last_;
248 Internals::decrement(addr);
273 address_type addr(first_);
274 for (
int i = 0; i < 3; ++i) {
276 if (Internals::increment(addr) && i != 2) {
281 return addr < last_ || addr == last_;
284 address_type first_, last_;
306 throw std::logic_error(
"Prefix length cannot exceed 48");
315 *it = 0xff << (8 - mask);
334 #endif // TINS_ADDRESS_RANGE const_iterator begin() const
Returns an interator to the beginning of this range.
Definition: address_range.h:233
AddressRange iterator class.
Definition: address_range.h:43
bool is_iterable() const
Indicates whether this range is iterable.
Definition: address_range.h:267
AddressRangeIterator & operator++()
Definition: address_range.h:106
bool operator==(const AddressRangeIterator &rhs) const
Definition: address_range.h:90
AddressRange(const address_type &first, const address_type &last, bool only_hosts=false)
Constructs an address range from two addresses.
Definition: address_range.h:198
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:212
bool operator!=(const AddressRangeIterator &rhs) const
Definition: address_range.h:99
iterator begin()
Retrieves an iterator pointing to the begining of the address.
Definition: hw_address.h:207
AddressRange< IPv4Address > IPv4Range
Definition: address_range.h:291
Address address_type
Definition: address_range.h:168
bool contains(const address_type &addr) const
Indicates whether an address is included in this range.
Definition: address_range.h:225
Represents a hardware address.
Definition: hw_address.h:91
AddressRange< HWAddress< n > > operator/(const HWAddress< n > &addr, int mask)
Constructs an AddressRange from a base address and a mask.
Definition: address_range.h:304
AddressRangeIterator(const value_type &address, end_iterator)
Definition: address_range.h:66
Definition: address_range.h:47
Base class for all libtins exceptions.
Definition: exceptions.h:41
The Tins namespace.
Definition: address_range.h:38
AddressRange< IPv6Address > IPv6Range
Definition: address_range.h:296
const value_type & operator*() const
Definition: address_range.h:74
const_iterator iterator
The iterator type.
Definition: address_range.h:181
AddressRangeIterator< address_type > const_iterator
Definition: address_range.h:173
Abstraction of an IPv4 address.
Definition: ip_address.h:45
AddressRangeIterator(const value_type &address)
Definition: address_range.h:56
Represents a range of addresses.
Definition: address_range.h:163
storage_type * iterator
The random access iterator type.
Definition: hw_address.h:101
Definition: ipv6_address.h:45
const_iterator end() const
Returns an interator to the end of this range.
Definition: address_range.h:245
AddressRangeIterator operator++(int)
Definition: address_range.h:114
const value_type * operator->() const
Definition: address_range.h:81