fix(ParseIPRange): mask host bits in Network output for CIDR ranges
The 'Parse IP range' operation echoed the raw input address on the 'Network:' line for CIDR ranges instead of the network address. For '10.1.2.3/24' it printed 'Network: 10.1.2.3' rather than the masked 'Network: 10.1.2.0', even though the adjacent 'Range:' line and the IP-list code path already use the masked value. Use the masked address (ip1 = network & mask) for the IPv4 'Network:' line and the IPv6 'Network:' and 'Shorthand:' lines, matching the 'Range:' output in the same functions. Fixes #1950
This commit is contained in:
parent
c56dd23358
commit
561419eb77
@ -34,7 +34,7 @@ export function ipv4CidrRange(cidr, includeNetworkInfo, enumerateAddresses, allo
|
||||
ip2 = ip1 | ~mask;
|
||||
|
||||
if (includeNetworkInfo) {
|
||||
output += "Network: " + ipv4ToStr(network) + "\n";
|
||||
output += "Network: " + ipv4ToStr(ip1) + "\n";
|
||||
output += "CIDR: " + cidrRange + "\n";
|
||||
output += "Mask: " + ipv4ToStr(mask) + "\n";
|
||||
output += "Range: " + ipv4ToStr(ip1) + " - " + ipv4ToStr(ip2) + "\n";
|
||||
@ -88,8 +88,8 @@ export function ipv6CidrRange(cidr, includeNetworkInfo) {
|
||||
}
|
||||
|
||||
if (includeNetworkInfo) {
|
||||
output += "Network: " + ipv6ToStr(network) + "\n";
|
||||
output += "Shorthand: " + ipv6ToStr(network, true) + "\n";
|
||||
output += "Network: " + ipv6ToStr(ip1) + "\n";
|
||||
output += "Shorthand: " + ipv6ToStr(ip1, true) + "\n";
|
||||
output += "CIDR: " + cidrRange + "\n";
|
||||
output += "Mask: " + ipv6ToStr(mask) + "\n";
|
||||
output += "Range: " + ipv6ToStr(ip1) + " - " + ipv6ToStr(ip2) + "\n";
|
||||
|
||||
@ -19,6 +19,28 @@ TestRegister.addTests([
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Parse IPv4 CIDR with host bits set",
|
||||
input: "10.0.0.1/30",
|
||||
expectedOutput: "Network: 10.0.0.0\nCIDR: 30\nMask: 255.255.255.252\nRange: 10.0.0.0 - 10.0.0.3\nTotal addresses in range: 4\n\n10.0.0.0\n10.0.0.1\n10.0.0.2\n10.0.0.3",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Parse IP range",
|
||||
"args": [true, true, false]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Parse IPv6 CIDR with host bits set",
|
||||
input: "2404:6800:4001:0001:0000:0000:0000:0000/48",
|
||||
expectedOutput: "Network: 2404:6800:4001:0000:0000:0000:0000:0000\nShorthand: 2404:6800:4001::\nCIDR: 48\nMask: ffff:ffff:ffff:0000:0000:0000:0000:0000\nRange: 2404:6800:4001:0000:0000:0000:0000:0000 - 2404:6800:4001:ffff:ffff:ffff:ffff:ffff\nTotal addresses in range: 1.2089258196146292e+24\n\n",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Parse IP range",
|
||||
"args": [true, true, false]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Parse IPv4 hyphenated",
|
||||
input: "10.0.0.0 - 10.0.0.3",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user