Fix usable hosts for /32 subnet
This commit is contained in:
parent
a763bf1d8c
commit
45c25fa5f3
1 changed files with 1 additions and 1 deletions
|
@ -40,7 +40,7 @@ class Subnet
|
|||
throw new Exception("CIDR must be between 0 and 32.");
|
||||
}
|
||||
|
||||
$hosts = (1 << (32 - $cidr)) - 2; // Excludes network and broadcast
|
||||
$hosts = ($cidr === 32) ? 1 : (1 << (32 - $cidr)) - 2; // Special case for /32
|
||||
$ipLong = ip2long($ip);
|
||||
$mask = -1 << (32 - $cidr);
|
||||
$network = $ipLong & $mask;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue