From 83770cfcdb1ffc8020622bd5cce1b99496eb9804 Mon Sep 17 00:00:00 2001 From: NoOne-dev <21012437+NoOne-dev@users.noreply.github.com> Date: Mon, 20 Oct 2025 10:40:20 -0400 Subject: [PATCH] Fix supernet-calculations.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Invert the loop to correctly find the smallest CIDR. Before this change, the loop in findSupernet starts at cidr = 1 and stops at the first CIDR that encompasses all addresses. Since /1 is large enough to cover any IPv4 range, it satisfies the condition (supernetStart ≤ minAddress and supernetEnd ≥ maxAddress) and is incorrectly selected. --- src/lib/utils/supernet-calculations.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/utils/supernet-calculations.ts b/src/lib/utils/supernet-calculations.ts index d51f3fb..e42ab3b 100644 --- a/src/lib/utils/supernet-calculations.ts +++ b/src/lib/utils/supernet-calculations.ts @@ -152,7 +152,7 @@ function findSupernet(networks: NetworkInput[]): { network: string; cidr: number // Find the smallest CIDR that can contain all networks let supernetCidr = 32; - for (let cidr = 1; cidr <= 30; cidr++) { + for (let cidr = 30; cidr >= 1; cidr--) { const mask = 0xffffffff << (32 - cidr); const supernetStart = minAddress & (mask >>> 0); const supernetEnd = supernetStart + Math.pow(2, 32 - cidr) - 1;