[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] Store options->Address as IP, not hostname
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/or
Modified Files:
config.c router.c routerlist.c
Log Message:
Store options->Address as IP, not hostname
And figure it out while reading config, not every time you
rebuild the descriptor
Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.90
retrieving revision 1.91
diff -u -d -r1.90 -r1.91
--- config.c 2 Mar 2004 05:19:01 -0000 1.90
+++ config.c 4 Mar 2004 01:53:55 -0000 1.91
@@ -524,6 +524,42 @@
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;
Index: router.c
===================================================================
RCS file: /home/or/cvsroot/src/or/router.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- router.c 18 Feb 2004 07:23:35 -0000 1.12
+++ router.c 4 Mar 2004 01:53:56 -0000 1.13
@@ -321,23 +321,9 @@
int router_rebuild_descriptor(void) {
routerinfo_t *ri;
- char localhostname[256];
- char *address = options.Address;
- if(!address) { /* if not specified in config, we find a default */
- if(gethostname(localhostname,sizeof(localhostname)) < 0) {
- log_fn(LOG_WARN,"Error obtaining local hostname");
- return -1;
- }
- address = localhostname;
- if(!strchr(address,'.')) {
- 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;
- }
- }
- ri = tor_malloc(sizeof(routerinfo_t));
- ri->address = tor_strdup(address);
+ ri = tor_malloc_zero(sizeof(routerinfo_t));
+ ri->address = tor_strdup(options.Address);
ri->nickname = tor_strdup(options.Nickname);
/* No need to set addr. */
ri->or_port = options.ORPort;
Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routerlist.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- routerlist.c 29 Feb 2004 01:31:33 -0000 1.29
+++ routerlist.c 4 Mar 2004 01:53:56 -0000 1.30
@@ -377,7 +377,8 @@
rent = (struct hostent *)gethostbyname(router->address);
if (!rent) {
- log_fn(LOG_WARN,"Could not get address for router %s.",router->address);
+ log_fn(LOG_WARN,"Could not get address for router %s (%s).",
+ router->address, router->nickname);
return -1;
}
assert(rent->h_length == 4);