ipsubnet icon indicating copy to clipboard operation
ipsubnet copied to clipboard

Incorrect output for /32

Open freb opened this issue 6 years ago • 1 comments

/32 networks (single host) get weird output from some of the calls. Admittedly some of the function calls don't necessarily make sense for /32, but the output doesn't seem to be what one would expect:

sub := ipsubnet.SubnetCalculator("8.8.8.8", "32")
sub.GetNumberIPAddresses() // 0
sub.GetNumberAddressableHosts() // 1
sub.GetIPAddressRange()[0] // 8.8.8.8
sub.GetIPAddressRange()[1] // 263.263.263.263
sub.GetBroadcastAddress() // 263.263.263.263
  • GetNumberIPAddresses: I would think this would return 1 since /32 generally means just a single IP address, though I can see how 0 might result from masking operations.
  • GetNumberAddressableHosts: I'm not sure if this should return 1 or 0, but 1 is probably preferred and is what is currently returned
  • GetIPAddressRange()[1]: This should just return the single IP address. The return value isn't valid
  • GetBroadcastAddress(): I would think this would just return the single IP address as well. The return value isn't valid.

freb avatar May 31 '18 17:05 freb

Noticed the same. For GetIPAddressRange() I think it should return two values like [8.8.8.8, 8.8.8.8] because otherwise prope ask for second entry and get an error.

But for GetBroadcastAddress() I noticed some weird behaviour:

sub := ipsubnet.SubnetCalculator("192.168.132.197", "32")
sub.GetBroadcastAddress() // 447.423.387.452      THIS IS NOT A VALID IP!

A fix would be appreciated.

the-hotmann avatar Oct 24 '22 13:10 the-hotmann