diff --git a/pkg/core/core.go b/pkg/core/core.go index a302265..698cb11 100644 --- a/pkg/core/core.go +++ b/pkg/core/core.go @@ -35,8 +35,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. 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",