diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-12-29 10:00:34 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-12-29 10:00:34 -0500 |
commit | e85f0c650c0509ceff777d0a7fafd6c953604ad8 (patch) | |
tree | 519327dc8872d86669392983c2e2b2459d1c777c /src/or | |
parent | 4d6a971ba94f22a86577840cdf1b4935cd445a9b (diff) | |
parent | de432d55657ee124bce0e9a4d5f5842088e2e13b (diff) | |
download | tor-e85f0c650c0509ceff777d0a7fafd6c953604ad8.tar.gz tor-e85f0c650c0509ceff777d0a7fafd6c953604ad8.zip |
Merge branch 'resolvemyaddr_squashed'
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/config.c | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/or/config.c b/src/or/config.c index e7891a5bd3..ae4b0892d6 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -11,6 +11,7 @@ #define CONFIG_PRIVATE #include "or.h" +#include "compat.h" #include "addressmap.h" #include "channel.h" #include "circuitbuild.h" @@ -2086,7 +2087,33 @@ reset_last_resolved_addr(void) } /** - * Use <b>options-\>Address</b> to guess our public IP address. + * Attempt getting our non-local (as judged by tor_addr_is_internal() + * function) IP address using following techniques, listed in + * order from best (most desirable, try first) to worst (least + * desirable, try if everything else fails). + * + * First, attempt using <b>options-\>Address</b> to get our + * non-local IP address. + * + * If <b>options-\>Address</b> represents a non-local IP address, + * consider it ours. + * + * If <b>options-\>Address</b> is a DNS name that resolves to + * a non-local IP address, consider this IP address ours. + * + * If <b>options-\>Address</b> is NULL, fall back to getting local + * hostname and using it in above-described ways to try and + * get our IP address. + * + * In case local hostname cannot be resolved to a non-local IP + * address, try getting an IP address of network interface + * in hopes it will be non-local one. + * + * Fail if one or more of the following is true: + * - DNS name in <b>options-\>Address</b> cannot be resolved. + * - <b>options-\>Address</b> is a local host address. + * - Attempt to getting local hostname fails. + * - Attempt to getting network interface address fails. * * Return 0 if all is well, or -1 if we can't find a suitable * public IP address. @@ -2095,6 +2122,11 @@ reset_last_resolved_addr(void) * - Put our public IP address (in host order) into *<b>addr_out</b>. * - If <b>method_out</b> is non-NULL, set *<b>method_out</b> to a static * string describing how we arrived at our answer. + * - "CONFIGURED" - parsed from IP address string in + * <b>options-\>Address</b> + * - "RESOLVED" - resolved from DNS name in <b>options-\>Address</b> + * - "GETHOSTNAME" - resolved from a local hostname. + * - "INTERFACE" - retrieved from a network interface. * - If <b>hostname_out</b> is non-NULL, and we resolved a hostname to * get our address, set *<b>hostname_out</b> to a newly allocated string * holding that hostname. (If we didn't get our address by resolving a @@ -2133,7 +2165,7 @@ resolve_my_address(int warn_severity, const or_options_t *options, explicit_ip = 0; /* it's implicit */ explicit_hostname = 0; /* it's implicit */ - if (gethostname(hostname, sizeof(hostname)) < 0) { + if (tor_gethostname(hostname, sizeof(hostname)) < 0) { log_fn(warn_severity, LD_NET,"Error obtaining local hostname"); return -1; } |