containing static method
The range of prefixLength bits that contains address: the address
with every bit past the prefix cleared. Unlike parse, which refuses a
host written as a range, this is how a host is turned into its network.
Implementation
static DVCidr containing(DVIpAddress address, int prefixLength) {
final int bits = address.isIPv4 ? 32 : 128;
if (prefixLength < 0 || prefixLength > bits) {
throw ArgumentError.value(
prefixLength, 'prefixLength', 'is not from 0 to $bits');
}
final List<int> bytes = address.bytes.toList();
for (int bit = prefixLength; bit < bits; bit++) {
bytes[bit >> 3] &= ~(0x80 >> (bit & 7)) & 0xff;
}
return DVCidr._(DVIpAddress.fromBytes(bytes), prefixLength);
}