From 3ecd486f97f2f20e27fc95621dece172011d7ae8 Mon Sep 17 00:00:00 2001 From: Bruno Schaatsbergen Date: Sat, 16 Mar 2024 22:35:41 +0100 Subject: [PATCH 1/2] chore: don't remove the network address and broadcast address --- pkg/core/core.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/core/core.go b/pkg/core/core.go index 5c6d8e4..fe79b27 100644 --- a/pkg/core/core.go +++ b/pkg/core/core.go @@ -32,8 +32,7 @@ func GetAddressCount(network *net.IPNet) uint64 { } } - // Subtract the network address and broadcast address (2) from the total number of addresses. - return 1<<(uint64(bits)-uint64(prefixLen)) - 2 + return 1 << (uint64(bits) - uint64(prefixLen)) } // ContainsAddress checks if the given IP network contains the specified IP address. From cb39a588fbeef7cfabd796333c347800da46fe9a Mon Sep 17 00:00:00 2001 From: Bruno Schaatsbergen Date: Sat, 16 Mar 2024 22:48:24 +0100 Subject: [PATCH 2/2] chore: fix tests --- pkg/core/core_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/core/core_test.go b/pkg/core/core_test.go index 7b64f1a..8cb05a6 100644 --- a/pkg/core/core_test.go +++ b/pkg/core/core_test.go @@ -44,12 +44,12 @@ func TestGetAddressCount(t *testing.T) { { name: "Return the count of all distinct host addresses in a common IPv4 CIDR", cidr: IPv4CIDR, - expectedCount: 65534, + expectedCount: 65536, }, { name: "Return the count of all distinct host addresses in a common IPv6 CIDR", cidr: IPv6CIDR, - expectedCount: 4194302, + expectedCount: 4194304, }, { name: "Return the count of all distinct host addresses in an uncommon (large prefix) IPv4 CIDR",