Skip to content

Commit

Permalink
Merge pull request #96 from bschaatsbergen/fix-count
Browse files Browse the repository at this point in the history
chore: don't remove the network address and broadcast address
  • Loading branch information
bschaatsbergen committed Mar 16, 2024
2 parents 7ab85f5 + cb39a58 commit 39881b1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions pkg/core/core.go
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions pkg/core/core_test.go
Expand Up @@ -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",
Expand Down

0 comments on commit 39881b1

Please sign in to comment.