@ac-kit/net-address 0.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/CHANGELOG.md +46 -0
- package/LICENSE +28 -0
- package/README.md +65 -0
- package/dist/errors.d.ts +6 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +10 -0
- package/dist/errors.js.map +1 -0
- package/dist/eui/constants.d.ts +7 -0
- package/dist/eui/constants.d.ts.map +1 -0
- package/dist/eui/constants.js +7 -0
- package/dist/eui/constants.js.map +1 -0
- package/dist/eui/eui-bits.d.ts +99 -0
- package/dist/eui/eui-bits.d.ts.map +1 -0
- package/dist/eui/eui-bits.js +138 -0
- package/dist/eui/eui-bits.js.map +1 -0
- package/dist/eui/eui-convert.d.ts +37 -0
- package/dist/eui/eui-convert.d.ts.map +1 -0
- package/dist/eui/eui-convert.js +76 -0
- package/dist/eui/eui-convert.js.map +1 -0
- package/dist/eui/interface-identifier.d.ts +24 -0
- package/dist/eui/interface-identifier.d.ts.map +1 -0
- package/dist/eui/interface-identifier.js +47 -0
- package/dist/eui/interface-identifier.js.map +1 -0
- package/dist/eui/parse-eui.d.ts +31 -0
- package/dist/eui/parse-eui.d.ts.map +1 -0
- package/dist/eui/parse-eui.js +93 -0
- package/dist/eui/parse-eui.js.map +1 -0
- package/dist/eui/print-eui.d.ts +44 -0
- package/dist/eui/print-eui.d.ts.map +1 -0
- package/dist/eui/print-eui.js +64 -0
- package/dist/eui/print-eui.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/ipv4/classify-ipv4.d.ts +69 -0
- package/dist/ipv4/classify-ipv4.d.ts.map +1 -0
- package/dist/ipv4/classify-ipv4.js +129 -0
- package/dist/ipv4/classify-ipv4.js.map +1 -0
- package/dist/ipv4/constants.d.ts +5 -0
- package/dist/ipv4/constants.d.ts.map +1 -0
- package/dist/ipv4/constants.js +5 -0
- package/dist/ipv4/constants.js.map +1 -0
- package/dist/ipv4/ipv4-prefix.d.ts +52 -0
- package/dist/ipv4/ipv4-prefix.d.ts.map +1 -0
- package/dist/ipv4/ipv4-prefix.js +81 -0
- package/dist/ipv4/ipv4-prefix.js.map +1 -0
- package/dist/ipv4/parse-ipv4.d.ts +49 -0
- package/dist/ipv4/parse-ipv4.d.ts.map +1 -0
- package/dist/ipv4/parse-ipv4.js +169 -0
- package/dist/ipv4/parse-ipv4.js.map +1 -0
- package/dist/ipv4/print-ipv4.d.ts +50 -0
- package/dist/ipv4/print-ipv4.d.ts.map +1 -0
- package/dist/ipv4/print-ipv4.js +76 -0
- package/dist/ipv4/print-ipv4.js.map +1 -0
- package/dist/ipv6/classify-ipv6.d.ts +79 -0
- package/dist/ipv6/classify-ipv6.d.ts.map +1 -0
- package/dist/ipv6/classify-ipv6.js +148 -0
- package/dist/ipv6/classify-ipv6.js.map +1 -0
- package/dist/ipv6/constants.d.ts +5 -0
- package/dist/ipv6/constants.d.ts.map +1 -0
- package/dist/ipv6/constants.js +5 -0
- package/dist/ipv6/constants.js.map +1 -0
- package/dist/ipv6/ipv4-mapped.d.ts +43 -0
- package/dist/ipv6/ipv4-mapped.d.ts.map +1 -0
- package/dist/ipv6/ipv4-mapped.js +65 -0
- package/dist/ipv6/ipv4-mapped.js.map +1 -0
- package/dist/ipv6/ipv6-prefix.d.ts +51 -0
- package/dist/ipv6/ipv6-prefix.d.ts.map +1 -0
- package/dist/ipv6/ipv6-prefix.js +78 -0
- package/dist/ipv6/ipv6-prefix.js.map +1 -0
- package/dist/ipv6/parse-ipv6.d.ts +50 -0
- package/dist/ipv6/parse-ipv6.d.ts.map +1 -0
- package/dist/ipv6/parse-ipv6.js +148 -0
- package/dist/ipv6/parse-ipv6.js.map +1 -0
- package/dist/ipv6/print-ipv6.d.ts +37 -0
- package/dist/ipv6/print-ipv6.d.ts.map +1 -0
- package/dist/ipv6/print-ipv6.js +93 -0
- package/dist/ipv6/print-ipv6.js.map +1 -0
- package/dist/port/endpoint.d.ts +47 -0
- package/dist/port/endpoint.d.ts.map +1 -0
- package/dist/port/endpoint.js +104 -0
- package/dist/port/endpoint.js.map +1 -0
- package/dist/port/ephemeral-port.d.ts +17 -0
- package/dist/port/ephemeral-port.d.ts.map +1 -0
- package/dist/port/ephemeral-port.js +26 -0
- package/dist/port/ephemeral-port.js.map +1 -0
- package/dist/port/port.d.ts +69 -0
- package/dist/port/port.d.ts.map +1 -0
- package/dist/port/port.js +94 -0
- package/dist/port/port.js.map +1 -0
- package/dist/prefix/_numeric-range.d.ts +23 -0
- package/dist/prefix/_numeric-range.d.ts.map +1 -0
- package/dist/prefix/_numeric-range.js +57 -0
- package/dist/prefix/_numeric-range.js.map +1 -0
- package/dist/prefix/_prefix-length.d.ts +7 -0
- package/dist/prefix/_prefix-length.d.ts.map +1 -0
- package/dist/prefix/_prefix-length.js +13 -0
- package/dist/prefix/_prefix-length.js.map +1 -0
- package/dist/prefix/aggregate.d.ts +45 -0
- package/dist/prefix/aggregate.d.ts.map +1 -0
- package/dist/prefix/aggregate.js +97 -0
- package/dist/prefix/aggregate.js.map +1 -0
- package/dist/prefix/bit-address.d.ts +110 -0
- package/dist/prefix/bit-address.d.ts.map +1 -0
- package/dist/prefix/bit-address.js +165 -0
- package/dist/prefix/bit-address.js.map +1 -0
- package/dist/prefix/bit-prefix.d.ts +79 -0
- package/dist/prefix/bit-prefix.d.ts.map +1 -0
- package/dist/prefix/bit-prefix.js +135 -0
- package/dist/prefix/bit-prefix.js.map +1 -0
- package/dist/prefix/bit-range.d.ts +49 -0
- package/dist/prefix/bit-range.d.ts.map +1 -0
- package/dist/prefix/bit-range.js +100 -0
- package/dist/prefix/bit-range.js.map +1 -0
- package/dist/prefix/compare.d.ts +21 -0
- package/dist/prefix/compare.d.ts.map +1 -0
- package/dist/prefix/compare.js +33 -0
- package/dist/prefix/compare.js.map +1 -0
- package/dist/prefix/mask.d.ts +26 -0
- package/dist/prefix/mask.d.ts.map +1 -0
- package/dist/prefix/mask.js +48 -0
- package/dist/prefix/mask.js.map +1 -0
- package/dist/prefix/set-ops.d.ts +38 -0
- package/dist/prefix/set-ops.d.ts.map +1 -0
- package/dist/prefix/set-ops.js +71 -0
- package/dist/prefix/set-ops.js.map +1 -0
- package/package.json +66 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# @ac-kit/net-address
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a5c4d66: New package: IPv4, IPv6, EUI-48/EUI-64 and ports over one shared fixed-width
|
|
8
|
+
prefix core.
|
|
9
|
+
|
|
10
|
+
All four are bit strings of a known width with several textual forms, prefix and
|
|
11
|
+
mask semantics, and registry-based classification — an OUI is the first 24 bits
|
|
12
|
+
of a MAC address exactly as `/24` is the first 24 bits of an IPv4 address. One
|
|
13
|
+
value-plus-width representation therefore carries `/32`, `/128`, `/48` and
|
|
14
|
+
`/64` alike, and each address kind adds only its own syntax and its own
|
|
15
|
+
registry. That shared core is what makes this one package rather than three.
|
|
16
|
+
|
|
17
|
+
`BitAddress` is `{ value: bigint; bitWidth: number }`: an address is an unsigned
|
|
18
|
+
integer of a width it cannot supply itself, so `255.255.255.255` is
|
|
19
|
+
`4294967295n` and never `-1n`. `bitAddressFromBytes` and `bitAddressToBytes` are
|
|
20
|
+
the octet boundary, for wire formats and anything else that speaks bytes.
|
|
21
|
+
|
|
22
|
+
Parsing is strict by default, and that is a security property rather than
|
|
23
|
+
pedantry. `0177.0.0.1`, `0x7f.0.0.1`, `127.1` and `2130706433` are all rejected
|
|
24
|
+
by `parseIpv4Address`, including where they hide inside an IPv6 literal, because
|
|
25
|
+
inconsistent IPv4 parsing is how an SSRF allowlist gets bypassed: a check that
|
|
26
|
+
reads one of those as "not 127.something" hands it to a resolver that reads it
|
|
27
|
+
as loopback. The legacy `inet_aton` grammar is still reachable, under a name
|
|
28
|
+
nobody arrives at by accident, so a guard can also prove what a hostile string
|
|
29
|
+
would resolve to under the lenient reading.
|
|
30
|
+
|
|
31
|
+
`getRandomEphemeralPort`, `EPHEMERAL_PORT_MIN_VALUE` and
|
|
32
|
+
`EPHEMERAL_PORT_MAX_VALUE` move here from `@ac-kit/core`, beside the rest of the
|
|
33
|
+
RFC 6335 port semantics.
|
|
34
|
+
|
|
35
|
+
Depends on `@ac-kit/math-numbers` for the fixed-width integer arithmetic behind
|
|
36
|
+
the prefix core.
|
|
37
|
+
|
|
38
|
+
### Patch Changes
|
|
39
|
+
|
|
40
|
+
- Updated dependencies [a5c4d66]
|
|
41
|
+
- Updated dependencies [a5c4d66]
|
|
42
|
+
- Updated dependencies [a5c4d66]
|
|
43
|
+
- Updated dependencies [a5c4d66]
|
|
44
|
+
- @ac-kit/algo@0.2.0
|
|
45
|
+
- @ac-kit/math-numbers@0.2.0
|
|
46
|
+
- @ac-kit/core@0.3.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 Anthony Champagne and contributors
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# @ac-kit/net-address
|
|
2
|
+
|
|
3
|
+
IPv4, IPv6, EUI-48/EUI-64 and ports — over one shared fixed-width prefix core.
|
|
4
|
+
|
|
5
|
+
All four are bit strings of a known width with several textual forms, prefix and
|
|
6
|
+
mask semantics, and registry-based classification. An OUI is the first 24 bits
|
|
7
|
+
of a MAC address exactly as `/24` is the first 24 bits of an IPv4 address, so
|
|
8
|
+
one value-plus-width representation carries `/32`, `/128`, `/48` and `/64`
|
|
9
|
+
alike, and each address kind adds only what is its own.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import {
|
|
13
|
+
aggregateBitPrefixes,
|
|
14
|
+
classifyIpv4Address,
|
|
15
|
+
parseIpv4Address,
|
|
16
|
+
parseIpv4Prefix,
|
|
17
|
+
parseIpv6Address,
|
|
18
|
+
printIpv4Prefix,
|
|
19
|
+
printIpv6Address,
|
|
20
|
+
} from "@ac-kit/net-address";
|
|
21
|
+
|
|
22
|
+
classifyIpv4Address(parseIpv4Address("169.254.169.254")); // "link-local"
|
|
23
|
+
printIpv6Address(parseIpv6Address("2001:0DB8:0:0:0:0:2:1")); // "2001:db8::2:1"
|
|
24
|
+
|
|
25
|
+
aggregateBitPrefixes([
|
|
26
|
+
parseIpv4Prefix("10.0.0.0/25"),
|
|
27
|
+
parseIpv4Prefix("10.0.0.128/25"),
|
|
28
|
+
]).map(printIpv4Prefix); // ["10.0.0.0/24"]
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Parsing is strict by default
|
|
32
|
+
|
|
33
|
+
`parseIpv4Address` takes four decimal octets and nothing else. `0177.0.0.1`,
|
|
34
|
+
`0x7f.0.0.1`, `127.1` and `2130706433` are all rejected, and an IPv4 part
|
|
35
|
+
embedded in an IPv6 literal is held to the same rule.
|
|
36
|
+
|
|
37
|
+
This is a security property, not pedantry. Inconsistent IPv4 parsing is the
|
|
38
|
+
classic SSRF allowlist bypass: a check that reads `0177.0.0.1` as "not
|
|
39
|
+
127.something" hands it to a C resolver that reads it as loopback. A parser that
|
|
40
|
+
refuses the ambiguous forms cannot disagree with the next hop.
|
|
41
|
+
|
|
42
|
+
The legacy grammar is still available, under a name you cannot reach by
|
|
43
|
+
accident: `parseInetAtonIpv4Address` implements what C's `inet_aton` accepts, so
|
|
44
|
+
a guard can prove a hostile string resolves to a blocked address under the
|
|
45
|
+
lenient reading too. Never validate an allowlist with it.
|
|
46
|
+
|
|
47
|
+
The same reasoning runs through the rest of the package. `parsePort` rejects
|
|
48
|
+
`080`. `parseEndpoint` refuses an unbracketed IPv6 literal, because `::1:8080`
|
|
49
|
+
has no single reading. An all-digit host such as `2130706433` stays a *name*,
|
|
50
|
+
since only a resolver can say what it points at — classify what the resolver
|
|
51
|
+
returns, never the string.
|
|
52
|
+
|
|
53
|
+
## Printing is canonical
|
|
54
|
+
|
|
55
|
+
`printIpv6Address` produces the RFC 5952 form: lowercase, leading zeros
|
|
56
|
+
suppressed, the longest run of zero groups compressed to `::` — leftmost on a
|
|
57
|
+
tie, never for a single group — and IPv4-mapped addresses in dotted form.
|
|
58
|
+
|
|
59
|
+
`printEui` has no default notation or case, because there is no neutral choice:
|
|
60
|
+
IEEE Std 802 writes `00-1A-2B-3C-4D-5E` and RFC 7042 writes
|
|
61
|
+
`00:1a:2b:3c:4d:5e`. `EUI_PRINT_IEEE` and `EUI_PRINT_IETF` name the two.
|
|
62
|
+
|
|
63
|
+
See the
|
|
64
|
+
[generated API docs](https://anthochamp.github.io/node-essentials/api/net-address/)
|
|
65
|
+
for the full reference.
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,qBAAa,qBAAsB,SAAQ,WAAW;IAEpD,QAAQ,CAAC,MAAM,EAAE,MAAM;IADxB,YACU,MAAM,EAAE,MAAM,EACvB,MAAM,EAAE,MAAM,EAId;CACD"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Text that is not a well-formed address, prefix, range or endpoint. */
|
|
2
|
+
export class NetAddressSyntaxError extends SyntaxError {
|
|
3
|
+
source;
|
|
4
|
+
constructor(source, detail) {
|
|
5
|
+
super(`${detail} in ${JSON.stringify(source)}`);
|
|
6
|
+
this.source = source;
|
|
7
|
+
this.name = "NetAddressSyntaxError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,MAAM,OAAO,qBAAsB,SAAQ,WAAW;IAE3C,MAAM;IADhB,YACU,MAAc,EACvB,MAAc;QAEd,KAAK,CAAC,GAAG,MAAM,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;sBAHvC,MAAM;QAIf,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACrC,CAAC;CACD"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** EUI-48 — the MAC address of IEEE 802 — is 48 bits wide. */
|
|
2
|
+
export declare const EUI48_BIT_WIDTH = 48;
|
|
3
|
+
/** EUI-64 is 64 bits wide. */
|
|
4
|
+
export declare const EUI64_BIT_WIDTH = 64;
|
|
5
|
+
/** An OUI is the leading 24 bits of an EUI. */
|
|
6
|
+
export declare const OUI_BIT_LENGTH = 24;
|
|
7
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/eui/constants.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,eAAO,MAAM,eAAe,KAAK,CAAC;AAElC,8BAA8B;AAC9B,eAAO,MAAM,eAAe,KAAK,CAAC;AAElC,+CAA+C;AAC/C,eAAO,MAAM,cAAc,KAAK,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** EUI-48 — the MAC address of IEEE 802 — is 48 bits wide. */
|
|
2
|
+
export const EUI48_BIT_WIDTH = 48;
|
|
3
|
+
/** EUI-64 is 64 bits wide. */
|
|
4
|
+
export const EUI64_BIT_WIDTH = 64;
|
|
5
|
+
/** An OUI is the leading 24 bits of an EUI. */
|
|
6
|
+
export const OUI_BIT_LENGTH = 24;
|
|
7
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/eui/constants.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AAElC,8BAA8B;AAC9B,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AAElC,+CAA+C;AAC/C,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { type BitAddress } from "../prefix/bit-address.js";
|
|
2
|
+
import { type BitPrefix } from "../prefix/bit-prefix.js";
|
|
3
|
+
/** `ff:ff:ff:ff:ff:ff` — the EUI-48 broadcast address. */
|
|
4
|
+
export declare const EUI48_BROADCAST_ADDRESS: BitAddress;
|
|
5
|
+
/** `00:00:00:00:00:00` — the EUI-48 null address. */
|
|
6
|
+
export declare const EUI48_NULL_ADDRESS: BitAddress;
|
|
7
|
+
/** `ff:ff:ff:ff:ff:ff:ff:ff` — the EUI-64 broadcast address. */
|
|
8
|
+
export declare const EUI64_BROADCAST_ADDRESS: BitAddress;
|
|
9
|
+
/** `00:00:00:00:00:00:00:00` — the EUI-64 null address. */
|
|
10
|
+
export declare const EUI64_NULL_ADDRESS: BitAddress;
|
|
11
|
+
/** Which IEEE registry block an assignment came from, and how wide it is. */
|
|
12
|
+
export type EuiAssignmentBlock = "ma-l" | "ma-m" | "ma-s";
|
|
13
|
+
/**
|
|
14
|
+
* How many leading bits the IEEE assigns for each registry block.
|
|
15
|
+
*
|
|
16
|
+
* MA-L leaves 24 bits to the assignee, MA-M 20 and MA-S 12 — which is why a
|
|
17
|
+
* small vendor buys an MA-S and a network card maker buys an MA-L.
|
|
18
|
+
*/
|
|
19
|
+
export declare const EUI_ASSIGNMENT_BLOCK_BIT_LENGTHS: Readonly<Record<EuiAssignmentBlock, number>>;
|
|
20
|
+
/**
|
|
21
|
+
* Whether the I/G bit is set — a group (multicast) address rather than an
|
|
22
|
+
* individual one. It is the least significant bit of the first octet.
|
|
23
|
+
*
|
|
24
|
+
* @throws RangeError When the address is neither 48 nor 64 bits wide.
|
|
25
|
+
*/
|
|
26
|
+
export declare function isEuiGroup(address: BitAddress): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Whether the address names a single interface.
|
|
29
|
+
*
|
|
30
|
+
* @throws RangeError When the address is neither 48 nor 64 bits wide.
|
|
31
|
+
*/
|
|
32
|
+
export declare function isEuiIndividual(address: BitAddress): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Whether the U/L bit is set — a locally administered address rather than one
|
|
35
|
+
* from an IEEE registry. It is the second-least significant bit of the first
|
|
36
|
+
* octet.
|
|
37
|
+
*
|
|
38
|
+
* @throws RangeError When the address is neither 48 nor 64 bits wide.
|
|
39
|
+
*/
|
|
40
|
+
export declare function isEuiLocal(address: BitAddress): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Whether the address came from an IEEE registry.
|
|
43
|
+
*
|
|
44
|
+
* @throws RangeError When the address is neither 48 nor 64 bits wide.
|
|
45
|
+
*/
|
|
46
|
+
export declare function isEuiUniversal(address: BitAddress): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* The leading 24 bits as an integer — the OUI of a universally administered
|
|
49
|
+
* address, or the CID of a locally administered one.
|
|
50
|
+
*
|
|
51
|
+
* @throws RangeError When the address is neither 48 nor 64 bits wide.
|
|
52
|
+
*/
|
|
53
|
+
export declare function euiOui(address: BitAddress): number;
|
|
54
|
+
/**
|
|
55
|
+
* Whether the leading 24 bits are a Company ID rather than an OUI: the IEEE
|
|
56
|
+
* issues a CID with the U/L bit set and the I/G bit clear, so a CID-derived
|
|
57
|
+
* address can never be confused with a registry assignment.
|
|
58
|
+
*
|
|
59
|
+
* @throws RangeError When the address is neither 48 nor 64 bits wide.
|
|
60
|
+
*/
|
|
61
|
+
export declare function isEuiCid(address: BitAddress): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* The Company ID of a locally administered individual address.
|
|
64
|
+
*
|
|
65
|
+
* @returns `null` when the address carries an OUI instead.
|
|
66
|
+
* @throws RangeError When the address is neither 48 nor 64 bits wide.
|
|
67
|
+
*/
|
|
68
|
+
export declare function euiCid(address: BitAddress): number | null;
|
|
69
|
+
/**
|
|
70
|
+
* The address's OUI as a 24-bit prefix over the same width, so it can be
|
|
71
|
+
* compared with `bitPrefixContains` against other addresses.
|
|
72
|
+
*
|
|
73
|
+
* @throws RangeError When the address is neither 48 nor 64 bits wide.
|
|
74
|
+
*/
|
|
75
|
+
export declare function euiOuiPrefix(address: BitAddress): BitPrefix;
|
|
76
|
+
/**
|
|
77
|
+
* The block an IEEE assignment occupies, as a prefix over the same width: 24
|
|
78
|
+
* bits for MA-L, 28 for MA-M, 36 for MA-S.
|
|
79
|
+
*
|
|
80
|
+
* Which block an address actually belongs to is only knowable from the IEEE
|
|
81
|
+
* registry, which this package deliberately does not carry — the caller says
|
|
82
|
+
* which block it is looking up.
|
|
83
|
+
*
|
|
84
|
+
* @throws RangeError When the address is neither 48 nor 64 bits wide.
|
|
85
|
+
*/
|
|
86
|
+
export declare function euiAssignmentPrefix(address: BitAddress, block: EuiAssignmentBlock): BitPrefix;
|
|
87
|
+
/**
|
|
88
|
+
* Whether every bit is set — the broadcast address of its width.
|
|
89
|
+
*
|
|
90
|
+
* @throws RangeError When the address is neither 48 nor 64 bits wide.
|
|
91
|
+
*/
|
|
92
|
+
export declare function isEuiBroadcast(address: BitAddress): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Whether every bit is clear — the null address of its width.
|
|
95
|
+
*
|
|
96
|
+
* @throws RangeError When the address is neither 48 nor 64 bits wide.
|
|
97
|
+
*/
|
|
98
|
+
export declare function isEuiNull(address: BitAddress): boolean;
|
|
99
|
+
//# sourceMappingURL=eui-bits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eui-bits.d.ts","sourceRoot":"","sources":["../../src/eui/eui-bits.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,UAAU,EAIf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,KAAK,SAAS,EAAmB,MAAM,yBAAyB,CAAC;AAQ1E,0DAA0D;AAC1D,eAAO,MAAM,uBAAuB,EAAE,UACN,CAAC;AAEjC,qDAAqD;AACrD,eAAO,MAAM,kBAAkB,EAAE,UAA4C,CAAC;AAE9E,gEAAgE;AAChE,eAAO,MAAM,uBAAuB,EAAE,UAErC,CAAC;AAEF,2DAA2D;AAC3D,eAAO,MAAM,kBAAkB,EAAE,UAEhC,CAAC;AAEF,6EAA6E;AAC7E,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAE1D;;;;;GAKG;AACH,eAAO,MAAM,gCAAgC,EAAE,QAAQ,CACtD,MAAM,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAKlC,CAAC;AAaF;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAIvD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAE5D;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAIvD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAE3D;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,CAIlD;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAErD;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAEzD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,UAAU,GAAG,SAAS,CAI3D;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAClC,OAAO,EAAE,UAAU,EACnB,KAAK,EAAE,kBAAkB,GACvB,SAAS,CAIX;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAI3D;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAItD"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { bitAddressBitAt, bitAddressIsAllOnes, bitAddressIsZero, } from "../prefix/bit-address.js";
|
|
2
|
+
import { createBitPrefix } from "../prefix/bit-prefix.js";
|
|
3
|
+
import { EUI48_BIT_WIDTH, EUI64_BIT_WIDTH, OUI_BIT_LENGTH, } from "./constants.js";
|
|
4
|
+
import { parseEui48, parseEui64 } from "./parse-eui.js";
|
|
5
|
+
/** `ff:ff:ff:ff:ff:ff` — the EUI-48 broadcast address. */
|
|
6
|
+
export const EUI48_BROADCAST_ADDRESS = parseEui48("ff:ff:ff:ff:ff:ff");
|
|
7
|
+
/** `00:00:00:00:00:00` — the EUI-48 null address. */
|
|
8
|
+
export const EUI48_NULL_ADDRESS = parseEui48("00:00:00:00:00:00");
|
|
9
|
+
/** `ff:ff:ff:ff:ff:ff:ff:ff` — the EUI-64 broadcast address. */
|
|
10
|
+
export const EUI64_BROADCAST_ADDRESS = parseEui64("ff:ff:ff:ff:ff:ff:ff:ff");
|
|
11
|
+
/** `00:00:00:00:00:00:00:00` — the EUI-64 null address. */
|
|
12
|
+
export const EUI64_NULL_ADDRESS = parseEui64("00:00:00:00:00:00:00:00");
|
|
13
|
+
/**
|
|
14
|
+
* How many leading bits the IEEE assigns for each registry block.
|
|
15
|
+
*
|
|
16
|
+
* MA-L leaves 24 bits to the assignee, MA-M 20 and MA-S 12 — which is why a
|
|
17
|
+
* small vendor buys an MA-S and a network card maker buys an MA-L.
|
|
18
|
+
*/
|
|
19
|
+
export const EUI_ASSIGNMENT_BLOCK_BIT_LENGTHS = {
|
|
20
|
+
"ma-l": 24,
|
|
21
|
+
"ma-m": 28,
|
|
22
|
+
"ma-s": 36,
|
|
23
|
+
};
|
|
24
|
+
function assertEuiWidth(address) {
|
|
25
|
+
if (address.bitWidth !== EUI48_BIT_WIDTH &&
|
|
26
|
+
address.bitWidth !== EUI64_BIT_WIDTH) {
|
|
27
|
+
throw new RangeError(`expected a 48- or 64-bit EUI, got ${address.bitWidth} bits`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Whether the I/G bit is set — a group (multicast) address rather than an
|
|
32
|
+
* individual one. It is the least significant bit of the first octet.
|
|
33
|
+
*
|
|
34
|
+
* @throws RangeError When the address is neither 48 nor 64 bits wide.
|
|
35
|
+
*/
|
|
36
|
+
export function isEuiGroup(address) {
|
|
37
|
+
assertEuiWidth(address);
|
|
38
|
+
return bitAddressBitAt(address, 7) === 1;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Whether the address names a single interface.
|
|
42
|
+
*
|
|
43
|
+
* @throws RangeError When the address is neither 48 nor 64 bits wide.
|
|
44
|
+
*/
|
|
45
|
+
export function isEuiIndividual(address) {
|
|
46
|
+
return !isEuiGroup(address);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Whether the U/L bit is set — a locally administered address rather than one
|
|
50
|
+
* from an IEEE registry. It is the second-least significant bit of the first
|
|
51
|
+
* octet.
|
|
52
|
+
*
|
|
53
|
+
* @throws RangeError When the address is neither 48 nor 64 bits wide.
|
|
54
|
+
*/
|
|
55
|
+
export function isEuiLocal(address) {
|
|
56
|
+
assertEuiWidth(address);
|
|
57
|
+
return bitAddressBitAt(address, 6) === 1;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Whether the address came from an IEEE registry.
|
|
61
|
+
*
|
|
62
|
+
* @throws RangeError When the address is neither 48 nor 64 bits wide.
|
|
63
|
+
*/
|
|
64
|
+
export function isEuiUniversal(address) {
|
|
65
|
+
return !isEuiLocal(address);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The leading 24 bits as an integer — the OUI of a universally administered
|
|
69
|
+
* address, or the CID of a locally administered one.
|
|
70
|
+
*
|
|
71
|
+
* @throws RangeError When the address is neither 48 nor 64 bits wide.
|
|
72
|
+
*/
|
|
73
|
+
export function euiOui(address) {
|
|
74
|
+
assertEuiWidth(address);
|
|
75
|
+
return Number(address.value >> BigInt(address.bitWidth - OUI_BIT_LENGTH));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Whether the leading 24 bits are a Company ID rather than an OUI: the IEEE
|
|
79
|
+
* issues a CID with the U/L bit set and the I/G bit clear, so a CID-derived
|
|
80
|
+
* address can never be confused with a registry assignment.
|
|
81
|
+
*
|
|
82
|
+
* @throws RangeError When the address is neither 48 nor 64 bits wide.
|
|
83
|
+
*/
|
|
84
|
+
export function isEuiCid(address) {
|
|
85
|
+
return isEuiLocal(address) && isEuiIndividual(address);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The Company ID of a locally administered individual address.
|
|
89
|
+
*
|
|
90
|
+
* @returns `null` when the address carries an OUI instead.
|
|
91
|
+
* @throws RangeError When the address is neither 48 nor 64 bits wide.
|
|
92
|
+
*/
|
|
93
|
+
export function euiCid(address) {
|
|
94
|
+
return isEuiCid(address) ? euiOui(address) : null;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The address's OUI as a 24-bit prefix over the same width, so it can be
|
|
98
|
+
* compared with `bitPrefixContains` against other addresses.
|
|
99
|
+
*
|
|
100
|
+
* @throws RangeError When the address is neither 48 nor 64 bits wide.
|
|
101
|
+
*/
|
|
102
|
+
export function euiOuiPrefix(address) {
|
|
103
|
+
assertEuiWidth(address);
|
|
104
|
+
return createBitPrefix(address, OUI_BIT_LENGTH);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The block an IEEE assignment occupies, as a prefix over the same width: 24
|
|
108
|
+
* bits for MA-L, 28 for MA-M, 36 for MA-S.
|
|
109
|
+
*
|
|
110
|
+
* Which block an address actually belongs to is only knowable from the IEEE
|
|
111
|
+
* registry, which this package deliberately does not carry — the caller says
|
|
112
|
+
* which block it is looking up.
|
|
113
|
+
*
|
|
114
|
+
* @throws RangeError When the address is neither 48 nor 64 bits wide.
|
|
115
|
+
*/
|
|
116
|
+
export function euiAssignmentPrefix(address, block) {
|
|
117
|
+
assertEuiWidth(address);
|
|
118
|
+
return createBitPrefix(address, EUI_ASSIGNMENT_BLOCK_BIT_LENGTHS[block]);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Whether every bit is set — the broadcast address of its width.
|
|
122
|
+
*
|
|
123
|
+
* @throws RangeError When the address is neither 48 nor 64 bits wide.
|
|
124
|
+
*/
|
|
125
|
+
export function isEuiBroadcast(address) {
|
|
126
|
+
assertEuiWidth(address);
|
|
127
|
+
return bitAddressIsAllOnes(address);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Whether every bit is clear — the null address of its width.
|
|
131
|
+
*
|
|
132
|
+
* @throws RangeError When the address is neither 48 nor 64 bits wide.
|
|
133
|
+
*/
|
|
134
|
+
export function isEuiNull(address) {
|
|
135
|
+
assertEuiWidth(address);
|
|
136
|
+
return bitAddressIsZero(address);
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=eui-bits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eui-bits.js","sourceRoot":"","sources":["../../src/eui/eui-bits.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { BitAddress } from "../prefix/bit-address.js";
|
|
2
|
+
/**
|
|
3
|
+
* Widens an EUI-48 to an EUI-64 by inserting `FF:FE` between the 24-bit company
|
|
4
|
+
* identifier and the 24-bit extension identifier, per IEEE's tutorial on the
|
|
5
|
+
* two formats.
|
|
6
|
+
*
|
|
7
|
+
* The U/L bit is left alone. Flipping it is part of building an IPv6 interface
|
|
8
|
+
* identifier, not part of the EUI conversion — see
|
|
9
|
+
* `euiToIpv6InterfaceIdentifier`.
|
|
10
|
+
*
|
|
11
|
+
* @throws RangeError When the address is not 48 bits wide.
|
|
12
|
+
*/
|
|
13
|
+
export declare function eui48ToEui64(address: BitAddress): BitAddress;
|
|
14
|
+
/**
|
|
15
|
+
* Whether an EUI-64 carries the `FF:FE` marker that {@link eui48ToEui64}
|
|
16
|
+
* inserts, and so can be narrowed back.
|
|
17
|
+
*
|
|
18
|
+
* @throws RangeError When the address is not 64 bits wide.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isEui64FromEui48(address: BitAddress): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Narrows an EUI-64 back to the EUI-48 it was widened from, dropping the
|
|
23
|
+
* `FF:FE` marker.
|
|
24
|
+
*
|
|
25
|
+
* @returns `null` when the address carries no marker, which means it is a
|
|
26
|
+
* native EUI-64 and has no 48-bit form.
|
|
27
|
+
* @throws RangeError When the address is not 64 bits wide.
|
|
28
|
+
*/
|
|
29
|
+
export declare function tryEui64ToEui48(address: BitAddress): BitAddress | null;
|
|
30
|
+
/**
|
|
31
|
+
* {@link tryEui64ToEui48}, throwing instead of answering `null`.
|
|
32
|
+
*
|
|
33
|
+
* @throws RangeError When the address is not 64 bits wide, or carries no
|
|
34
|
+
* `FF:FE` marker.
|
|
35
|
+
*/
|
|
36
|
+
export declare function eui64ToEui48(address: BitAddress): BitAddress;
|
|
37
|
+
//# sourceMappingURL=eui-convert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eui-convert.d.ts","sourceRoot":"","sources":["../../src/eui/eui-convert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAe3D;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,UAAU,GAAG,UAAU,CAe5D;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAM7D;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,UAAU,GAAG,UAAU,GAAG,IAAI,CAYtE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,UAAU,GAAG,UAAU,CAQ5D"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { EUI48_BIT_WIDTH, EUI64_BIT_WIDTH, OUI_BIT_LENGTH, } from "./constants.js";
|
|
2
|
+
/** The 24 bits below the OUI, in either width. */
|
|
3
|
+
const EXTENSION_MASK = (1n << BigInt(OUI_BIT_LENGTH)) - 1n;
|
|
4
|
+
/** `FF:FE`, and the 16 bits it occupies between the two identifiers. */
|
|
5
|
+
const MARKER = 0xfffen;
|
|
6
|
+
const MARKER_BIT_LENGTH = 16;
|
|
7
|
+
const MARKER_MASK = (1n << BigInt(MARKER_BIT_LENGTH)) - 1n;
|
|
8
|
+
/**
|
|
9
|
+
* Widens an EUI-48 to an EUI-64 by inserting `FF:FE` between the 24-bit company
|
|
10
|
+
* identifier and the 24-bit extension identifier, per IEEE's tutorial on the
|
|
11
|
+
* two formats.
|
|
12
|
+
*
|
|
13
|
+
* The U/L bit is left alone. Flipping it is part of building an IPv6 interface
|
|
14
|
+
* identifier, not part of the EUI conversion — see
|
|
15
|
+
* `euiToIpv6InterfaceIdentifier`.
|
|
16
|
+
*
|
|
17
|
+
* @throws RangeError When the address is not 48 bits wide.
|
|
18
|
+
*/
|
|
19
|
+
export function eui48ToEui64(address) {
|
|
20
|
+
if (address.bitWidth !== EUI48_BIT_WIDTH) {
|
|
21
|
+
throw new RangeError(`expected a 48-bit EUI, got ${address.bitWidth} bits`);
|
|
22
|
+
}
|
|
23
|
+
const oui = address.value >> BigInt(OUI_BIT_LENGTH);
|
|
24
|
+
const extension = address.value & EXTENSION_MASK;
|
|
25
|
+
return {
|
|
26
|
+
value: (oui << BigInt(MARKER_BIT_LENGTH + OUI_BIT_LENGTH)) |
|
|
27
|
+
(MARKER << BigInt(OUI_BIT_LENGTH)) |
|
|
28
|
+
extension,
|
|
29
|
+
bitWidth: EUI64_BIT_WIDTH,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Whether an EUI-64 carries the `FF:FE` marker that {@link eui48ToEui64}
|
|
34
|
+
* inserts, and so can be narrowed back.
|
|
35
|
+
*
|
|
36
|
+
* @throws RangeError When the address is not 64 bits wide.
|
|
37
|
+
*/
|
|
38
|
+
export function isEui64FromEui48(address) {
|
|
39
|
+
if (address.bitWidth !== EUI64_BIT_WIDTH) {
|
|
40
|
+
throw new RangeError(`expected a 64-bit EUI, got ${address.bitWidth} bits`);
|
|
41
|
+
}
|
|
42
|
+
return ((address.value >> BigInt(OUI_BIT_LENGTH)) & MARKER_MASK) === MARKER;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Narrows an EUI-64 back to the EUI-48 it was widened from, dropping the
|
|
46
|
+
* `FF:FE` marker.
|
|
47
|
+
*
|
|
48
|
+
* @returns `null` when the address carries no marker, which means it is a
|
|
49
|
+
* native EUI-64 and has no 48-bit form.
|
|
50
|
+
* @throws RangeError When the address is not 64 bits wide.
|
|
51
|
+
*/
|
|
52
|
+
export function tryEui64ToEui48(address) {
|
|
53
|
+
if (!isEui64FromEui48(address)) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
const oui = address.value >> BigInt(MARKER_BIT_LENGTH + OUI_BIT_LENGTH);
|
|
57
|
+
const extension = address.value & EXTENSION_MASK;
|
|
58
|
+
return {
|
|
59
|
+
value: (oui << BigInt(OUI_BIT_LENGTH)) | extension,
|
|
60
|
+
bitWidth: EUI48_BIT_WIDTH,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* {@link tryEui64ToEui48}, throwing instead of answering `null`.
|
|
65
|
+
*
|
|
66
|
+
* @throws RangeError When the address is not 64 bits wide, or carries no
|
|
67
|
+
* `FF:FE` marker.
|
|
68
|
+
*/
|
|
69
|
+
export function eui64ToEui48(address) {
|
|
70
|
+
const narrowed = tryEui64ToEui48(address);
|
|
71
|
+
if (narrowed === null) {
|
|
72
|
+
throw new RangeError("EUI-64 does not encapsulate an EUI-48");
|
|
73
|
+
}
|
|
74
|
+
return narrowed;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=eui-convert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eui-convert.js","sourceRoot":"","sources":["../../src/eui/eui-convert.ts"],"names":[],"mappings":"AACA,OAAO,EACN,eAAe,EACf,eAAe,EACf,cAAc,GACd,MAAM,gBAAgB,CAAC;AAExB,kDAAkD;AAClD,MAAM,cAAc,GAAG,CAAC,EAAE,IAAI,MAAM,CAAC,cAAc,CAAC,CAAC,GAAG,EAAE,CAAC;AAE3D,wEAAwE;AACxE,MAAM,MAAM,GAAG,OAAO,CAAC;AACvB,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,MAAM,WAAW,GAAG,CAAC,EAAE,IAAI,MAAM,CAAC,iBAAiB,CAAC,CAAC,GAAG,EAAE,CAAC;AAE3D;;;;;;;;;;GAUG;AACH,MAAM,UAAU,YAAY,CAAC,OAAmB;IAC/C,IAAI,OAAO,CAAC,QAAQ,KAAK,eAAe,EAAE,CAAC;QAC1C,MAAM,IAAI,UAAU,CAAC,8BAA8B,OAAO,CAAC,QAAQ,OAAO,CAAC,CAAC;IAC7E,CAAC;IAED,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,IAAI,MAAM,CAAC,cAAc,CAAC,CAAC;IACpD,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,GAAG,cAAc,CAAC;IAEjD,OAAO;QACN,KAAK,EACJ,CAAC,GAAG,IAAI,MAAM,CAAC,iBAAiB,GAAG,cAAc,CAAC,CAAC;YACnD,CAAC,MAAM,IAAI,MAAM,CAAC,cAAc,CAAC,CAAC;YAClC,SAAS;QACV,QAAQ,EAAE,eAAe;KACzB,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAmB;IACnD,IAAI,OAAO,CAAC,QAAQ,KAAK,eAAe,EAAE,CAAC;QAC1C,MAAM,IAAI,UAAU,CAAC,8BAA8B,OAAO,CAAC,QAAQ,OAAO,CAAC,CAAC;IAC7E,CAAC;IAED,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,IAAI,MAAM,CAAC,cAAc,CAAC,CAAC,GAAG,WAAW,CAAC,KAAK,MAAM,CAAC;AAC7E,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,OAAmB;IAClD,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,IAAI,MAAM,CAAC,iBAAiB,GAAG,cAAc,CAAC,CAAC;IACxE,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,GAAG,cAAc,CAAC;IAEjD,OAAO;QACN,KAAK,EAAE,CAAC,GAAG,IAAI,MAAM,CAAC,cAAc,CAAC,CAAC,GAAG,SAAS;QAClD,QAAQ,EAAE,eAAe;KACzB,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,OAAmB;IAC/C,MAAM,QAAQ,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;IAE1C,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACvB,MAAM,IAAI,UAAU,CAAC,uCAAuC,CAAC,CAAC;IAC/D,CAAC;IAED,OAAO,QAAQ,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { BitAddress } from "../prefix/bit-address.js";
|
|
2
|
+
/** The IPv6 interface identifier occupies the low 64 bits of an address. */
|
|
3
|
+
export declare const IPV6_INTERFACE_IDENTIFIER_BIT_WIDTH = 64;
|
|
4
|
+
/**
|
|
5
|
+
* Builds the IPv6 interface identifier of RFC 4291 Appendix A.
|
|
6
|
+
*
|
|
7
|
+
* An EUI-48 is first widened with `FF:FE`; then — for either width — **the U/L
|
|
8
|
+
* bit is complemented**. That inversion is the step implementations skip: the
|
|
9
|
+
* identifier form spells "universal" as a one, the opposite of IEEE 802, so a
|
|
10
|
+
* universally administered `34-56-78-9A-BC-DE` yields `36-56-78-FF-FE-9A-BC-DE`
|
|
11
|
+
* and not `34-…`.
|
|
12
|
+
*
|
|
13
|
+
* @returns A 64-bit value.
|
|
14
|
+
* @throws RangeError When the address is neither 48 nor 64 bits wide.
|
|
15
|
+
*/
|
|
16
|
+
export declare function euiToIpv6InterfaceIdentifier(address: BitAddress): BitAddress;
|
|
17
|
+
/**
|
|
18
|
+
* The inverse of {@link euiToIpv6InterfaceIdentifier}: complements the U/L bit
|
|
19
|
+
* back, yielding the EUI-64 the identifier was built from.
|
|
20
|
+
*
|
|
21
|
+
* @throws RangeError When the identifier is not 64 bits wide.
|
|
22
|
+
*/
|
|
23
|
+
export declare function ipv6InterfaceIdentifierToEui64(identifier: BitAddress): BitAddress;
|
|
24
|
+
//# sourceMappingURL=interface-identifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface-identifier.d.ts","sourceRoot":"","sources":["../../src/eui/interface-identifier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAI3D,4EAA4E;AAC5E,eAAO,MAAM,mCAAmC,KAAK,CAAC;AActD;;;;;;;;;;;GAWG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,UAAU,GAAG,UAAU,CAY5E;AAED;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAC7C,UAAU,EAAE,UAAU,GACpB,UAAU,CAQZ"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { EUI48_BIT_WIDTH, EUI64_BIT_WIDTH } from "./constants.js";
|
|
2
|
+
import { eui48ToEui64 } from "./eui-convert.js";
|
|
3
|
+
/** The IPv6 interface identifier occupies the low 64 bits of an address. */
|
|
4
|
+
export const IPV6_INTERFACE_IDENTIFIER_BIT_WIDTH = 64;
|
|
5
|
+
/** The U/L bit is the second-most significant bit of the first octet. */
|
|
6
|
+
const UNIVERSAL_LOCAL_BIT_INDEX = 6;
|
|
7
|
+
function withFlippedUniversalLocalBit(address) {
|
|
8
|
+
return {
|
|
9
|
+
value: address.value ^
|
|
10
|
+
(1n << BigInt(address.bitWidth - 1 - UNIVERSAL_LOCAL_BIT_INDEX)),
|
|
11
|
+
bitWidth: address.bitWidth,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Builds the IPv6 interface identifier of RFC 4291 Appendix A.
|
|
16
|
+
*
|
|
17
|
+
* An EUI-48 is first widened with `FF:FE`; then — for either width — **the U/L
|
|
18
|
+
* bit is complemented**. That inversion is the step implementations skip: the
|
|
19
|
+
* identifier form spells "universal" as a one, the opposite of IEEE 802, so a
|
|
20
|
+
* universally administered `34-56-78-9A-BC-DE` yields `36-56-78-FF-FE-9A-BC-DE`
|
|
21
|
+
* and not `34-…`.
|
|
22
|
+
*
|
|
23
|
+
* @returns A 64-bit value.
|
|
24
|
+
* @throws RangeError When the address is neither 48 nor 64 bits wide.
|
|
25
|
+
*/
|
|
26
|
+
export function euiToIpv6InterfaceIdentifier(address) {
|
|
27
|
+
if (address.bitWidth === EUI48_BIT_WIDTH) {
|
|
28
|
+
return withFlippedUniversalLocalBit(eui48ToEui64(address));
|
|
29
|
+
}
|
|
30
|
+
if (address.bitWidth === EUI64_BIT_WIDTH) {
|
|
31
|
+
return withFlippedUniversalLocalBit(address);
|
|
32
|
+
}
|
|
33
|
+
throw new RangeError(`expected a 48- or 64-bit EUI, got ${address.bitWidth} bits`);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The inverse of {@link euiToIpv6InterfaceIdentifier}: complements the U/L bit
|
|
37
|
+
* back, yielding the EUI-64 the identifier was built from.
|
|
38
|
+
*
|
|
39
|
+
* @throws RangeError When the identifier is not 64 bits wide.
|
|
40
|
+
*/
|
|
41
|
+
export function ipv6InterfaceIdentifierToEui64(identifier) {
|
|
42
|
+
if (identifier.bitWidth !== IPV6_INTERFACE_IDENTIFIER_BIT_WIDTH) {
|
|
43
|
+
throw new RangeError(`expected a 64-bit interface identifier, got ${identifier.bitWidth} bits`);
|
|
44
|
+
}
|
|
45
|
+
return withFlippedUniversalLocalBit(identifier);
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=interface-identifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface-identifier.js","sourceRoot":"","sources":["../../src/eui/interface-identifier.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,4EAA4E;AAC5E,MAAM,CAAC,MAAM,mCAAmC,GAAG,EAAE,CAAC;AAEtD,yEAAyE;AACzE,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAEpC,SAAS,4BAA4B,CAAC,OAAmB;IACxD,OAAO;QACN,KAAK,EACJ,OAAO,CAAC,KAAK;YACb,CAAC,EAAE,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,GAAG,CAAC,GAAG,yBAAyB,CAAC,CAAC;QACjE,QAAQ,EAAE,OAAO,CAAC,QAAQ;KAC1B,CAAC;AACH,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,4BAA4B,CAAC,OAAmB;IAC/D,IAAI,OAAO,CAAC,QAAQ,KAAK,eAAe,EAAE,CAAC;QAC1C,OAAO,4BAA4B,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED,IAAI,OAAO,CAAC,QAAQ,KAAK,eAAe,EAAE,CAAC;QAC1C,OAAO,4BAA4B,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,MAAM,IAAI,UAAU,CACnB,qCAAqC,OAAO,CAAC,QAAQ,OAAO,CAC5D,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,8BAA8B,CAC7C,UAAsB;IAEtB,IAAI,UAAU,CAAC,QAAQ,KAAK,mCAAmC,EAAE,CAAC;QACjE,MAAM,IAAI,UAAU,CACnB,+CAA+C,UAAU,CAAC,QAAQ,OAAO,CACzE,CAAC;IACH,CAAC;IAED,OAAO,4BAA4B,CAAC,UAAU,CAAC,CAAC;AACjD,CAAC"}
|