From 8ae5fd084c8aad0300c3882c2a5c4024193fb451 Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Wed, 29 Dec 2021 23:23:19 +0000 Subject: [PATCH 01/20] Added BigInt return to strToIpv6() This shouldn't change the outcome of any existing calls to strToIpv6 as the additional parameter is defaulted to not have any effect. --- src/core/lib/IP.mjs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/core/lib/IP.mjs b/src/core/lib/IP.mjs index c97f87ab..08c712e0 100644 --- a/src/core/lib/IP.mjs +++ b/src/core/lib/IP.mjs @@ -336,16 +336,27 @@ export function ipv4ToStr(ipInt) { /** - * Converts an IPv6 address from string format to numerical array format. + * Converts an IPv6 address from string format to numerical format. * * @param {string} ipStr - * @returns {number[]} + * @param {boolean} retArr If true, an array is returned. If false, a BigInt is returned. + * @returns {(number[]|BigInt)} * * @example * // returns [65280, 0, 0, 0, 0, 0, 4369, 8738] * strToIpv6("ff00::1111:2222"); + * + * // returns 126946n + * strToIpv6("1:f000", false); */ -export function strToIpv6(ipStr) { +export function strToIpv6(ipStr, retArr=true) { + if (retArr === false) { + if (ipStr.length % 2 === 1) { + ipStr = "0" + ipStr; + } + return BigInt("0x" + ipStr.replace(":", "")); + return + } let j = 0; const blocks = ipStr.split(":"), numBlocks = parseBlocks(blocks), From 588cd93900633abf15ffc503f3f3ac640e50bcfd Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Wed, 29 Dec 2021 23:31:39 +0000 Subject: [PATCH 02/20] Added sorting functionality --- src/core/lib/IP.mjs | 1 + src/core/operations/Sort.mjs | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/core/lib/IP.mjs b/src/core/lib/IP.mjs index 08c712e0..c43a0797 100644 --- a/src/core/lib/IP.mjs +++ b/src/core/lib/IP.mjs @@ -351,6 +351,7 @@ export function ipv4ToStr(ipInt) { */ export function strToIpv6(ipStr, retArr=true) { if (retArr === false) { + // TODO: Expand address. if (ipStr.length % 2 === 1) { ipStr = "0" + ipStr; } diff --git a/src/core/operations/Sort.mjs b/src/core/operations/Sort.mjs index a1148f7c..cd3b8e76 100644 --- a/src/core/operations/Sort.mjs +++ b/src/core/operations/Sort.mjs @@ -38,7 +38,7 @@ class Sort extends Operation { { "name": "Order", "type": "option", - "value": ["Alphabetical (case sensitive)", "Alphabetical (case insensitive)", "IP address", "Numeric", "Numeric (hexadecimal)"] + "value": ["Alphabetical (case sensitive)", "Alphabetical (case insensitive)", "IPv4 address", "IPv6 address", "Numeric", "Numeric (hexadecimal)"] } ]; } @@ -58,8 +58,10 @@ class Sort extends Operation { sorted = sorted.sort(); } else if (order === "Alphabetical (case insensitive)") { sorted = sorted.sort(Sort._caseInsensitiveSort); - } else if (order === "IP address") { - sorted = sorted.sort(Sort._ipSort); + } else if (order === "IPv4 address") { + sorted = sorted.sort(Sort._ipv4Sort); + } else if (order == "IPv6 address") { + sorted = sorted.sort(Sort._ipv6Sort); } else if (order === "Numeric") { sorted = sorted.sort(Sort._numericSort); } else if (order === "Numeric (hexadecimal)") { @@ -91,7 +93,7 @@ class Sort extends Operation { * @param {string} b * @returns {number} */ - static _ipSort(a, b) { + static _ipv4Sort(a, b) { let a_ = a.split("."), b_ = b.split("."); @@ -105,6 +107,19 @@ class Sort extends Operation { return a_ - b_; } + /** + * Comparison operator for sorting of IPv6 addresses. + * + * @param {string} a + * @param {string} b + * @returns {number} + */ + static _ipv6Sort(a, b) { + const numericalA = strToIpv6(a, false), + numericalB = strToIpv6(b, false); + return numericalA < numericalB ? -1 : 1; + } + /** * Comparison operation for sorting of numeric values. * From 200fbb2360be206ef9f397612bd0969104f114fc Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Thu, 30 Dec 2021 01:40:09 +0000 Subject: [PATCH 03/20] Minor fixes --- src/core/lib/IP.mjs | 3 +-- src/core/operations/Sort.mjs | 13 +++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/core/lib/IP.mjs b/src/core/lib/IP.mjs index c43a0797..350bca7a 100644 --- a/src/core/lib/IP.mjs +++ b/src/core/lib/IP.mjs @@ -345,7 +345,7 @@ export function ipv4ToStr(ipInt) { * @example * // returns [65280, 0, 0, 0, 0, 0, 4369, 8738] * strToIpv6("ff00::1111:2222"); - * + * * // returns 126946n * strToIpv6("1:f000", false); */ @@ -356,7 +356,6 @@ export function strToIpv6(ipStr, retArr=true) { ipStr = "0" + ipStr; } return BigInt("0x" + ipStr.replace(":", "")); - return } let j = 0; const blocks = ipStr.split(":"), diff --git a/src/core/operations/Sort.mjs b/src/core/operations/Sort.mjs index cd3b8e76..354a01ed 100644 --- a/src/core/operations/Sort.mjs +++ b/src/core/operations/Sort.mjs @@ -60,7 +60,7 @@ class Sort extends Operation { sorted = sorted.sort(Sort._caseInsensitiveSort); } else if (order === "IPv4 address") { sorted = sorted.sort(Sort._ipv4Sort); - } else if (order == "IPv6 address") { + } else if (order === "IPv6 address") { sorted = sorted.sort(Sort._ipv6Sort); } else if (order === "Numeric") { sorted = sorted.sort(Sort._numericSort); @@ -109,14 +109,15 @@ class Sort extends Operation { /** * Comparison operator for sorting of IPv6 addresses. - * - * @param {string} a - * @param {string} b + * + * @param {string} a + * @param {string} b * @returns {number} */ static _ipv6Sort(a, b) { - const numericalA = strToIpv6(a, false), - numericalB = strToIpv6(b, false); + const ipLib = require("../lib/IP.mjs"); + const numericalA = ipLib.strToIpv6(a, false), + numericalB = ipLib.strToIpv6(b, false); return numericalA < numericalB ? -1 : 1; } From 9b2d2c65caf9959ecc18587ced101c990625d2c4 Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Thu, 30 Dec 2021 01:54:20 +0000 Subject: [PATCH 04/20] Fixed errors --- src/core/lib/IP.mjs | 2 +- src/core/operations/Sort.mjs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/core/lib/IP.mjs b/src/core/lib/IP.mjs index 350bca7a..e5d18dd7 100644 --- a/src/core/lib/IP.mjs +++ b/src/core/lib/IP.mjs @@ -355,7 +355,7 @@ export function strToIpv6(ipStr, retArr=true) { if (ipStr.length % 2 === 1) { ipStr = "0" + ipStr; } - return BigInt("0x" + ipStr.replace(":", "")); + return Number("0x" + ipStr.replace(":", "")); } let j = 0; const blocks = ipStr.split(":"), diff --git a/src/core/operations/Sort.mjs b/src/core/operations/Sort.mjs index 354a01ed..da7ded80 100644 --- a/src/core/operations/Sort.mjs +++ b/src/core/operations/Sort.mjs @@ -116,8 +116,7 @@ class Sort extends Operation { */ static _ipv6Sort(a, b) { const ipLib = require("../lib/IP.mjs"); - const numericalA = ipLib.strToIpv6(a, false), - numericalB = ipLib.strToIpv6(b, false); + const numericalA = ipLib.strToIpv6(a, false), numericalB = ipLib.strToIpv6(b, false); return numericalA < numericalB ? -1 : 1; } From 74e2e7e924089a83fae22e302627b31a7e63eeb2 Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Thu, 30 Dec 2021 02:01:20 +0000 Subject: [PATCH 05/20] Fixed IPv6 sorting --- src/core/operations/Sort.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/operations/Sort.mjs b/src/core/operations/Sort.mjs index da7ded80..80e09b95 100644 --- a/src/core/operations/Sort.mjs +++ b/src/core/operations/Sort.mjs @@ -117,7 +117,7 @@ class Sort extends Operation { static _ipv6Sort(a, b) { const ipLib = require("../lib/IP.mjs"); const numericalA = ipLib.strToIpv6(a, false), numericalB = ipLib.strToIpv6(b, false); - return numericalA < numericalB ? -1 : 1; + return numericalA - numericalB; } /** From c9504ac6757fed8497fb5a89a764c5f33fc1c0ba Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Thu, 30 Dec 2021 02:22:43 +0000 Subject: [PATCH 06/20] Debugging --- src/core/operations/Sort.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/operations/Sort.mjs b/src/core/operations/Sort.mjs index 80e09b95..c3d75b32 100644 --- a/src/core/operations/Sort.mjs +++ b/src/core/operations/Sort.mjs @@ -117,6 +117,7 @@ class Sort extends Operation { static _ipv6Sort(a, b) { const ipLib = require("../lib/IP.mjs"); const numericalA = ipLib.strToIpv6(a, false), numericalB = ipLib.strToIpv6(b, false); + console.log(numericalA + " : " + numericalB); return numericalA - numericalB; } From 67886c886dbb9bce5d540a6c4fe623116eba9911 Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Thu, 30 Dec 2021 02:55:22 +0000 Subject: [PATCH 07/20] Update IP.mjs --- src/core/lib/IP.mjs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/core/lib/IP.mjs b/src/core/lib/IP.mjs index e5d18dd7..91283447 100644 --- a/src/core/lib/IP.mjs +++ b/src/core/lib/IP.mjs @@ -352,10 +352,7 @@ export function ipv4ToStr(ipInt) { export function strToIpv6(ipStr, retArr=true) { if (retArr === false) { // TODO: Expand address. - if (ipStr.length % 2 === 1) { - ipStr = "0" + ipStr; - } - return Number("0x" + ipStr.replace(":", "")); + return Number("0x" + ipStr.replace(/\:/g, '')); } let j = 0; const blocks = ipStr.split(":"), From 1eb6d03a6f8d4c3403b9cae315dbca879f9799f7 Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Thu, 30 Dec 2021 02:56:54 +0000 Subject: [PATCH 08/20] Update IP.mjs --- src/core/lib/IP.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/lib/IP.mjs b/src/core/lib/IP.mjs index 91283447..7235d1fa 100644 --- a/src/core/lib/IP.mjs +++ b/src/core/lib/IP.mjs @@ -352,7 +352,7 @@ export function ipv4ToStr(ipInt) { export function strToIpv6(ipStr, retArr=true) { if (retArr === false) { // TODO: Expand address. - return Number("0x" + ipStr.replace(/\:/g, '')); + return Number("0x" + ipStr.replace(/:/g, "")); } let j = 0; const blocks = ipStr.split(":"), From 1327a476b9af3a0a845d8c7700ac1ae8a4c04ddd Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Thu, 30 Dec 2021 14:03:46 +0000 Subject: [PATCH 09/20] Added expandIpv6() --- src/core/lib/IP.mjs | 35 +++++++++++++++++++++++++++++++++-- src/core/operations/Sort.mjs | 1 - 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/core/lib/IP.mjs b/src/core/lib/IP.mjs index 7235d1fa..2e5a7870 100644 --- a/src/core/lib/IP.mjs +++ b/src/core/lib/IP.mjs @@ -351,8 +351,7 @@ export function ipv4ToStr(ipInt) { */ export function strToIpv6(ipStr, retArr=true) { if (retArr === false) { - // TODO: Expand address. - return Number("0x" + ipStr.replace(/:/g, "")); + return Number("0x" + expandIpv6(ipStr).replace(/:/g, "")); } let j = 0; const blocks = ipStr.split(":"), @@ -386,6 +385,38 @@ export function strToIpv6(ipStr, retArr=true) { } } +/** + * Expands an IPv6 address in string format to its 'longhand' equivalent. + * + * @param {string} ipStr + * @returns {string} + * + * @example + * // returns "5555:126f:0000:0000:0000:0000:0000:0001" + * expandIpv6("5555:126f::0001"); + */ + export function expandIpv6(ipStr) { + const compactIndex = ipStr.search("::"); + if (compactIndex === -1) { + // There were no occurances of '::' + // in ipStr. + return ipStr; + } + let expandedStr = ipStr.substring(0, compactIndex); // 1234:5678::.. + const insertOffset = compactIndex == 0 ? 1 : 0; + const ipEnd = ipStr.substring(compactIndex + 1); + const missingChars = 39 - (expandedStr.length + ipEnd.length); + for (let i = insertOffset; i < missingChars + insertOffset; i++) { + if (i % 5 == 0) { + expandedStr += ":"; + continue; + } + expandedStr += "0"; + } + expandedStr += ipEnd; + return expandedStr; +} + /** * Converts an IPv6 address from numerical array format to string format. * diff --git a/src/core/operations/Sort.mjs b/src/core/operations/Sort.mjs index c3d75b32..80e09b95 100644 --- a/src/core/operations/Sort.mjs +++ b/src/core/operations/Sort.mjs @@ -117,7 +117,6 @@ class Sort extends Operation { static _ipv6Sort(a, b) { const ipLib = require("../lib/IP.mjs"); const numericalA = ipLib.strToIpv6(a, false), numericalB = ipLib.strToIpv6(b, false); - console.log(numericalA + " : " + numericalB); return numericalA - numericalB; } From 7af7b4df5e7095668962147848bfa91908610918 Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Thu, 30 Dec 2021 14:05:56 +0000 Subject: [PATCH 10/20] Adjusted strToIpv6 example #2 --- src/core/lib/IP.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/lib/IP.mjs b/src/core/lib/IP.mjs index 2e5a7870..b2473d2f 100644 --- a/src/core/lib/IP.mjs +++ b/src/core/lib/IP.mjs @@ -346,8 +346,8 @@ export function ipv4ToStr(ipInt) { * // returns [65280, 0, 0, 0, 0, 0, 4369, 8738] * strToIpv6("ff00::1111:2222"); * - * // returns 126946n - * strToIpv6("1:f000", false); + * // returns 3.3895313892515355e+38 + * strToIpv6("ff00::1111:2222", false); */ export function strToIpv6(ipStr, retArr=true) { if (retArr === false) { From 444065c9262ec9fd3894315c99dab12dc5a904d7 Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Thu, 30 Dec 2021 14:25:12 +0000 Subject: [PATCH 11/20] Improved ParseIPv6Address formatting --- src/core/lib/IP.mjs | 2 +- src/core/operations/ParseIPv6Address.mjs | 440 +++++++++++------------ 2 files changed, 220 insertions(+), 222 deletions(-) diff --git a/src/core/lib/IP.mjs b/src/core/lib/IP.mjs index b2473d2f..7eab1f33 100644 --- a/src/core/lib/IP.mjs +++ b/src/core/lib/IP.mjs @@ -403,7 +403,7 @@ export function strToIpv6(ipStr, retArr=true) { return ipStr; } let expandedStr = ipStr.substring(0, compactIndex); // 1234:5678::.. - const insertOffset = compactIndex == 0 ? 1 : 0; + const insertOffset = compactIndex == 0; const ipEnd = ipStr.substring(compactIndex + 1); const missingChars = 39 - (expandedStr.length + ipEnd.length); for (let i = insertOffset; i < missingChars + insertOffset; i++) { diff --git a/src/core/operations/ParseIPv6Address.mjs b/src/core/operations/ParseIPv6Address.mjs index f2141e01..0beaa6d3 100644 --- a/src/core/operations/ParseIPv6Address.mjs +++ b/src/core/operations/ParseIPv6Address.mjs @@ -38,235 +38,233 @@ class ParseIPv6Address extends Operation { run(input, args) { let match, output = ""; + if (!(match = IPV6_REGEX.exec(input))) { + throw new OperationError("Invalid IPv6 address."); + } + const ipv6 = strToIpv6(match[1]), + longhand = ipv6ToStr(ipv6), + shorthand = ipv6ToStr(ipv6, true); - if ((match = IPV6_REGEX.exec(input))) { - const ipv6 = strToIpv6(match[1]), - longhand = ipv6ToStr(ipv6), - shorthand = ipv6ToStr(ipv6, true); + output += "Longhand: " + longhand + "\nShorthand: " + shorthand + "\n"; - output += "Longhand: " + longhand + "\nShorthand: " + shorthand + "\n"; + // Detect reserved addresses + if (shorthand === "::") { + // Unspecified address + output += "\nUnspecified address corresponding to 0.0.0.0/32 in IPv4."; + output += "\nUnspecified address range: ::/128"; + } else if (shorthand === "::1") { + // Loopback address + output += "\nLoopback address to the local host corresponding to 127.0.0.1/8 in IPv4."; + output += "\nLoopback addresses range: ::1/128"; + } else if (ipv6[0] === 0 && ipv6[1] === 0 && ipv6[2] === 0 && + ipv6[3] === 0 && ipv6[4] === 0 && ipv6[5] === 0xffff) { + // IPv4-mapped IPv6 address + output += "\nIPv4-mapped IPv6 address detected. IPv6 clients will be handled natively by default, and IPv4 clients appear as IPv6 clients at their IPv4-mapped IPv6 address."; + output += "\nMapped IPv4 address: " + ipv4ToStr((ipv6[6] << 16) + ipv6[7]); + output += "\nIPv4-mapped IPv6 addresses range: ::ffff:0:0/96"; + } else if (ipv6[0] === 0 && ipv6[1] === 0 && ipv6[2] === 0 && + ipv6[3] === 0 && ipv6[4] === 0xffff && ipv6[5] === 0) { + // IPv4-translated address + output += "\nIPv4-translated address detected. Used by Stateless IP/ICMP Translation (SIIT). See RFCs 6145 and 6052 for more details."; + output += "\nTranslated IPv4 address: " + ipv4ToStr((ipv6[6] << 16) + ipv6[7]); + output += "\nIPv4-translated addresses range: ::ffff:0:0:0/96"; + } else if (ipv6[0] === 0x100) { + // Discard prefix per RFC 6666 + output += "\nDiscard prefix detected. This is used when forwarding traffic to a sinkhole router to mitigate the effects of a denial-of-service attack. See RFC 6666 for more details."; + output += "\nDiscard range: 100::/64"; + } else if (ipv6[0] === 0x64 && ipv6[1] === 0xff9b && ipv6[2] === 0 && + ipv6[3] === 0 && ipv6[4] === 0 && ipv6[5] === 0) { + // IPv4/IPv6 translation per RFC 6052 + output += "\n'Well-Known' prefix for IPv4/IPv6 translation detected. See RFC 6052 for more details."; + output += "\nTranslated IPv4 address: " + ipv4ToStr((ipv6[6] << 16) + ipv6[7]); + output += "\n'Well-Known' prefix range: 64:ff9b::/96"; + } else if (ipv6[0] === 0x2001 && ipv6[1] === 0) { + // Teredo tunneling + output += "\nTeredo tunneling IPv6 address detected\n"; + const serverIpv4 = (ipv6[2] << 16) + ipv6[3], + udpPort = (~ipv6[5]) & 0xffff, + clientIpv4 = ~((ipv6[6] << 16) + ipv6[7]), + flagCone = (ipv6[4] >>> 15) & 1, + flagR = (ipv6[4] >>> 14) & 1, + flagRandom1 = (ipv6[4] >>> 10) & 15, + flagUg = (ipv6[4] >>> 8) & 3, + flagRandom2 = ipv6[4] & 255; - // Detect reserved addresses - if (shorthand === "::") { - // Unspecified address - output += "\nUnspecified address corresponding to 0.0.0.0/32 in IPv4."; - output += "\nUnspecified address range: ::/128"; - } else if (shorthand === "::1") { - // Loopback address - output += "\nLoopback address to the local host corresponding to 127.0.0.1/8 in IPv4."; - output += "\nLoopback addresses range: ::1/128"; - } else if (ipv6[0] === 0 && ipv6[1] === 0 && ipv6[2] === 0 && - ipv6[3] === 0 && ipv6[4] === 0 && ipv6[5] === 0xffff) { - // IPv4-mapped IPv6 address - output += "\nIPv4-mapped IPv6 address detected. IPv6 clients will be handled natively by default, and IPv4 clients appear as IPv6 clients at their IPv4-mapped IPv6 address."; - output += "\nMapped IPv4 address: " + ipv4ToStr((ipv6[6] << 16) + ipv6[7]); - output += "\nIPv4-mapped IPv6 addresses range: ::ffff:0:0/96"; - } else if (ipv6[0] === 0 && ipv6[1] === 0 && ipv6[2] === 0 && - ipv6[3] === 0 && ipv6[4] === 0xffff && ipv6[5] === 0) { - // IPv4-translated address - output += "\nIPv4-translated address detected. Used by Stateless IP/ICMP Translation (SIIT). See RFCs 6145 and 6052 for more details."; - output += "\nTranslated IPv4 address: " + ipv4ToStr((ipv6[6] << 16) + ipv6[7]); - output += "\nIPv4-translated addresses range: ::ffff:0:0:0/96"; - } else if (ipv6[0] === 0x100) { - // Discard prefix per RFC 6666 - output += "\nDiscard prefix detected. This is used when forwarding traffic to a sinkhole router to mitigate the effects of a denial-of-service attack. See RFC 6666 for more details."; - output += "\nDiscard range: 100::/64"; - } else if (ipv6[0] === 0x64 && ipv6[1] === 0xff9b && ipv6[2] === 0 && - ipv6[3] === 0 && ipv6[4] === 0 && ipv6[5] === 0) { - // IPv4/IPv6 translation per RFC 6052 - output += "\n'Well-Known' prefix for IPv4/IPv6 translation detected. See RFC 6052 for more details."; - output += "\nTranslated IPv4 address: " + ipv4ToStr((ipv6[6] << 16) + ipv6[7]); - output += "\n'Well-Known' prefix range: 64:ff9b::/96"; - } else if (ipv6[0] === 0x2001 && ipv6[1] === 0) { - // Teredo tunneling - output += "\nTeredo tunneling IPv6 address detected\n"; - const serverIpv4 = (ipv6[2] << 16) + ipv6[3], - udpPort = (~ipv6[5]) & 0xffff, - clientIpv4 = ~((ipv6[6] << 16) + ipv6[7]), - flagCone = (ipv6[4] >>> 15) & 1, - flagR = (ipv6[4] >>> 14) & 1, - flagRandom1 = (ipv6[4] >>> 10) & 15, - flagUg = (ipv6[4] >>> 8) & 3, - flagRandom2 = ipv6[4] & 255; + output += "\nServer IPv4 address: " + ipv4ToStr(serverIpv4) + + "\nClient IPv4 address: " + ipv4ToStr(clientIpv4) + + "\nClient UDP port: " + udpPort + + "\nFlags:" + + "\n\tCone: " + flagCone; - output += "\nServer IPv4 address: " + ipv4ToStr(serverIpv4) + - "\nClient IPv4 address: " + ipv4ToStr(clientIpv4) + - "\nClient UDP port: " + udpPort + - "\nFlags:" + - "\n\tCone: " + flagCone; - - if (flagCone) { - output += " (Client is behind a cone NAT)"; - } else { - output += " (Client is not behind a cone NAT)"; - } - - output += "\n\tR: " + flagR; - - if (flagR) { - output += " Error: This flag should be set to 0. See RFC 5991 and RFC 4380."; - } - - output += "\n\tRandom1: " + Utils.bin(flagRandom1, 4) + - "\n\tUG: " + Utils.bin(flagUg, 2); - - if (flagUg) { - output += " Error: This flag should be set to 00. See RFC 4380."; - } - - output += "\n\tRandom2: " + Utils.bin(flagRandom2, 8); - - if (!flagR && !flagUg && flagRandom1 && flagRandom2) { - output += "\n\nThis is a valid Teredo address which complies with RFC 4380 and RFC 5991."; - } else if (!flagR && !flagUg) { - output += "\n\nThis is a valid Teredo address which complies with RFC 4380, however it does not comply with RFC 5991 (Teredo Security Updates) as there are no randomised bits in the flag field."; - } else { - output += "\n\nThis is an invalid Teredo address."; - } - output += "\n\nTeredo prefix range: 2001::/32"; - } else if (ipv6[0] === 0x2001 && ipv6[1] === 0x2 && ipv6[2] === 0) { - // Benchmarking - output += "\nAssigned to the Benchmarking Methodology Working Group (BMWG) for benchmarking IPv6. Corresponds to 198.18.0.0/15 for benchmarking IPv4. See RFC 5180 for more details."; - output += "\nBMWG range: 2001:2::/48"; - } else if (ipv6[0] === 0x2001 && ipv6[1] >= 0x10 && ipv6[1] <= 0x1f) { - // ORCHIDv1 - output += "\nDeprecated, previously ORCHIDv1 (Overlay Routable Cryptographic Hash Identifiers).\nORCHIDv1 range: 2001:10::/28\nORCHIDv2 now uses 2001:20::/28."; - } else if (ipv6[0] === 0x2001 && ipv6[1] >= 0x20 && ipv6[1] <= 0x2f) { - // ORCHIDv2 - output += "\nORCHIDv2 (Overlay Routable Cryptographic Hash Identifiers).\nThese are non-routed IPv6 addresses used for Cryptographic Hash Identifiers."; - output += "\nORCHIDv2 range: 2001:20::/28"; - } else if (ipv6[0] === 0x2001 && ipv6[1] === 0xdb8) { - // Documentation - output += "\nThis is a documentation IPv6 address. This range should be used whenever an example IPv6 address is given or to model networking scenarios. Corresponds to 192.0.2.0/24, 198.51.100.0/24, and 203.0.113.0/24 in IPv4."; - output += "\nDocumentation range: 2001:db8::/32"; - } else if (ipv6[0] === 0x2002) { - // 6to4 - output += "\n6to4 transition IPv6 address detected. See RFC 3056 for more details." + - "\n6to4 prefix range: 2002::/16"; - - const v4Addr = ipv4ToStr((ipv6[1] << 16) + ipv6[2]), - slaId = ipv6[3], - interfaceIdStr = ipv6[4].toString(16) + ipv6[5].toString(16) + ipv6[6].toString(16) + ipv6[7].toString(16), - interfaceId = new BigNumber(interfaceIdStr, 16); - - output += "\n\nEncapsulated IPv4 address: " + v4Addr + - "\nSLA ID: " + slaId + - "\nInterface ID (base 16): " + interfaceIdStr + - "\nInterface ID (base 10): " + interfaceId.toString(); - } else if (ipv6[0] >= 0xfc00 && ipv6[0] <= 0xfdff) { - // Unique local address - output += "\nThis is a unique local address comparable to the IPv4 private addresses 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. See RFC 4193 for more details."; - output += "\nUnique local addresses range: fc00::/7"; - } else if (ipv6[0] >= 0xfe80 && ipv6[0] <= 0xfebf) { - // Link-local address - output += "\nThis is a link-local address comparable to the auto-configuration addresses 169.254.0.0/16 in IPv4."; - output += "\nLink-local addresses range: fe80::/10"; - } else if (ipv6[0] >= 0xff00) { - // Multicast - output += "\nThis is a reserved multicast address."; - output += "\nMulticast addresses range: ff00::/8"; - - switch (ipv6[0]) { - case 0xff01: - output += "\n\nReserved Multicast Block for Interface Local Scope"; - break; - case 0xff02: - output += "\n\nReserved Multicast Block for Link Local Scope"; - break; - case 0xff03: - output += "\n\nReserved Multicast Block for Realm Local Scope"; - break; - case 0xff04: - output += "\n\nReserved Multicast Block for Admin Local Scope"; - break; - case 0xff05: - output += "\n\nReserved Multicast Block for Site Local Scope"; - break; - case 0xff08: - output += "\n\nReserved Multicast Block for Organisation Local Scope"; - break; - case 0xff0e: - output += "\n\nReserved Multicast Block for Global Scope"; - break; - } - - if (ipv6[6] === 1) { - if (ipv6[7] === 2) { - output += "\nReserved Multicast Address for 'All DHCP Servers and Relay Agents (defined in RFC3315)'"; - } else if (ipv6[7] === 3) { - output += "\nReserved Multicast Address for 'All LLMNR Hosts (defined in RFC4795)'"; - } - } else { - switch (ipv6[7]) { - case 1: - output += "\nReserved Multicast Address for 'All nodes'"; - break; - case 2: - output += "\nReserved Multicast Address for 'All routers'"; - break; - case 5: - output += "\nReserved Multicast Address for 'OSPFv3 - All OSPF routers'"; - break; - case 6: - output += "\nReserved Multicast Address for 'OSPFv3 - All Designated Routers'"; - break; - case 8: - output += "\nReserved Multicast Address for 'IS-IS for IPv6 Routers'"; - break; - case 9: - output += "\nReserved Multicast Address for 'RIP Routers'"; - break; - case 0xa: - output += "\nReserved Multicast Address for 'EIGRP Routers'"; - break; - case 0xc: - output += "\nReserved Multicast Address for 'Simple Service Discovery Protocol'"; - break; - case 0xd: - output += "\nReserved Multicast Address for 'PIM Routers'"; - break; - case 0x16: - output += "\nReserved Multicast Address for 'MLDv2 Reports (defined in RFC3810)'"; - break; - case 0x6b: - output += "\nReserved Multicast Address for 'Precision Time Protocol v2 Peer Delay Measurement Messages'"; - break; - case 0xfb: - output += "\nReserved Multicast Address for 'Multicast DNS'"; - break; - case 0x101: - output += "\nReserved Multicast Address for 'Network Time Protocol'"; - break; - case 0x108: - output += "\nReserved Multicast Address for 'Network Information Service'"; - break; - case 0x114: - output += "\nReserved Multicast Address for 'Experiments'"; - break; - case 0x181: - output += "\nReserved Multicast Address for 'Precision Time Protocol v2 Messages (exc. Peer Delay)'"; - break; - } - } + if (flagCone) { + output += " (Client is behind a cone NAT)"; + } else { + output += " (Client is not behind a cone NAT)"; } + output += "\n\tR: " + flagR; - // Detect possible EUI-64 addresses - if (((ipv6[5] & 0xff) === 0xff) && (ipv6[6] >>> 8 === 0xfe)) { - output += "\n\nThis IPv6 address contains a modified EUI-64 address, identified by the presence of FF:FE in the 12th and 13th octets."; - - const intIdent = Utils.hex(ipv6[4] >>> 8) + ":" + Utils.hex(ipv6[4] & 0xff) + ":" + - Utils.hex(ipv6[5] >>> 8) + ":" + Utils.hex(ipv6[5] & 0xff) + ":" + - Utils.hex(ipv6[6] >>> 8) + ":" + Utils.hex(ipv6[6] & 0xff) + ":" + - Utils.hex(ipv6[7] >>> 8) + ":" + Utils.hex(ipv6[7] & 0xff), - mac = Utils.hex((ipv6[4] >>> 8) ^ 2) + ":" + Utils.hex(ipv6[4] & 0xff) + ":" + - Utils.hex(ipv6[5] >>> 8) + ":" + Utils.hex(ipv6[6] & 0xff) + ":" + - Utils.hex(ipv6[7] >>> 8) + ":" + Utils.hex(ipv6[7] & 0xff); - output += "\nInterface identifier: " + intIdent + - "\nMAC address: " + mac; + if (flagR) { + output += " Error: This flag should be set to 0. See RFC 5991 and RFC 4380."; } - } else { - throw new OperationError("Invalid IPv6 address"); + + output += "\n\tRandom1: " + Utils.bin(flagRandom1, 4) + + "\n\tUG: " + Utils.bin(flagUg, 2); + + if (flagUg) { + output += " Error: This flag should be set to 00. See RFC 4380."; + } + + output += "\n\tRandom2: " + Utils.bin(flagRandom2, 8); + + if (!flagR && !flagUg && flagRandom1 && flagRandom2) { + output += "\n\nThis is a valid Teredo address which complies with RFC 4380 and RFC 5991."; + } else if (!flagR && !flagUg) { + output += "\n\nThis is a valid Teredo address which complies with RFC 4380, however it does not comply with RFC 5991 (Teredo Security Updates) as there are no randomised bits in the flag field."; + } else { + output += "\n\nThis is an invalid Teredo address."; + } + output += "\n\nTeredo prefix range: 2001::/32"; + } else if (ipv6[0] === 0x2001 && ipv6[1] === 0x2 && ipv6[2] === 0) { + // Benchmarking + output += "\nAssigned to the Benchmarking Methodology Working Group (BMWG) for benchmarking IPv6. Corresponds to 198.18.0.0/15 for benchmarking IPv4. See RFC 5180 for more details."; + output += "\nBMWG range: 2001:2::/48"; + } else if (ipv6[0] === 0x2001 && ipv6[1] >= 0x10 && ipv6[1] <= 0x1f) { + // ORCHIDv1 + output += "\nDeprecated, previously ORCHIDv1 (Overlay Routable Cryptographic Hash Identifiers).\nORCHIDv1 range: 2001:10::/28\nORCHIDv2 now uses 2001:20::/28."; + } else if (ipv6[0] === 0x2001 && ipv6[1] >= 0x20 && ipv6[1] <= 0x2f) { + // ORCHIDv2 + output += "\nORCHIDv2 (Overlay Routable Cryptographic Hash Identifiers).\nThese are non-routed IPv6 addresses used for Cryptographic Hash Identifiers."; + output += "\nORCHIDv2 range: 2001:20::/28"; + } else if (ipv6[0] === 0x2001 && ipv6[1] === 0xdb8) { + // Documentation + output += "\nThis is a documentation IPv6 address. This range should be used whenever an example IPv6 address is given or to model networking scenarios. Corresponds to 192.0.2.0/24, 198.51.100.0/24, and 203.0.113.0/24 in IPv4."; + output += "\nDocumentation range: 2001:db8::/32"; + } else if (ipv6[0] === 0x2002) { + // 6to4 + output += "\n6to4 transition IPv6 address detected. See RFC 3056 for more details." + + "\n6to4 prefix range: 2002::/16"; + + const v4Addr = ipv4ToStr((ipv6[1] << 16) + ipv6[2]), + slaId = ipv6[3], + interfaceIdStr = ipv6[4].toString(16) + ipv6[5].toString(16) + ipv6[6].toString(16) + ipv6[7].toString(16), + interfaceId = new BigNumber(interfaceIdStr, 16); + + output += "\n\nEncapsulated IPv4 address: " + v4Addr + + "\nSLA ID: " + slaId + + "\nInterface ID (base 16): " + interfaceIdStr + + "\nInterface ID (base 10): " + interfaceId.toString(); + } else if (ipv6[0] >= 0xfc00 && ipv6[0] <= 0xfdff) { + // Unique local address + output += "\nThis is a unique local address comparable to the IPv4 private addresses 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. See RFC 4193 for more details."; + output += "\nUnique local addresses range: fc00::/7"; + } else if (ipv6[0] >= 0xfe80 && ipv6[0] <= 0xfebf) { + // Link-local address + output += "\nThis is a link-local address comparable to the auto-configuration addresses 169.254.0.0/16 in IPv4."; + output += "\nLink-local addresses range: fe80::/10"; + } else if (ipv6[0] >= 0xff00) { + // Multicast + output += "\nThis is a reserved multicast address."; + output += "\nMulticast addresses range: ff00::/8"; + + switch (ipv6[0]) { + case 0xff01: + output += "\n\nReserved Multicast Block for Interface Local Scope"; + break; + case 0xff02: + output += "\n\nReserved Multicast Block for Link Local Scope"; + break; + case 0xff03: + output += "\n\nReserved Multicast Block for Realm Local Scope"; + break; + case 0xff04: + output += "\n\nReserved Multicast Block for Admin Local Scope"; + break; + case 0xff05: + output += "\n\nReserved Multicast Block for Site Local Scope"; + break; + case 0xff08: + output += "\n\nReserved Multicast Block for Organisation Local Scope"; + break; + case 0xff0e: + output += "\n\nReserved Multicast Block for Global Scope"; + break; + } + + if (ipv6[6] === 1) { + if (ipv6[7] === 2) { + output += "\nReserved Multicast Address for 'All DHCP Servers and Relay Agents (defined in RFC3315)'"; + } else if (ipv6[7] === 3) { + output += "\nReserved Multicast Address for 'All LLMNR Hosts (defined in RFC4795)'"; + } + } else { + switch (ipv6[7]) { + case 1: + output += "\nReserved Multicast Address for 'All nodes'"; + break; + case 2: + output += "\nReserved Multicast Address for 'All routers'"; + break; + case 5: + output += "\nReserved Multicast Address for 'OSPFv3 - All OSPF routers'"; + break; + case 6: + output += "\nReserved Multicast Address for 'OSPFv3 - All Designated Routers'"; + break; + case 8: + output += "\nReserved Multicast Address for 'IS-IS for IPv6 Routers'"; + break; + case 9: + output += "\nReserved Multicast Address for 'RIP Routers'"; + break; + case 0xa: + output += "\nReserved Multicast Address for 'EIGRP Routers'"; + break; + case 0xc: + output += "\nReserved Multicast Address for 'Simple Service Discovery Protocol'"; + break; + case 0xd: + output += "\nReserved Multicast Address for 'PIM Routers'"; + break; + case 0x16: + output += "\nReserved Multicast Address for 'MLDv2 Reports (defined in RFC3810)'"; + break; + case 0x6b: + output += "\nReserved Multicast Address for 'Precision Time Protocol v2 Peer Delay Measurement Messages'"; + break; + case 0xfb: + output += "\nReserved Multicast Address for 'Multicast DNS'"; + break; + case 0x101: + output += "\nReserved Multicast Address for 'Network Time Protocol'"; + break; + case 0x108: + output += "\nReserved Multicast Address for 'Network Information Service'"; + break; + case 0x114: + output += "\nReserved Multicast Address for 'Experiments'"; + break; + case 0x181: + output += "\nReserved Multicast Address for 'Precision Time Protocol v2 Messages (exc. Peer Delay)'"; + break; + } + } + } + + + // Detect possible EUI-64 addresses + if (((ipv6[5] & 0xff) === 0xff) && (ipv6[6] >>> 8 === 0xfe)) { + output += "\n\nThis IPv6 address contains a modified EUI-64 address, identified by the presence of FF:FE in the 12th and 13th octets."; + + const intIdent = Utils.hex(ipv6[4] >>> 8) + ":" + Utils.hex(ipv6[4] & 0xff) + ":" + + Utils.hex(ipv6[5] >>> 8) + ":" + Utils.hex(ipv6[5] & 0xff) + ":" + + Utils.hex(ipv6[6] >>> 8) + ":" + Utils.hex(ipv6[6] & 0xff) + ":" + + Utils.hex(ipv6[7] >>> 8) + ":" + Utils.hex(ipv6[7] & 0xff), + mac = Utils.hex((ipv6[4] >>> 8) ^ 2) + ":" + Utils.hex(ipv6[4] & 0xff) + ":" + + Utils.hex(ipv6[5] >>> 8) + ":" + Utils.hex(ipv6[6] & 0xff) + ":" + + Utils.hex(ipv6[7] >>> 8) + ":" + Utils.hex(ipv6[7] & 0xff); + output += "\nInterface identifier: " + intIdent + + "\nMAC address: " + mac; } return output; } From ea8acc60350afe6293808ffdd6b7406b23fd48fb Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Thu, 30 Dec 2021 14:33:43 +0000 Subject: [PATCH 12/20] Accounted for compact endings in expandIpv6 When an address ended in '::' the function would return an invalid string, this commit fixes that issue. --- src/core/lib/IP.mjs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/core/lib/IP.mjs b/src/core/lib/IP.mjs index 7eab1f33..0393f8d9 100644 --- a/src/core/lib/IP.mjs +++ b/src/core/lib/IP.mjs @@ -397,14 +397,9 @@ export function strToIpv6(ipStr, retArr=true) { */ export function expandIpv6(ipStr) { const compactIndex = ipStr.search("::"); - if (compactIndex === -1) { - // There were no occurances of '::' - // in ipStr. - return ipStr; - } let expandedStr = ipStr.substring(0, compactIndex); // 1234:5678::.. const insertOffset = compactIndex == 0; - const ipEnd = ipStr.substring(compactIndex + 1); + const ipEnd = ipStr.substring(compactIndex + 1); // :7ABC:DEFG:... const missingChars = 39 - (expandedStr.length + ipEnd.length); for (let i = insertOffset; i < missingChars + insertOffset; i++) { if (i % 5 == 0) { @@ -413,6 +408,10 @@ export function strToIpv6(ipStr, retArr=true) { } expandedStr += "0"; } + if (compactIndex === ipStr.length - 2) { + expandedStr = expandedStr + "0"; + return expandedStr; + } expandedStr += ipEnd; return expandedStr; } From 05f51b30d0df1d79aaf8034a467066024503b244 Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Thu, 30 Dec 2021 14:37:33 +0000 Subject: [PATCH 13/20] Fixed compilation errors --- src/core/lib/IP.mjs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/lib/IP.mjs b/src/core/lib/IP.mjs index 0393f8d9..f72fa2ae 100644 --- a/src/core/lib/IP.mjs +++ b/src/core/lib/IP.mjs @@ -390,19 +390,19 @@ export function strToIpv6(ipStr, retArr=true) { * * @param {string} ipStr * @returns {string} - * + * * @example * // returns "5555:126f:0000:0000:0000:0000:0000:0001" * expandIpv6("5555:126f::0001"); */ - export function expandIpv6(ipStr) { +export function expandIpv6(ipStr) { const compactIndex = ipStr.search("::"); let expandedStr = ipStr.substring(0, compactIndex); // 1234:5678::.. - const insertOffset = compactIndex == 0; + const insertOffset = compactIndex === 0; // 0 / 1 const ipEnd = ipStr.substring(compactIndex + 1); // :7ABC:DEFG:... const missingChars = 39 - (expandedStr.length + ipEnd.length); for (let i = insertOffset; i < missingChars + insertOffset; i++) { - if (i % 5 == 0) { + if (i % 5 === 0) { expandedStr += ":"; continue; } From 680650f86ceacbd6a32ec9fef2a95e16ef613c19 Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Thu, 30 Dec 2021 15:50:41 +0000 Subject: [PATCH 14/20] Rewrote expandIpv6() This version of the function pads the hex-blocks of IPv6 addresses ("ff0:..." -> "0ff0:...") whereas the original did not. --- src/core/lib/IP.mjs | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/core/lib/IP.mjs b/src/core/lib/IP.mjs index f72fa2ae..5b93507a 100644 --- a/src/core/lib/IP.mjs +++ b/src/core/lib/IP.mjs @@ -396,24 +396,36 @@ export function strToIpv6(ipStr, retArr=true) { * expandIpv6("5555:126f::0001"); */ export function expandIpv6(ipStr) { - const compactIndex = ipStr.search("::"); - let expandedStr = ipStr.substring(0, compactIndex); // 1234:5678::.. - const insertOffset = compactIndex === 0; // 0 / 1 - const ipEnd = ipStr.substring(compactIndex + 1); // :7ABC:DEFG:... - const missingChars = 39 - (expandedStr.length + ipEnd.length); - for (let i = insertOffset; i < missingChars + insertOffset; i++) { - if (i % 5 === 0) { - expandedStr += ":"; - continue; + const padHex = function(ipStr){ + if (ipStr.length === 39) { + return ipStr; } - expandedStr += "0"; + const blockArray = ipStr.split(':'); + let reconstructed = ""; + blockArray.forEach((a) => { + for (let i = a.length; i < 4; i++) { + reconstructed += "0"; + } + reconstructed += a + ":"; + }); + return reconstructed.substring(0, reconstructed.length - 1); + }; + ipStr = padHex(ipStr); + const doubleColonOffset = ipStr.search("::"); + if (doubleColonOffset === -1) { + return ipStr; } - if (compactIndex === ipStr.length - 2) { - expandedStr = expandedStr + "0"; - return expandedStr; + const totalBlocks = ipStr.match(/:/g).length - (ipStr.startsWith(":") || ipStr.endsWith(":")), + reqBlocks = 8 - totalBlocks; + let expandedBlocks = (ipStr.startsWith(":") ? "" : ":") + "0000"; + for (let i = 1; i < reqBlocks; i++) { + expandedBlocks += ":0000"; } - expandedStr += ipEnd; - return expandedStr; + ipStr = ipStr.substring(0, doubleColonOffset) + expandedBlocks + ":" + ipStr.substring(doubleColonOffset + 2); + if (ipStr.endsWith(":")) { + ipStr = ipStr.substring(0, ipStr.length - 1); + } + return padHex(ipStr); } /** From 3326329c296a48bd3e5bdf1bd9db7bc63018912d Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Thu, 30 Dec 2021 16:09:59 +0000 Subject: [PATCH 15/20] Fixed errors --- src/core/lib/IP.mjs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/lib/IP.mjs b/src/core/lib/IP.mjs index 5b93507a..e6e97058 100644 --- a/src/core/lib/IP.mjs +++ b/src/core/lib/IP.mjs @@ -396,11 +396,11 @@ export function strToIpv6(ipStr, retArr=true) { * expandIpv6("5555:126f::0001"); */ export function expandIpv6(ipStr) { - const padHex = function(ipStr){ + const padHex = function (ipStr) { if (ipStr.length === 39) { return ipStr; } - const blockArray = ipStr.split(':'); + const blockArray = ipStr.split(":"); let reconstructed = ""; blockArray.forEach((a) => { for (let i = a.length; i < 4; i++) { @@ -416,7 +416,7 @@ export function expandIpv6(ipStr) { return ipStr; } const totalBlocks = ipStr.match(/:/g).length - (ipStr.startsWith(":") || ipStr.endsWith(":")), - reqBlocks = 8 - totalBlocks; + reqBlocks = 8 - totalBlocks; let expandedBlocks = (ipStr.startsWith(":") ? "" : ":") + "0000"; for (let i = 1; i < reqBlocks; i++) { expandedBlocks += ":0000"; From 1c1d24df8f39e657fd7c2f97f612dd507864960a Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Thu, 30 Dec 2021 16:29:54 +0000 Subject: [PATCH 16/20] Updated expandIpv6() example --- src/core/lib/IP.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/lib/IP.mjs b/src/core/lib/IP.mjs index e6e97058..8fef8c77 100644 --- a/src/core/lib/IP.mjs +++ b/src/core/lib/IP.mjs @@ -393,7 +393,7 @@ export function strToIpv6(ipStr, retArr=true) { * * @example * // returns "5555:126f:0000:0000:0000:0000:0000:0001" - * expandIpv6("5555:126f::0001"); + * expandIpv6("5555:126f::1"); */ export function expandIpv6(ipStr) { const padHex = function (ipStr) { From 9b41fb3c68834cef3b70b8f5bf6b683566aa5f23 Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Thu, 30 Dec 2021 16:36:06 +0000 Subject: [PATCH 17/20] Corrected return value of strToIpv6() --- src/core/lib/IP.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/lib/IP.mjs b/src/core/lib/IP.mjs index 8fef8c77..59cc8fce 100644 --- a/src/core/lib/IP.mjs +++ b/src/core/lib/IP.mjs @@ -340,7 +340,7 @@ export function ipv4ToStr(ipInt) { * * @param {string} ipStr * @param {boolean} retArr If true, an array is returned. If false, a BigInt is returned. - * @returns {(number[]|BigInt)} + * @returns {(number[]|number)} * * @example * // returns [65280, 0, 0, 0, 0, 0, 4369, 8738] From 0c0a035a531012a08f68a4381e9710127a29e7fe Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Thu, 30 Dec 2021 22:51:30 +0000 Subject: [PATCH 18/20] Added @author --- src/core/lib/IP.mjs | 1 + src/core/operations/ParseIPv6Address.mjs | 1 + src/core/operations/Sort.mjs | 1 + 3 files changed, 3 insertions(+) diff --git a/src/core/lib/IP.mjs b/src/core/lib/IP.mjs index 59cc8fce..c1b37371 100644 --- a/src/core/lib/IP.mjs +++ b/src/core/lib/IP.mjs @@ -3,6 +3,7 @@ * * @author picapi * @author n1474335 [n1474335@gmail.com] + * @author Michael Rowley [michaellrowley@protonmail.com] * @author Klaxon [klaxon@veyr.com] * @copyright Crown Copyright 2016 * @license Apache-2.0 diff --git a/src/core/operations/ParseIPv6Address.mjs b/src/core/operations/ParseIPv6Address.mjs index 0beaa6d3..3fb9f383 100644 --- a/src/core/operations/ParseIPv6Address.mjs +++ b/src/core/operations/ParseIPv6Address.mjs @@ -1,5 +1,6 @@ /** * @author n1474335 [n1474335@gmail.com] + * @author Michael Rowley [michaellrowley@protonmail.com] * @copyright Crown Copyright 2016 * @license Apache-2.0 */ diff --git a/src/core/operations/Sort.mjs b/src/core/operations/Sort.mjs index 80e09b95..2feb3587 100644 --- a/src/core/operations/Sort.mjs +++ b/src/core/operations/Sort.mjs @@ -1,5 +1,6 @@ /** * @author n1474335 [n1474335@gmail.com] + * @author Michael Rowley [michaellrowley@protonmail.com] * @copyright Crown Copyright 2016 * @license Apache-2.0 */ From 51a7cdff06480b0cf01180a67ec68cc63740e48e Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Fri, 31 Dec 2021 14:05:59 +0000 Subject: [PATCH 19/20] Added strToIpv6 import --- src/core/operations/Sort.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/operations/Sort.mjs b/src/core/operations/Sort.mjs index 2feb3587..8092f62c 100644 --- a/src/core/operations/Sort.mjs +++ b/src/core/operations/Sort.mjs @@ -8,6 +8,7 @@ import Operation from "../Operation.mjs"; import Utils from "../Utils.mjs"; import {INPUT_DELIM_OPTIONS} from "../lib/Delim.mjs"; +import {strToIpv6} from "../lib/IP.mjs"; /** * Sort operation @@ -116,8 +117,7 @@ class Sort extends Operation { * @returns {number} */ static _ipv6Sort(a, b) { - const ipLib = require("../lib/IP.mjs"); - const numericalA = ipLib.strToIpv6(a, false), numericalB = ipLib.strToIpv6(b, false); + const numericalA = strToIpv6(a, false), numericalB = strToIpv6(b, false); return numericalA - numericalB; } From bc093bce2ca05fb8a7df54f427dbb156233c5d53 Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Fri, 31 Dec 2021 22:03:05 +0000 Subject: [PATCH 20/20] Revert "Added @author" This reverts commit 0c0a035a531012a08f68a4381e9710127a29e7fe. --- src/core/lib/IP.mjs | 1 - src/core/operations/ParseIPv6Address.mjs | 1 - src/core/operations/Sort.mjs | 1 - 3 files changed, 3 deletions(-) diff --git a/src/core/lib/IP.mjs b/src/core/lib/IP.mjs index c1b37371..59cc8fce 100644 --- a/src/core/lib/IP.mjs +++ b/src/core/lib/IP.mjs @@ -3,7 +3,6 @@ * * @author picapi * @author n1474335 [n1474335@gmail.com] - * @author Michael Rowley [michaellrowley@protonmail.com] * @author Klaxon [klaxon@veyr.com] * @copyright Crown Copyright 2016 * @license Apache-2.0 diff --git a/src/core/operations/ParseIPv6Address.mjs b/src/core/operations/ParseIPv6Address.mjs index 3fb9f383..0beaa6d3 100644 --- a/src/core/operations/ParseIPv6Address.mjs +++ b/src/core/operations/ParseIPv6Address.mjs @@ -1,6 +1,5 @@ /** * @author n1474335 [n1474335@gmail.com] - * @author Michael Rowley [michaellrowley@protonmail.com] * @copyright Crown Copyright 2016 * @license Apache-2.0 */ diff --git a/src/core/operations/Sort.mjs b/src/core/operations/Sort.mjs index 8092f62c..b5caf0ae 100644 --- a/src/core/operations/Sort.mjs +++ b/src/core/operations/Sort.mjs @@ -1,6 +1,5 @@ /** * @author n1474335 [n1474335@gmail.com] - * @author Michael Rowley [michaellrowley@protonmail.com] * @copyright Crown Copyright 2016 * @license Apache-2.0 */