mirror of
https://github.com/lissy93/networking-toolbox.git
synced 2026-12-02 09:42:20 +03:00
Fix supernet-calculations.ts
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.
This commit is contained in:
1 parent
380ee214db
commit
83770cfcdb
1 file changed
+1
-1
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user