diff options
author | Nick Mathewson <nickm@torproject.org> | 2012-05-11 11:52:51 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-05-11 11:52:51 -0400 |
commit | e0655708a20069a5f42476a25d62e9d3f8138d8c (patch) | |
tree | 4ee26e5176efe7f61c4fba89bc21886b7508df27 /src/or/config.c | |
parent | 84ddc4b6aad392dd9a735580caf6fb68e3694d42 (diff) | |
parent | 6d2898607bd831944c6c15b6e15200a426149811 (diff) | |
download | tor-e0655708a20069a5f42476a25d62e9d3f8138d8c.tar.gz tor-e0655708a20069a5f42476a25d62e9d3f8138d8c.zip |
Merge remote-tracking branch 'asn/bug4865_take2'
Diffstat (limited to 'src/or/config.c')
-rw-r--r-- | src/or/config.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/or/config.c b/src/or/config.c index ab4f160bf2..d11835463b 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -6040,6 +6040,65 @@ get_configured_ports(void) return configured_ports; } +/** Return an <address>:<port> string representation of the address + * where the first <b>listener_type</b> listener waits for + * connections. Return NULL if we couldn't find a listener. The + * string is allocated on the heap and it's the responsibility of the + * caller to free it after use. + * + * This function is meant to be used by the pluggable transport proxy + * spawning code, please make sure that it fits your purposes before + * using it. */ +char * +get_first_listener_addrport_string(int listener_type) +{ + static const char *ipv4_localhost = "127.0.0.1"; + static const char *ipv6_localhost = "[::1]"; + const char *address; + uint16_t port; + char *string = NULL; + + if (!configured_ports) + return NULL; + + SMARTLIST_FOREACH_BEGIN(configured_ports, const port_cfg_t *, cfg) { + if (cfg->no_listen) + continue; + + if (cfg->type == listener_type && + tor_addr_family(&cfg->addr) != AF_UNSPEC) { + + /* We found the first listener of the type we are interested in! */ + + /* If a listener is listening on INADDR_ANY, assume that it's + also listening on 127.0.0.1, and point the transport proxy + there: */ + if (tor_addr_is_null(&cfg->addr)) + address = tor_addr_is_v4(&cfg->addr) ? ipv4_localhost : ipv6_localhost; + else + address = fmt_and_decorate_addr(&cfg->addr); + + /* If a listener is configured with port 'auto', we are forced + to iterate all listener connections and find out in which + port it ended up listening: */ + if (cfg->port == CFG_AUTO_PORT) { + port = router_get_active_listener_port_by_type(listener_type); + if (!port) + return NULL; + } else { + port = cfg->port; + } + + tor_asprintf(&string, "%s:%u", address, port); + + return string; + } + + } SMARTLIST_FOREACH_END(cfg); + + return NULL; +} + /** Return the first advertised port of type <b>listener_type</b> in <b>address_family</b>. */ int |