(address)
| 138 | NAT64_BLOCKLIST.addSubnet("64:ff9b:1::", 48, "ipv6"); |
| 139 | |
| 140 | function getNat64EmbeddedIpv4(address) { |
| 141 | if (net.isIP(address) !== 6) return null; |
| 142 | if (!NAT64_BLOCKLIST.check(address, "ipv6")) return null; |
| 143 | |
| 144 | // Expand to full hextets and read the trailing 32 bits as IPv4 octets. |
| 145 | const groups = expandIpv6(address); |
| 146 | if (!groups) return null; |
| 147 | const lo = (groups[6] << 16) | groups[7]; // last two 16-bit groups = 32-bit IPv4 |
| 148 | const ipv4 = [(lo >>> 24) & 0xff, (lo >>> 16) & 0xff, (lo >>> 8) & 0xff, lo & 0xff].join("."); |
| 149 | return net.isIP(ipv4) === 4 ? ipv4 : null; |
| 150 | } |
| 151 | |
| 152 | function expandIpv6(address) { |
| 153 | // Returns an array of 8 numeric hextets, or null if not a valid IPv6 literal. |
no test coverage detected