Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subnet question #58

Open
molinto opened this issue Oct 11, 2017 · 1 comment
Open

Subnet question #58

molinto opened this issue Oct 11, 2017 · 1 comment

Comments

@molinto
Copy link

molinto commented Oct 11, 2017

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)

@beaugunderson
Copy link
Owner

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants