/* learn things from parent, so we can perform auth */
memcpy(&newconn->local,&conn->local,sizeof(struct sockaddr_in));
newconn->prkey = conn->prkey;
- newconn->address = strdup(inet_ntoa(*(struct in_addr *)&remote.sin_addr.s_addr)); /* remember the remote address */
+ newconn->address = strdup(inet_ntoa(remote.sin_addr)); /* remember the remote address */
if(connection_add(newconn) < 0) { /* no space, forget it */
connection_free(newconn);
log(LOG_ERR,"Error obtaining local hostname.");
return -1;
}
+ log(LOG_DEBUG,"learn_local: localhostname is '%s'.",localhostname);
localhost = gethostbyname(localhostname);
if (!localhost) {
log(LOG_ERR,"Error obtaining local host info.");
}
memset((void *)local,0,sizeof(struct sockaddr_in));
local->sin_family = AF_INET;
- local->sin_addr.s_addr = INADDR_ANY;
memcpy((void *)&local->sin_addr,(void *)localhost->h_addr,sizeof(struct in_addr));
+ log(LOG_DEBUG,"learn_local: chose address as '%s'.",inet_ntoa(local->sin_addr));
return 0;
}
/* local host information */
char localhostname[512];
struct hostent *localhost;
+ struct in_addr *a;
+ char *tmp1;
char *addr = NULL;
int i = 0;
addr = localhost->h_addr_list[i++]; /* set to the first local address */
while(addr)
{
+ a = (struct in_addr *)addr;
+
+ tmp1 = strdup(inet_ntoa(*a)); /* can't call inet_ntoa twice in the same
+ printf, since it overwrites its static
+ memory each time */
+ log(LOG_DEBUG,"router_is_me(): Comparing '%s' to '%s'.",tmp1,
+ inet_ntoa( *((struct in_addr *)&or_address) ) );
+ free(tmp1);
if (!memcmp((void *)&or_address, (void *)addr, sizeof(uint32_t))) { /* addresses match */
-/* FIXME one's a string, one's a uint32_t? does this make sense? */
- if (or_listenport == my_or_listenport) /* ports also match */
+ log(LOG_DEBUG,"router_is_me(): Addresses match. Comparing ports.");
+ if (or_listenport == my_or_listenport) { /* ports also match */
+ log(LOG_DEBUG,"router_is_me(): Ports match too.");
return 1;
+ }
}
addr = localhost->h_addr_list[i++];