(host)
| 33 | // like `[::ffff:169.254.169.254]` slips a dotted-quad regex but resolves |
| 34 | // directly to 169.254.169.254 at connect time. |
| 35 | function hostVariants(host) { |
| 36 | const out = new Set(); |
| 37 | const lower = host.toLowerCase(); |
| 38 | out.add(lower); |
| 39 | let h = lower; |
| 40 | if (h.startsWith("[") && h.endsWith("]")) { |
| 41 | h = h.slice(1, -1); |
| 42 | out.add(h); |
| 43 | } |
| 44 | const dotted = h.match(/^(?:::ffff:|::)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/); |
| 45 | if (dotted) |
| 46 | out.add(dotted[1]); |
| 47 | const hex = h.match(/^(?:::ffff:|::)([0-9a-f]{1,4}):([0-9a-f]{1,4})$/); |
| 48 | if (hex) { |
| 49 | const a = parseInt(hex[1], 16), b = parseInt(hex[2], 16); |
| 50 | out.add(`${(a >> 8) & 0xff}.${a & 0xff}.${(b >> 8) & 0xff}.${b & 0xff}`); |
| 51 | } |
| 52 | return [...out]; |
| 53 | } |
| 54 | function isLoopbackOne(h) { |
| 55 | if (h === "localhost" || h === "::1" || h === "::") |
| 56 | return true; |
no test coverage detected