|
@@ -524,6 +524,42 @@ int getconfig(int argc, char **argv, or_options_t *options) {
|
|
|
result = -1;
|
|
|
}
|
|
|
|
|
|
+ if(options->ORPort) { /* get an IP for ourselves */
|
|
|
+ struct in_addr in;
|
|
|
+ struct hostent *rent;
|
|
|
+ char localhostname[256];
|
|
|
+
|
|
|
+ if(!options->Address) { /* then we need to guess our address */
|
|
|
+
|
|
|
+ if(gethostname(localhostname,sizeof(localhostname)) < 0) {
|
|
|
+ log_fn(LOG_WARN,"Error obtaining local hostname");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+#if 0 /* don't worry about complaining, as long as it resolves */
|
|
|
+ if(!strchr(localhostname,'.')) {
|
|
|
+ log_fn(LOG_WARN,"fqdn '%s' has only one element. Misconfigured machine?",address);
|
|
|
+ log_fn(LOG_WARN,"Try setting the Address line in your config file.");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+#endif
|
|
|
+ options->Address = tor_strdup(localhostname);
|
|
|
+ log_fn(LOG_DEBUG,"Guessed local host name as '%s'",options->Address);
|
|
|
+ }
|
|
|
+
|
|
|
+ /* now we know options->Address is set. resolve it and keep only the IP */
|
|
|
+
|
|
|
+ rent = (struct hostent *)gethostbyname(options->Address);
|
|
|
+ if (!rent) {
|
|
|
+ log_fn(LOG_WARN,"Could not resolve Address %s. Failing.", options->Address);
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ assert(rent->h_length == 4);
|
|
|
+ memcpy(&in.s_addr, rent->h_addr,rent->h_length);
|
|
|
+ tor_free(options->Address);
|
|
|
+ options->Address = tor_strdup(inet_ntoa(in));
|
|
|
+ log_fn(LOG_DEBUG,"Resolved Address to %s.", options->Address);
|
|
|
+ }
|
|
|
+
|
|
|
if(options->SocksPort < 0) {
|
|
|
log(LOG_WARN,"SocksPort option can't be negative.");
|
|
|
result = -1;
|