From 89df43dd6b8cb8df82cfbf395b923014d2826b5a Mon Sep 17 00:00:00 2001 From: Kevin Webb Date: Thu, 28 Jan 2010 16:56:54 +0000 Subject: [PATCH] Cleanups and debuging output. --- drl/ulogd_DRL.c | 8 ++++---- drl/util.c | 12 ++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/drl/ulogd_DRL.c b/drl/ulogd_DRL.c index 2bb4e52..f7b0272 100644 --- a/drl/ulogd_DRL.c +++ b/drl/ulogd_DRL.c @@ -1526,10 +1526,10 @@ static int init_drl(void) { pthread_rwlock_init(&limiter.limiter_lock,NULL); /* determine our local IP by iterating through interfaces */ - if ((limiter.ip = get_local_ip())==0) { - printlog(LOG_CRITICAL, - "ulogd_DRL unable to aquire local IP address, not registering.\n"); - return (false); + limiter.ip = get_local_ip(); + if (limiter.ip == NULL) { + printlog(LOG_CRITICAL, "ulogd_DRL unable to aquire local IP address, not registering.\n"); + return false; } limiter.localaddr = inet_addr(limiter.ip); limiter.port = htons(LIMITER_LISTEN_PORT); diff --git a/drl/util.c b/drl/util.c index a99e27e..c03eced 100644 --- a/drl/util.c +++ b/drl/util.c @@ -257,6 +257,7 @@ char* get_local_ip(){ for (ifa = ifp; ifa; ifa=ifa->ifa_next){ + printlog(LOG_DEBUG, "get_local_ip: checking new addr.\n"); if (ifa->ifa_addr->sa_family == AF_INET){ salen = sizeof(struct sockaddr_in); } else if( ifa->ifa_addr->sa_family == AF_INET6){ @@ -281,8 +282,12 @@ char* get_local_ip(){ /* is it MSB first? */ /* We don't want to choose the loopback. */ - if (addrbyte == 127) + if (addrbyte == 127) { + printlog(LOG_DEBUG, "get_local_ip: ignoring the loopback.\n"); continue; + } + + printlog(LOG_DEBUG, "get_local_ip: found address starting with %hhu\n", addrbyte); /* If there's a non-local address, use that. */ if ((addrbyte != 192) && (addrbyte != 172) && (addrbyte != 10)){ @@ -291,6 +296,7 @@ char* get_local_ip(){ if (localip != NULL) { free(localip); } + printlog(LOG_DEBUG, "get_local_ip: returning routable address %s\n", ip); return(ip); /* for now return the IP address */ } else { if (localip == NULL) { @@ -302,8 +308,10 @@ char* get_local_ip(){ freeifaddrs(ifp); free(ip); - if (localip != NULL) + if (localip != NULL) { + printlog(LOG_DEBUG, "get_local_ip: returning local address %s\n", localip); return localip; + } else return(NULL); } -- 2.43.0