1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-29 04:54:28 +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

@@ -41,6 +41,7 @@
#include <limits>
#include <sstream>
#include "ipv6_address.h"
#include "address_range.h"
namespace Tins {
IPv6Address::IPv6Address() {
@@ -96,6 +97,19 @@ namespace Tins {
#endif
return buffer;
}
AddressRange<IPv6Address> operator/(const IPv6Address &addr, int mask) {
if(mask > 128)
throw std::logic_error("Prefix length cannot exceed 128");
IPv6Address last_addr;
IPv6Address::iterator it = last_addr.begin();
while(mask > 8) {
*it = 0xff;
++it;
mask -= 8;
}
*it = 0xff << (8 - mask);
return AddressRange<IPv6Address>::from_mask(addr, last_addr);
}
}