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

Using prefix returns wrong ip range. #4

Open
mustafaKagan opened this issue Feb 19, 2020 · 1 comment
Open

Using prefix returns wrong ip range. #4

mustafaKagan opened this issue Feb 19, 2020 · 1 comment
Assignees

Comments

@mustafaKagan
Copy link

Describe the bug
Using prefix returns wrong ip range. Normarlly I give to prefix function network like 8.8.8.8/24 ,I expect to see 8.8.8.0-8.8.8.255 ip pool but function returns 8.8.8.8-8.8.9.7

To Reproduce
Steps to reproduce the behavior:

  1. let prefix=new Ip.Prefix("8.8.8.8",24)
  2. prefix.lastIp().toString() ;//"8.8.9.7"

Expected behavior

  1. let prefix=new Ip.Prefix("8.8.8.8",24)
  2. prefix.lastIp().toString() ;//"8.8.8.255"
@vasturiano
Copy link
Owner

vasturiano commented Feb 19, 2020

@mustafaKagan thanks for reaching out.

For performance reasons the Prefix constructor doesn't automatically check for bit boundary correctness, that's why you get those results on 8.8.8.8/24, which is invalid CIDR technically.
But, you can always force the correction after creation by running:

const prefix = (new Ip.Prefix("8.8.8.8",24)).correctBitBoundary();
prefix.lastIp().toString(); // "8.8.8.255"

@vasturiano vasturiano self-assigned this Feb 19, 2020
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