ip-utilties 3.1.4 → 3.2.0
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 +17 -5
- package/types/ip.d.mts +1 -0
package/package.json
CHANGED
package/src/ip.mjs
CHANGED
|
@@ -18,6 +18,7 @@ const ipv4 = {
|
|
|
18
18
|
segmentLength: 8,
|
|
19
19
|
segmentMask: 0xffn,
|
|
20
20
|
base: 10,
|
|
21
|
+
linkLocalPrefix: new Uint8Array([169, 254]),
|
|
21
22
|
linkLocalPrefixLength: 16
|
|
22
23
|
};
|
|
23
24
|
|
|
@@ -39,6 +40,7 @@ const ipv6 = {
|
|
|
39
40
|
segmentLength: 16,
|
|
40
41
|
segmentMask: 0xffffn,
|
|
41
42
|
base: 16,
|
|
43
|
+
linkLocalPrefix: new Uint16Array([0xfe80]),
|
|
42
44
|
linkLocalPrefixLength: 64
|
|
43
45
|
};
|
|
44
46
|
|
|
@@ -253,7 +255,7 @@ export function normalizeCIDR(address) {
|
|
|
253
255
|
|
|
254
256
|
const family = isIPv6(prefix) ? ipv6 : ipv4;
|
|
255
257
|
|
|
256
|
-
if (isUniqueLocal(address) ||
|
|
258
|
+
if (isUniqueLocal(address) || _isLinkLocal(family, address)) {
|
|
257
259
|
prefixLength = family.linkLocalPrefixLength;
|
|
258
260
|
const n = _prefix(family, address, prefixLength);
|
|
259
261
|
prefix = _decode(family, n, prefixLength);
|
|
@@ -336,12 +338,22 @@ export function isLocalhost(address) {
|
|
|
336
338
|
}
|
|
337
339
|
|
|
338
340
|
export function isLinkLocal(address) {
|
|
339
|
-
const
|
|
340
|
-
if (
|
|
341
|
-
return
|
|
341
|
+
const family = _family(address);
|
|
342
|
+
if (!family) {
|
|
343
|
+
return false;
|
|
342
344
|
}
|
|
345
|
+
return _isLinkLocal(family, address);
|
|
346
|
+
}
|
|
343
347
|
|
|
344
|
-
|
|
348
|
+
export function _isLinkLocal(family, address) {
|
|
349
|
+
const eaddr = _encode(family, address);
|
|
350
|
+
let i = 0;
|
|
351
|
+
for (const slot of family.linkLocalPrefix) {
|
|
352
|
+
if (slot !== eaddr[i++]) {
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return true;
|
|
345
357
|
}
|
|
346
358
|
|
|
347
359
|
export function isUniqueLocal(address) {
|
package/types/ip.d.mts
CHANGED
|
@@ -42,6 +42,7 @@ export function normalizeIP(address: any): string | undefined;
|
|
|
42
42
|
export function reverseArpa(address: any): string;
|
|
43
43
|
export function isLocalhost(address: any): boolean;
|
|
44
44
|
export function isLinkLocal(address: any): boolean;
|
|
45
|
+
export function _isLinkLocal(family: any, address: any): boolean;
|
|
45
46
|
export function isUniqueLocal(address: any): boolean;
|
|
46
47
|
export function hasWellKnownSubnet(address: any): boolean;
|
|
47
48
|
/**
|