From 45c25fa5f3a34e5a24f9e8cddcab658e5f0b72a4 Mon Sep 17 00:00:00 2001 From: Maarten Date: Wed, 27 Nov 2024 20:12:45 +0100 Subject: [PATCH] Fix usable hosts for /32 subnet --- app/Services/Subnet.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Services/Subnet.php b/app/Services/Subnet.php index 36322f3..ff54bbe 100644 --- a/app/Services/Subnet.php +++ b/app/Services/Subnet.php @@ -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;