cidrSubnet() is skipping first/last address
- Dominant language
- JavaScript
- Stars
- 1.5k
- Forks
- 228
- PR merge metrics
- No merged PRs in 30d
Description
AFAIK, `ip.cidrSubnet('192.168.1.0/30')` should return 4 hosts in the range `192.168.1.0 - 192.168.1.3`, but it actually returns 2 hosts in the range `192.168.1.1 - 192.168.1.2`.
I checked out the source code and the reason is pretty obvious in `subnet()`:
```
firstAddress: numberOfAddresses <= 2 ?
ip.fromLong(networkAddress) :
ip.fromLong(networkAddress + 1),
```
However, I can't understand the reason of such implementation. What am I missing?
Thank you,
Marco
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the `subnet()` implementation reached by `ip.cidrSubnet()` and reproduce the `192.168.1.0/30` example from the issue. Determine whether excluding the first and last addresses is intentional, then make the returned count and range match the agreed behavior and add regression coverage if the repository has a suitable test entry point.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100