From 5d44a6b334f647b162801aa4d0c8607ac14c3ef7 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 7 Dec 2011 16:03:32 -0500 Subject: Multicast addresses, if any were configured, would not be good if addrs --- src/common/address.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/common/address.c') diff --git a/src/common/address.c b/src/common/address.c index 9ee5d61f2c..be205e4725 100644 --- a/src/common/address.c +++ b/src/common/address.c @@ -1203,6 +1203,24 @@ get_interface_addresses_raw(int severity) return NULL; #endif } + +/** Return true iff a is a multicast address. */ +static int +tor_addr_is_multicast(const tor_addr_t *a) +{ + sa_family_t family = tor_addr_family(a); + if (family == AF_INET) { + uint32_t ipv4h = tor_addr_to_ipv4h(a); + if ((ipv4h >> 24) == 0xe0) + return 1; /* Multicast */ + } else if (family == AF_INET6) { + const uint8_t *a32 = tor_addr_to_in6_addr8(a); + if (a32[0] == 0xff) + return 1; + } + return 0; +} + /** Set *addr to the IP address (if any) of whatever interface * connects to the Internet. This address should only be used in checking * whether our address has changed. Return 0 on success, -1 on failure. @@ -1223,8 +1241,10 @@ get_interface_address6(int severity, sa_family_t family, tor_addr_t *addr) SMARTLIST_FOREACH_BEGIN(addrs, tor_addr_t *, a) { if (family != AF_UNSPEC && family != tor_addr_family(a)) continue; - if (tor_addr_is_loopback(a)) + if (tor_addr_is_loopback(a) || + tor_addr_is_multicast(a)) continue; + tor_addr_copy(addr, a); rv = 0; -- cgit v1.2.3-54-g00ecf