Commit e920a995 authored by Stefan Becker's avatar Stefan Becker
Browse files

interfaces: detect IPv6 ULA & link-local addresses

Update nice_interfaces_is_private_ip() to handle IPv6 too:

- unique local address block: fc00::/7
- link-local address block:   fe80::/10
parent 9c93234b
......@@ -193,6 +193,7 @@ nice_interfaces_is_private_ip (const struct sockaddr *_sa)
union {
const struct sockaddr *addr;
const struct sockaddr_in *in;
const struct sockaddr_in6 *in6;
} sa;
sa.addr = _sa;
......@@ -213,6 +214,15 @@ nice_interfaces_is_private_ip (const struct sockaddr *_sa)
/* 169.254.x.x/16 (for APIPA) */
if (sa.in->sin_addr.s_addr >> 16 == 0xA9FE)
return TRUE;
} else if (sa.addr->sa_family == AF_INET6) {
/* fc00::/7 Unique local address (ULA) */
if ((sa.in6->sin6_addr.s6_addr[0] & 0xFE) == 0xFC)
return TRUE;
/* fe80::/10 link-local address */
if ( (sa.in6->sin6_addr.s6_addr[0] == 0xFE) &&
((sa.in6->sin6_addr.s6_addr[1] & 0xC0) == 0x80))
return TRUE;
}
return FALSE;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment