Classes
Methods
_getBinaryPrefix(cidr, prefix_length) → {string}
Convert one subnet to the binary representation of its IP address, truncated to its CIDR prefix length. If the cidr is incomplete or specifies no prefix length, assume it is the left-most portion of the CIDR, and consider its binary length to be its prefix_length.
Parameters:
Name | Type | Description |
---|---|---|
cidr |
string | The CIDR whose binary prefix should be returned |
prefix_length |
number | The integer length of the CIDR's binary prefix |
Returns:
The CIDR's binary prefix
- Type
- string
_getClasses(cidr) → {array}
Get the CIDR's classes as an array of classes
Parameters:
Name | Type | Description |
---|---|---|
cidr |
string | The CIDR whose classes should be returned |
Returns:
An array of the classes in the CIDR
- Type
- array
_getPrefixesOfShortestEqualLength(first_cidr, second_cidr) → {array}
Convert subnets to their IP addresses' binary representations, truncated to the shortest of their two CIDR prefix lengths
Parameters:
Name | Type | Description |
---|---|---|
first_cidr |
string | The first CIDR from which to get a prefix |
second_cidr |
string | The second CIDR from which to get a prefix |
Returns:
An array containing the binary representations of the two input CIDRs, truncated to the shortest of their two prefix lengths
- Type
- array
_getPrefixLength(cidr) → {number}
Get the CIDR's prefix length as an integer. Handle incomplete cidrs by counting their binary length as their prefix_length.
Parameters:
Name | Type | Description |
---|---|---|
cidr |
string | The CIDR whose prefix length should be returned |
Returns:
The CIDR's prefix length as an integer
- Type
- number
doSubnetsOverlap(first_cidr, second_cidr) → {boolean}
Determine if the new subnet overlaps the existing subnet
Parameters:
Name | Type | Description |
---|---|---|
first_cidr |
string | The first CIDR to compare |
second_cidr |
string | The second CIDR to compare |
Returns:
- Type
- boolean
getBinaryRepresentation(cidr) → {string}
Get the CIDR's binary representation including both its prefix and suffix
Parameters:
Name | Type | Description |
---|---|---|
cidr |
string | The CIDR whose binary representation should be returned |
Returns:
The CIDR's binary representation
- Type
- string
sortCidrByBinary(a, b) → {number}
Sort CIDRs by their binary representation
Parameters:
Name | Type | Description |
---|---|---|
a |
string | The first CIDR to sort |
b |
string | The second CIDR to sort |
Returns:
1 means sort a before b; 0 means they sort to the same level; -1 means sort a after b
- Type
- number