ip-address icon indicating copy to clipboard operation
ip-address copied to clipboard

Subnet question

Open molinto opened this issue 8 years ago • 1 comments

Hi, thanks for the NPM package. Maybe I'm just being stupid but when finding the subnet of an IP address seems incorrect, eg:

let netMask = new Address4('255.255.255.0');

returns /32

But normally, 255.255.255.0 returns /24 (as 8 + 8 + 8)

molinto avatar Oct 11 '17 10:10 molinto

the default subnet of any single address when a subnet is not specified is /32--you could count the bits in the netmask to translate to a subnet though, e.g.:

let netMask = new Address4('255.255.255.0');
console.log(/^1+/.exec(netMask.binaryZeroPad())[0].length); // 24

this should probably be a static helper function on Address4, like Address4.netmaskToSubnet('255.255.255.0'), would that work for you?

beaugunderson avatar Dec 01 '17 07:12 beaugunderson