|
I was cross-checking $ netprobe subnet 192.168.1.0/31
network : 192.168.1.0
prefix : 31
total_addresses : 2
usable_hosts : 2Several calculators report 0 usable hosts for a |
Replies: 1 comment
|
Short version: the calculators reporting 0 are applying a rule that has an explicit exception, and Where "subtract 2" comes fromIn a normal IPv4 subnet, two addresses are not assignable to a host:
So Why it breaks at /31A
On a point-to-point link there is no need for a broadcast address - there is exactly one other node, so "broadcast" and "unicast to the peer" are the same packet. RFC 3021 therefore assigns both addresses to hosts. Two usable, not zero. This is not theoretical: And /32A What the code doesdef usable_hosts(net):
if net.version == 6:
return net.num_addresses
if net.prefixlen >= 31:
return net.num_addresses
return net.num_addresses - 2IPv6 is a separate branch because it has no broadcast address at all - it uses multicast instead - so nothing is ever reserved and a Summary
These five rows are pinned in One caveat worth stating: a |
Short version: the calculators reporting 0 are applying a rule that has an explicit exception, and
netprobeimplements the exception.Where "subtract 2" comes from
In a normal IPv4 subnet, two addresses are not assignable to a host:
0)1)So
usable = 2^host_bits - 2. For a/24that is256 - 2 = 254, which is right.Why it breaks at /31
A
/31has exactly two addresses. Apply the rule blindly and you get2 - 2 = 0- a subnet that cannot hold anything, which would make the prefix useless. That was in fact the situation until RFC 3021 (December 2000), which defines/31for point-to-point links: