ip-utilties 3.1.3 → 3.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/ip.mjs +16 -9
package/package.json
CHANGED
package/src/ip.mjs
CHANGED
|
@@ -17,7 +17,8 @@ const ipv4 = {
|
|
|
17
17
|
segments: 4,
|
|
18
18
|
segmentLength: 8,
|
|
19
19
|
segmentMask: 0xffn,
|
|
20
|
-
base: 10
|
|
20
|
+
base: 10,
|
|
21
|
+
linkLocalPrefixLength: 16
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
const ipv6 = {
|
|
@@ -37,7 +38,8 @@ const ipv6 = {
|
|
|
37
38
|
segments: 8,
|
|
38
39
|
segmentLength: 16,
|
|
39
40
|
segmentMask: 0xffffn,
|
|
40
|
-
base: 16
|
|
41
|
+
base: 16,
|
|
42
|
+
linkLocalPrefixLength: 64
|
|
41
43
|
};
|
|
42
44
|
|
|
43
45
|
/**
|
|
@@ -249,19 +251,23 @@ export function normalizeCIDR(address) {
|
|
|
249
251
|
let [prefix, prefixLength] = address.split(/\//);
|
|
250
252
|
let longPrefix;
|
|
251
253
|
|
|
254
|
+
const family = isIPv6(prefix) ? ipv6 : ipv4;
|
|
255
|
+
|
|
252
256
|
if (isUniqueLocal(address) || isLinkLocal(address)) {
|
|
253
|
-
prefixLength =
|
|
254
|
-
const n = _prefix(
|
|
255
|
-
prefix = _decode(
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
257
|
+
prefixLength = family.linkLocalPrefixLength;
|
|
258
|
+
const n = _prefix(family, address, prefixLength);
|
|
259
|
+
prefix = _decode(family, n, prefixLength);
|
|
260
|
+
|
|
261
|
+
if (family == ipv6) {
|
|
262
|
+
if (!prefix.endsWith("::")) {
|
|
263
|
+
// TODO
|
|
264
|
+
prefix += prefix.endsWith(":") ? ":" : "::";
|
|
265
|
+
}
|
|
259
266
|
}
|
|
260
267
|
longPrefix = prefix;
|
|
261
268
|
} else {
|
|
262
269
|
prefixLength = prefixLength === undefined ? 0 : parseInt(prefixLength);
|
|
263
270
|
|
|
264
|
-
const family = /*_family(prefix); */ isIPv6(prefix) ? ipv6 : ipv4;
|
|
265
271
|
let n;
|
|
266
272
|
|
|
267
273
|
if (prefixLength) {
|
|
@@ -364,6 +370,7 @@ export function hasWellKnownSubnet(address) {
|
|
|
364
370
|
::1 128. local host
|
|
365
371
|
127 8 local host
|
|
366
372
|
172
|
|
373
|
+
|
|
367
374
|
*/
|
|
368
375
|
|
|
369
376
|
/*
|