diff options
-rw-r--r-- | lib/util/util_net.c | 23 | ||||
-rw-r--r-- | lib/util/util_net.h | 1 | ||||
-rw-r--r-- | source3/utils/net_dns.c | 5 |
3 files changed, 29 insertions, 0 deletions
diff --git a/lib/util/util_net.c b/lib/util/util_net.c index 23d25acab9..139c9d42bc 100644 --- a/lib/util/util_net.c +++ b/lib/util/util_net.c @@ -432,6 +432,29 @@ void zero_ip_v4(struct in_addr *ip) ZERO_STRUCTP(ip); } +bool is_linklocal_addr(const struct sockaddr_storage *pss) +{ +#ifdef HAVE_IPV6 + if (pss->ss_family == AF_INET6) { + const struct in6_addr *pin6 = + &((const struct sockaddr_in6 *)pss)->sin6_addr; + return IN6_IS_ADDR_LINKLOCAL(pin6); + } +#endif + if (pss->ss_family == AF_INET) { + const struct in_addr *pin = + &((const struct sockaddr_in *)pss)->sin_addr; + struct in_addr ll_addr; + struct in_addr mask_addr; + + /* 169.254.0.0/16, is link local, see RFC 3927 */ + ll_addr.s_addr = 0xa9fe0000; + mask_addr.s_addr = 0xffff0000; + return same_net_v4(*pin, ll_addr, mask_addr); + } + return false; +} + /** * Convert an IPv4 struct in_addr to a struct sockaddr_storage. */ diff --git a/lib/util/util_net.h b/lib/util/util_net.h index fc2776a32b..215a6574d4 100644 --- a/lib/util/util_net.h +++ b/lib/util/util_net.h @@ -74,6 +74,7 @@ bool is_loopback_ip_v4(struct in_addr ip); bool is_loopback_addr(const struct sockaddr *pss); bool is_zero_addr(const struct sockaddr_storage *pss); void zero_ip_v4(struct in_addr *ip); +bool is_linklocal_addr(const struct sockaddr_storage *pss); /** Interpret an internet address or name into an IP address in 4 byte form. **/ diff --git a/source3/utils/net_dns.c b/source3/utils/net_dns.c index 5fbdc0a70f..f146f29bcd 100644 --- a/source3/utils/net_dns.c +++ b/source3/utils/net_dns.c @@ -170,6 +170,11 @@ int get_my_ip_address( struct sockaddr_storage **pp_ss ) continue; } + /* Don't register link-local addresses */ + if (is_linklocal_addr(nic_sa_storage)) { + continue; + } + memcpy(&list[count++], nic_sa_storage, sizeof(struct sockaddr_storage)); } *pp_ss = list; |