9 #ifndef __libutilxx__sella__net__IPPrefix_H__
10 #define __libutilxx__sella__net__IPPrefix_H__
12 #include "../../common.h"
13 #include "IPAddress.h"
14 #include "AddressException.h"
16 #include <netinet/in.h>
22 #include <forward_list>
23 #include <unordered_set>
33 typedef std::shared_ptr<IPPrefix> shared;
37 size_t operator()(
const IPPrefix &a)
const {
43 size_t operator()(
const ptr a)
const {
49 size_t operator()(
const shared &a)
const {
61 bool operator()(
const ptr a,
const ptr b)
const {
62 if (a == NULL || b == NULL) {
70 bool operator()(
const shared &a,
const shared &b)
const {
71 #ifdef KEYEQUAL_METHOD
72 const std::unordered_set<std::string> s;
73 const std::unordered_set<std::string>::key_equal &eqfn = s.key_eq();
75 return eqfn(a->str(), b->str());
88 typedef std::list<IPPrefix> list;
89 typedef std::list<ptr> ptr_list;
90 typedef std::list<shared> shared_list;
91 typedef std::forward_list<IPPrefix> flist;
92 typedef std::forward_list<ptr> ptr_flist;
93 typedef std::forward_list<shared> shared_flist;
94 typedef std::vector<IPPrefix> vector;
95 typedef std::vector<ptr> ptr_vector;
96 typedef std::vector<shared> shared_vector;
97 typedef std::unordered_set<IPPrefix, hash> uset;
98 typedef std::unordered_set<ptr, ptr_hash, ptr_eq> ptr_uset;
99 typedef std::unordered_set<shared, shared_hash, shared_eq> shared_uset;
100 typedef std::unordered_multiset<IPPrefix, hash> umset;
101 typedef std::unordered_multiset<ptr, ptr_hash, ptr_eq> ptr_umset;
102 typedef std::unordered_multiset<shared, shared_hash, shared_eq> shared_umset;
106 IPPrefix(const std::
string &address, uint8_t cidr) throw (AddressException);
107 IPPrefix(const std::
string &prefix = std::
string("0.0.0.0/32")) throw (AddressException);
116 bool operator==(const
IPPrefix &other) const throw ();
117 bool operator!=(const
IPPrefix &other) const throw ();
118 bool operator>=(const
IPPrefix &other) const throw ();
119 bool operator<=(const
IPPrefix &other) const throw ();
120 bool operator<(const
IPPrefix &other) const throw ();
121 bool operator>(const
IPPrefix &other) const throw ();
124 bool operator<<(const
IPPrefix &other) const throw ();
125 bool operator<<=(const
IPPrefix &other) const throw ();
126 bool operator>>(const
IPPrefix &other) const throw ();
127 bool operator>>=(const
IPPrefix &other) const throw ();
129 bool operator<<(const
IPAddress &other) const throw ();
130 bool operator<<=(const
IPAddress &other) const throw ();
131 bool operator>>(const
IPAddress &other) const throw ();
132 bool operator>>=(const
IPAddress &other) const throw ();
134 bool contains(const
IPPrefix &other,
bool orEquals = false) const throw ();
135 bool contains(const
IPAddress &other,
bool orEquals = false) const throw ();
138 int getFamily(
void) const throw ();
139 const
IPAddress& getIPAddress(
void) const throw ();
141 uint8_t getCIDR(
void) const throw ();
142 IPAddress getNetmask(
void) const throw ();
143 IPAddress getInverseMask(
void) const throw ();
144 IPAddress getNetwork(
void) const throw ();
145 IPAddress getBroadcast(
void) const throw ();
146 IPAddress::vector getIPAddresses(
bool usable = true) const throw ();
147 const std::
string& str(
void) const throw (AddressException);
148 const
char* c_str(
void) const throw (AddressException);
149 uint32_t getU32(
void) const throw ();
150 uint32_t getHash(
void) const throw ();
152 bool empty(
void) const throw ();
153 void clear(
void) throw ();
155 static const
IPPrefix::shared shared_ptr(const
IPAddress &address, uint8_t cidr = 255) throw (AddressException);
156 static const
IPPrefix::shared shared_ptr(const std::
string &address, uint8_t cidr) throw (AddressException);
157 static const
IPPrefix::shared shared_ptr(const std::
string &prefix = std::
string("0.0.0.0/32")) throw (AddressException);
160 static
bool bi_cmp(const
IPPrefix &a, const
IPPrefix &b) {
return (a < b); }
161 static bool shared_bi_cmp(shared &a, shared &b) {
return (*a < *b); }
162 static bool shared_bi_eq(shared &a, shared &b) {
return (*a == *b); }
169 mutable std::string scache;
170 mutable uint32_t hcache;
172 void generateMask(
void) throw ();