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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user