MCPcopy Index your code
hub / github.com/nodejs/node / isIpv6LinkLocal

Function isIpv6LinkLocal

lib/net.js:2404–2419  ·  view source on GitHub ↗
(ip)

Source from the content-addressed store, hash-verified

2402};
2403
2404function 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
2421function filterOnlyValidAddress(addresses) {
2422 // Return the first non IPV6 link-local address if present

Callers 1

filterOnlyValidAddressFunction · 0.85

Calls 1

isIPv6Function · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…