[tor-commits] [tor/master] Turn get_first_advertised_v4_port_by_type() into get_first_advertised_port_by_type_af().

nickm at torproject.org nickm at torproject.org
Wed Nov 30 17:02:43 UTC 2011


commit 5bee213d236943dac2e08e04c1525e96a62f13f7
Author: Linus Nordberg <linus at nordberg.se>
Date:   Thu Nov 24 17:49:31 2011 +0100

    Turn get_first_advertised_v4_port_by_type() into get_first_advertised_port_by_type_af().
---
 src/or/config.c |   15 ++++++++++-----
 src/or/config.h |    6 +++---
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/or/config.c b/src/or/config.c
index 76b2bcb..c9320f4 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -5907,18 +5907,23 @@ get_configured_ports(void)
   return configured_ports;
 }
 
-/** DOCDOC */
+/** Return the first advertised port of type <b>listener_type</b> in
+    <b>address_family</b>.  */
 int
-get_first_advertised_v4_port_by_type(int listener_type)
+get_first_advertised_port_by_type_af(int listener_type, int address_family)
 {
   if (!configured_ports)
     return 0;
   SMARTLIST_FOREACH_BEGIN(configured_ports, const port_cfg_t *, cfg) {
     if (cfg->type == listener_type &&
         !cfg->no_advertise &&
-        (tor_addr_family(&cfg->addr) == AF_INET ||
-         (tor_addr_family(&cfg->addr) == AF_UNSPEC && !cfg->ipv6_only))) {
-      return cfg->port;
+        (tor_addr_family(&cfg->addr) == address_family ||
+	 tor_addr_family(&cfg->addr) == AF_UNSPEC)) {
+      if (tor_addr_family(&cfg->addr) != AF_UNSPEC ||
+	  (address_family == AF_INET && !cfg->ipv6_only) ||
+	  (address_family == AF_INET6 && !cfg->ipv4_only)) {
+	return cfg->port;
+      }
     }
   } SMARTLIST_FOREACH_END(cfg);
   return 0;
diff --git a/src/or/config.h b/src/or/config.h
index a202bff..cbba9e6 100644
--- a/src/or/config.h
+++ b/src/or/config.h
@@ -65,11 +65,11 @@ int did_last_state_file_write_fail(void);
 int or_state_save(time_t now);
 
 const smartlist_t *get_configured_ports(void);
-int get_first_advertised_v4_port_by_type(int listener_type);
+int get_first_advertised_port_by_type_af(int listener_type, int address_family);
 #define get_primary_or_port() \
-  (get_first_advertised_v4_port_by_type(CONN_TYPE_OR_LISTENER))
+  (get_first_advertised_port_by_type_af(CONN_TYPE_OR_LISTENER, AF_INET))
 #define get_primary_dir_port() \
-  (get_first_advertised_v4_port_by_type(CONN_TYPE_DIR_LISTENER))
+  (get_first_advertised_port_by_type_af(CONN_TYPE_DIR_LISTENER, AF_INET))
 
 int options_need_geoip_info(const or_options_t *options,
                             const char **reason_out);





More information about the tor-commits mailing list