ip-utilties 3.3.0 → 3.4.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 +19 -18
- package/types/ip.d.mts +2 -2
package/package.json
CHANGED
package/src/ip.mjs
CHANGED
|
@@ -20,6 +20,7 @@ const ipv4 = {
|
|
|
20
20
|
base: 10,
|
|
21
21
|
linkLocalPrefix: new Uint8Array([169, 254]),
|
|
22
22
|
linkLocalPrefixLength: 16,
|
|
23
|
+
localHost: new Uint8Array([127, 0, 0, 1]),
|
|
23
24
|
localHostPrefixLenth: 8
|
|
24
25
|
};
|
|
25
26
|
|
|
@@ -43,6 +44,7 @@ const ipv6 = {
|
|
|
43
44
|
base: 16,
|
|
44
45
|
linkLocalPrefix: new Uint16Array([0xfe80]),
|
|
45
46
|
linkLocalPrefixLength: 64,
|
|
47
|
+
localHost: new Uint16Array([0, 0, 0, 0, 0, 0, 0, 1]),
|
|
46
48
|
localHostPrefixLenth: 128
|
|
47
49
|
};
|
|
48
50
|
|
|
@@ -329,16 +331,23 @@ export function reverseArpa(address) {
|
|
|
329
331
|
return address.split(".").reverse().join(".") + ".in-addr.arpa";
|
|
330
332
|
}
|
|
331
333
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
334
|
+
function _equal(a, b) {
|
|
335
|
+
let i = 0;
|
|
336
|
+
for (const slot of a) {
|
|
337
|
+
if (slot !== b[i++]) {
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
337
340
|
}
|
|
341
|
+
return true;
|
|
342
|
+
}
|
|
338
343
|
|
|
339
|
-
|
|
344
|
+
export function isLocalhost(address) {
|
|
345
|
+
const family = _family(address);
|
|
346
|
+
if (family) {
|
|
347
|
+
return _equal(family.localHost, _encode(family, address));
|
|
348
|
+
}
|
|
340
349
|
|
|
341
|
-
return
|
|
350
|
+
return false;
|
|
342
351
|
}
|
|
343
352
|
|
|
344
353
|
export function isLinkLocal(address) {
|
|
@@ -350,14 +359,7 @@ export function isLinkLocal(address) {
|
|
|
350
359
|
}
|
|
351
360
|
|
|
352
361
|
export function _isLinkLocal(family, address) {
|
|
353
|
-
|
|
354
|
-
let i = 0;
|
|
355
|
-
for (const slot of family.linkLocalPrefix) {
|
|
356
|
-
if (slot !== eaddr[i++]) {
|
|
357
|
-
return false;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
return true;
|
|
362
|
+
return _equal(family.linkLocalPrefix, _encode(family, address));
|
|
361
363
|
}
|
|
362
364
|
|
|
363
365
|
export function isUniqueLocal(address) {
|
|
@@ -386,7 +388,6 @@ export function hasWellKnownSubnet(address) {
|
|
|
386
388
|
::1 128. local host
|
|
387
389
|
127 8 local host
|
|
388
390
|
172
|
|
389
|
-
|
|
390
391
|
*/
|
|
391
392
|
|
|
392
393
|
/*
|
|
@@ -399,5 +400,5 @@ export const IPV6_LINK_LOCAL_ALL_ROUTERS = _encode(ipv6, "ff02::2");
|
|
|
399
400
|
export const IPV6_SITE_LOCAL_ALL_ROUTERS = _encode(ipv6, "ff05::2");
|
|
400
401
|
export const IPV6_SITE_LOCAL_ALL_DHCP_SERVERS = _encode(ipv6, "ff05::1:3");
|
|
401
402
|
|
|
402
|
-
export const IPV4_LOCALHOST =
|
|
403
|
-
export const IPV6_LOCALHOST =
|
|
403
|
+
export const IPV4_LOCALHOST = ipv4.localHost;
|
|
404
|
+
export const IPV6_LOCALHOST = ipv6.localHost;
|
package/types/ip.d.mts
CHANGED
|
@@ -59,5 +59,5 @@ export const IPV6_LINK_LOCAL_ALL_NODES: any;
|
|
|
59
59
|
export const IPV6_LINK_LOCAL_ALL_ROUTERS: any;
|
|
60
60
|
export const IPV6_SITE_LOCAL_ALL_ROUTERS: any;
|
|
61
61
|
export const IPV6_SITE_LOCAL_ALL_DHCP_SERVERS: any;
|
|
62
|
-
export const IPV4_LOCALHOST:
|
|
63
|
-
export const IPV6_LOCALHOST:
|
|
62
|
+
export const IPV4_LOCALHOST: Uint8Array<ArrayBuffer>;
|
|
63
|
+
export const IPV6_LOCALHOST: Uint16Array<ArrayBuffer>;
|