cidr-js icon indicating copy to clipboard operation
cidr-js copied to clipboard

list method incorrect for some ranges

Open DigitalZebra opened this issue 9 years ago • 3 comments

Hello! Thanks for the super useful library. I think there may be an issue with the list method and some CIDR blocks.

For the CIDR block of 255.255.142.72/28, I'd expect list to list the IP addresses from the range 255.255.142.64 to 255.255.142.79; a total of 16 IP addresses. However, cidr-js gives me a range from 255.255.142.64 to 255.255.142.87; a total of 24 IP addresses.

console.log(new CIDR().list('255.255.142.72/28'));
// prints out:
/*
[ '255.255.142.64',
  '255.255.142.65',
  '255.255.142.66',
  '255.255.142.67',
  '255.255.142.68',
  '255.255.142.69',
  '255.255.142.70',
  '255.255.142.71',
  '255.255.142.72',
  '255.255.142.73',
  '255.255.142.74',
  '255.255.142.75',
  '255.255.142.76',
  '255.255.142.77',
  '255.255.142.78',
  '255.255.142.79',
  '255.255.142.80',
  '255.255.142.81',
  '255.255.142.82',
  '255.255.142.83',
  '255.255.142.84',
  '255.255.142.85',
  '255.255.142.86',
  '255.255.142.87' ]
*/

DigitalZebra avatar Sep 10 '15 22:09 DigitalZebra

Thanks for the feedback! I pushed some updates to a branch. Let me know if the changes in this branch fixes the issue.

krg7880 avatar Sep 11 '15 15:09 krg7880

@DigitalZebra - Note that I will enhance the test suite for the range function before merging this to the master branch. I added your use case to the test suite, but would like to include some more just to boost confidence.

krg7880 avatar Sep 11 '15 15:09 krg7880

I can confirm .list is still broken (version 2.2.1). Correction: for the above example.

And some other sites are giving conflicting results. My usage was for 1.1.1.1/28. Wolfram gave 1 fewer IP.

tony-cocco avatar Nov 16 '15 21:11 tony-cocco