1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-28 04:34:27 +01:00

Added AddressRange class template.

This commit is contained in:
Matias Fontanini
2013-07-06 17:48:26 -03:00
parent f385e4e975
commit 3b349471ea
12 changed files with 598 additions and 6 deletions

View File

@@ -31,6 +31,7 @@
#include <sstream>
#include "ip_address.h"
#include "endianness.h"
#include "address_range.h"
using std::string;
@@ -94,4 +95,13 @@ std::ostream &operator<<(std::ostream &output, const IPv4Address &addr) {
}
return output;;
}
AddressRange<IPv4Address> operator/(const IPv4Address &addr, int mask) {
if(mask > 32)
throw std::logic_error("Prefix length cannot exceed 32");
return AddressRange<IPv4Address>::from_mask(
addr,
IPv4Address(Endian::host_to_be(0xffffffff << (32 - mask)))
);
}
}