(ip)
| 2402 | }; |
| 2403 | |
| 2404 | function isIpv6LinkLocal(ip) { |
| 2405 | if (!isIPv6(ip)) { return false; } |
| 2406 | |
| 2407 | const ipv6Buffer = convertIpv6StringToBuffer(ip); |
| 2408 | const firstByte = ipv6Buffer[0]; // The first 8 bits |
| 2409 | const secondByte = ipv6Buffer[1]; // The next 8 bits |
| 2410 | |
| 2411 | // The link-local prefix is `1111111010`, which in hexadecimal is `fe80` |
| 2412 | // First 8 bits (firstByte) should be `11111110` (0xfe) |
| 2413 | // The next 2 bits of the second byte should be `10` (0x80) |
| 2414 | |
| 2415 | const isFirstByteCorrect = (firstByte === 0xfe); // 0b11111110 == 0xfe |
| 2416 | const isSecondByteCorrect = (secondByte & 0xc0) === 0x80; // 0b10xxxxxx == 0x80 |
| 2417 | |
| 2418 | return isFirstByteCorrect && isSecondByteCorrect; |
| 2419 | } |
| 2420 | |
| 2421 | function filterOnlyValidAddress(addresses) { |
| 2422 | // Return the first non IPV6 link-local address if present |
no test coverage detected
searching dependent graphs…