aboutsummaryrefslogtreecommitdiff
path: root/src/common/address.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2011-12-07 16:03:32 -0500
committerNick Mathewson <nickm@torproject.org>2011-12-28 16:34:16 -0500
commit5d44a6b334f647b162801aa4d0c8607ac14c3ef7 (patch)
tree9cd5c4928c888ff8a9fd6e3d5f2b6e7f0b7ca4ab /src/common/address.c
parentaa529f6c32f2103a5571f98047ee3bd2d5074330 (diff)
downloadtor-5d44a6b334f647b162801aa4d0c8607ac14c3ef7.tar
tor-5d44a6b334f647b162801aa4d0c8607ac14c3ef7.tar.gz
Multicast addresses, if any were configured, would not be good if addrs
Diffstat (limited to 'src/common/address.c')
-rw-r--r--src/common/address.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/common/address.c b/src/common/address.c
index 9ee5d61f2..be205e472 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;