From e920a99518b3e8812f779dd7b5d809b8ac97dcd2 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Wed, 26 Jun 2019 11:45:06 +0300 Subject: 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 --- agent/interfaces.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'agent/interfaces.c') diff --git a/agent/interfaces.c b/agent/interfaces.c index 0dc4b0d..f8bb086 100644 --- a/agent/interfaces.c +++ b/agent/interfaces.c @@ -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; -- cgit v1.2.1