1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-25 19:51:34 +01:00

Add IPv4Address::from_prefix_length

This commit is contained in:
Matias Fontanini
2016-03-19 16:26:00 -07:00
parent 3773443fc8
commit a70ce10bed
3 changed files with 14 additions and 6 deletions

View File

@@ -39,15 +39,12 @@ IPv4Range operator/(const IPv4Address& addr, int mask) {
if (mask > 32) {
throw logic_error("Prefix length cannot exceed 32");
}
return IPv4Range::from_mask(
addr,
IPv4Address(Endian::host_to_be(0xffffffff << (32 - mask)))
);
return IPv4Range::from_mask(addr, IPv4Address::from_prefix_length(mask));
}
IPv6Range operator/(const IPv6Address& addr, int mask) {
if (mask > 128) {
throw std::logic_error("Prefix length cannot exceed 128");
throw logic_error("Prefix length cannot exceed 128");
}
return IPv6Range::from_mask(addr, IPv6Address::from_prefix_length(mask));
}