Cleanups and debuging output.
[distributedratelimiting.git] / drl / util.c
index a99e27e..c03eced 100644 (file)
@@ -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);
 }