[tor-commits] [tor/master] Use get_interface6_via_udp_socket_hack() properly in _list().

nickm at torproject.org nickm at torproject.org
Fri Jan 8 23:09:46 UTC 2016


commit 110765f5564a588c5f019d32b5e6f66cc7806c41
Author: rl1987 <rl1987 at sdf.lonestar.org>
Date:   Wed Jan 6 14:47:35 2016 +0100

    Use get_interface6_via_udp_socket_hack() properly in _list().
    
    When _list() is called with AF_UNSPEC family and fails to enumerate
    network interfaces using platform specific API, have it call
    _hack() twice to find out IPv4 and/or IPv6 address of a machine Tor
    instance is running on. This is correct way to handle this case
    because _hack() can only be called with AF_INET and AF_INET6 and
    does not support any other address family.
---
 changes/feature17951 |    6 ++++++
 src/common/address.c |   33 +++++++++++++++++++++++----------
 2 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/changes/feature17951 b/changes/feature17951
new file mode 100644
index 0000000..42ec32a
--- /dev/null
+++ b/changes/feature17951
@@ -0,0 +1,6 @@
+  o Minor features:
+    - When get_interface_address6_list(.,AF_UNSPEC,.) is called and fails
+      to enumerate interface addresses using the platform-specific API,
+      have it rely on the UDP socket fallback technique to try and find
+      out what IP addresses (both IPv4 and IPv6) our machine has. Resolves
+      ticket 17951.
diff --git a/src/common/address.c b/src/common/address.c
index 69a8098..e2d0eac 100644
--- a/src/common/address.c
+++ b/src/common/address.c
@@ -1547,8 +1547,9 @@ tor_addr_is_multicast(const tor_addr_t *a)
 }
 
 /** Attempt to retrieve IP address of current host by utilizing some
- * UDP socket trickery. Only look for address of given <b>family</b>.
- * Set result to *<b>addr</b>. Return 0 on success, -1 on failure.
+ * UDP socket trickery. Only look for address of given <b>family</b>
+ * (only AF_INET and AF_INET6 are supported). Set result to *<b>addr</b>.
+ * Return 0 on success, -1 on failure.
  */
 MOCK_IMPL(int,
 get_interface_address6_via_udp_socket_hack,(int severity,
@@ -1720,15 +1721,27 @@ MOCK_IMPL(smartlist_t *,get_interface_address6_list,(int severity,
   }
 
   /* Okay, the smart way is out. */
-  if (get_interface_address6_via_udp_socket_hack(severity,family,&addr))
-     return smartlist_new();
-  if (!include_internal && tor_addr_is_internal(&addr, 0)) {
-    return smartlist_new();
-  } else {
-    addrs = smartlist_new();
-    smartlist_add(addrs, tor_dup_addr(&addr));
-    return addrs;
+  addrs = smartlist_new();
+
+  if (family == AF_INET || family == AF_UNSPEC) {
+    if (get_interface_address6_via_udp_socket_hack(severity,AF_INET,
+                                                   &addr) == 0) {
+      if (include_internal || !tor_addr_is_internal(&addr, 0)) {
+        smartlist_add(addrs, tor_dup_addr(&addr));
+      }
+    }
   }
+
+  if (family == AF_INET6 || family == AF_UNSPEC) {
+    if (get_interface_address6_via_udp_socket_hack(severity,AF_INET6,
+                                                   &addr) == 0) {
+      if (include_internal || !tor_addr_is_internal(&addr, 0)) {
+        smartlist_add(addrs, tor_dup_addr(&addr));
+      }
+    }
+  }
+
+  return addrs;
 }
 
 /* ======





More information about the tor-commits mailing list