(address)
| 150 | } |
| 151 | |
| 152 | function 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 | |
| 170 | function isMetadataAddress(address) { |
| 171 | if (METADATA_IP_ADDRESSES.has(address)) return true; |
no outgoing calls
no test coverage detected