BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
IPAddressRange.h
1 #pragma once
2 
3 #include <Poco/Net/IPAddress.h>
4 
5 namespace BeeeOn {
6 
7 /*
8  * @brief The class enables iterating on Poco::Net::IPAddress class.
9  * It supports only IPv4. It accepts IP address and netmask. It can
10  * iterate from given IP address to last IP address identified by
11  * given netmask. End method return broadcast address it means
12  * this address is not processed in loop.
13  *
14  * In case of mask /31 and network address loop process just one
15  * address and it is the network address.
16  * Methods end and begin return same iterator for net mask /32.
17  * Loop does not process any address in this case.
18  */
20 public:
21  /*
22  * @param address It starts iterate from this address.
23  * @param mask Defines the range.
24  */
25  IPAddressRange(const Poco::Net::IPAddress& address, const Poco::Net::IPAddress& mask);
26  ~IPAddressRange();
27 
28 protected:
30  public:
31  IPAddressIterator(const Poco::Net::IPAddress& address);
33 
34  IPAddressIterator& operator++();
35  IPAddressIterator& operator++(int);
36  bool operator==(const IPAddressIterator& address) const;
37  bool operator!=(const IPAddressIterator& address) const;
38  Poco::Net::IPAddress& operator*();
39 
40  private:
41  Poco::Net::IPAddress m_currentAddress;
42  };
43 
44 public:
47 
48  Poco::Net::IPAddress broadcast() const;
49  Poco::Net::IPAddress network() const;
50  bool isValidMask(const Poco::Net::IPAddress& mask) const;
51 
52 private:
53  Poco::Net::IPAddress m_address;
54  Poco::Net::IPAddress m_mask;
55 };
56 
57 }
Definition: IPAddressRange.h:19
Definition: IPAddressRange.h:29