commit 5d44a6b334f647b162801aa4d0c8607ac14c3ef7 Author: Nick Mathewson nickm@torproject.org Date: Wed Dec 7 16:03:32 2011 -0500
Multicast addresses, if any were configured, would not be good if addrs --- src/common/address.c | 22 +++++++++++++++++++++- 1 files changed, 21 insertions(+), 1 deletions(-)
diff --git a/src/common/address.c b/src/common/address.c index 9ee5d61..be205e4 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 <b>a</b> 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 *<b>addr</b> 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;