diff options
author | George Kadianakis <desnacked@gmail.com> | 2011-12-18 13:21:58 +0100 |
---|---|---|
committer | George Kadianakis <desnacked@gmail.com> | 2011-12-18 13:21:58 +0100 |
commit | 539cb627f71b476eb325ae6fff829b1f360ada00 (patch) | |
tree | 835ebfe1555cb4cd1cca8bc1f134a647632ef89e /src/or/config.c | |
parent | 960f62bd82c249b456a0aa2e1ae62f68c754aacb (diff) | |
download | tor-539cb627f71b476eb325ae6fff829b1f360ada00.tar.gz tor-539cb627f71b476eb325ae6fff829b1f360ada00.zip |
Server transports should be instructed to bind on INADDR_ANY by default.
Diffstat (limited to 'src/or/config.c')
-rw-r--r-- | src/or/config.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/or/config.c b/src/or/config.c index 073b44d5e6..521f760051 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -6828,21 +6828,29 @@ get_transport_bindaddr(const char *line, const char *transport) return NULL; } -/** Return a static string containing the address:port a proxy - * transport should bind on. */ -const char * +/** Return a string containing the address:port that a proxy transport + * should bind on. The string is stored on the heap and must be freed + * by the caller of this function. */ +char * get_bindaddr_for_transport(const char *transport) { - static const char default_addrport[] = "127.0.0.1:0"; - const char *bindaddr = NULL; + char *default_addrport = NULL; + const char *stored_bindaddr = NULL; config_line_t *line = get_transport_in_state_by_name(transport); - if (!line) - return default_addrport; - - bindaddr = get_transport_bindaddr(line->value, transport); - - return bindaddr ? bindaddr : default_addrport; + if (!line) /* Found no references in state for this transport. */ + goto no_bindaddr_found; + + stored_bindaddr = get_transport_bindaddr(line->value, transport); + if (stored_bindaddr) /* found stored bindaddr in state file. */ + return tor_strdup(stored_bindaddr); + + no_bindaddr_found: + /** If we didn't find references for this pluggable transport in the + state file, we should instruct the pluggable transport proxy to + listen on INADDR_ANY on a random ephemeral port. */ + tor_asprintf(&default_addrport, "%s:%s", fmt_addr32(INADDR_ANY), "0"); + return default_addrport; } /** Save <b>transport</b> listening on <b>addr</b>:<b>port</b> to |