MCPcopy Create free account
hub / github.com/chartbrew/chartbrew / expandIpv6

Function expandIpv6

server/modules/outboundTargetPolicy.js:152–168  ·  view source on GitHub ↗
(address)

Source from the content-addressed store, hash-verified

150}
151
152function expandIpv6(address) {
153 // Returns an array of 8 numeric hextets, or null if not a valid IPv6 literal.
154 const stripped = address.replace(/^\[|\]$/g, "");
155 if (net.isIP(stripped) !== 6) return null;
156 const [head, tail] = stripped.split("::");
157 const headParts = head ? head.split(":") : [];
158 const tailParts = tail !== undefined && tail !== "" ? tail.split(":") : [];
159 const fill = 8 - headParts.length - tailParts.length;
160 if (fill < 0) return null;
161 const parts = [
162 ...headParts,
163 ...Array(tail !== undefined ? fill : 0).fill("0"),
164 ...tailParts,
165 ];
166 if (parts.length !== 8) return null;
167 return parts.map((p) => parseInt(p || "0", 16) & 0xffff);
168}
169
170function isMetadataAddress(address) {
171 if (METADATA_IP_ADDRESSES.has(address)) return true;

Callers 1

getNat64EmbeddedIpv4Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected