add units to time, use configuration time api where appropriate, fixing Mantis #1875
[oweals/gnunet.git] / src / util / os_network.c
index af8046814e350451013eae041f4835443f38bdab..c5afde7d0cf86fa0b1f6f1b5a41e3f44664d85de 100644 (file)
 #include "gnunet_common.h"
 #include "gnunet_os_lib.h"
 
+
+#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
+#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
+
 /**
  * @brief Enumerate all network interfaces
  *
@@ -131,15 +135,13 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
 
         /* Set entry */
         memset (bPhysAddr, 0, MAXLEN_PHYSADDR);
-        memcpy (bPhysAddr,
-                pTable->table[dwIfIdx].bPhysAddr,
+        memcpy (bPhysAddr, pTable->table[dwIfIdx].bPhysAddr,
                 pTable->table[dwIfIdx].dwPhysAddrLen);
 
         snprintf (szEntry, 1000, "%s (%s - %I64u)",
-                  pszIfName ? pszIfName : (char *)
-                  pTable->table[dwIfIdx].bDescr, inet_ntop (AF_INET,
-                                                            &dwIP, dst,
-                                                            INET_ADDRSTRLEN),
+                  pszIfName ? pszIfName : (char *) pTable->
+                  table[dwIfIdx].bDescr, inet_ntop (AF_INET, &dwIP, dst,
+                                                    INET_ADDRSTRLEN),
                   *((unsigned long long *) bPhysAddr));
         szEntry[1000] = 0;
 
@@ -153,10 +155,12 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
         sa.sin_addr.S_un.S_addr = dwIP;
 
         if (GNUNET_OK !=
-            proc (proc_cls,
-                  szEntry,
+            proc (proc_cls, szEntry,
                   pTable->table[dwIfIdx].dwIndex == dwExternalNIC,
-                  (const struct sockaddr *) &sa, sizeof (sa)))
+                  (const struct sockaddr *) &sa,
+                  NULL,
+                  NULL,
+                  sizeof (sa)))
           break;
       }
     }
@@ -176,8 +180,8 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
   {
     for (ifa_ptr = ifa_first; ifa_ptr != NULL; ifa_ptr = ifa_ptr->ifa_next)
     {
-      if (ifa_ptr->ifa_name != NULL &&
-          ifa_ptr->ifa_addr != NULL && (ifa_ptr->ifa_flags & IFF_UP) != 0)
+      if (ifa_ptr->ifa_name != NULL && ifa_ptr->ifa_addr != NULL &&
+          (ifa_ptr->ifa_flags & IFF_UP) != 0)
       {
         if ((ifa_ptr->ifa_addr->sa_family != AF_INET) &&
             (ifa_ptr->ifa_addr->sa_family != AF_INET6))
@@ -186,11 +190,13 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
           alen = sizeof (struct sockaddr_in);
         else
           alen = sizeof (struct sockaddr_in6);
-        if (GNUNET_OK != proc (proc_cls,
-                               ifa_ptr->ifa_name,
-                               0 == strcmp (ifa_ptr->ifa_name,
-                                            GNUNET_DEFAULT_INTERFACE),
-                               ifa_ptr->ifa_addr, alen))
+        if (GNUNET_OK !=
+            proc (proc_cls, ifa_ptr->ifa_name,
+                  0 == strcmp (ifa_ptr->ifa_name, GNUNET_DEFAULT_INTERFACE),
+                  ifa_ptr->ifa_addr,
+                  ifa_ptr->ifa_broadaddr,
+                  ifa_ptr->ifa_netmask,
+                  alen))
           break;
       }
     }
@@ -217,8 +223,8 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
     f = popen ("ifconfig -a 2> /dev/null", "r");
   if (!f)
   {
-    GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
-                              GNUNET_ERROR_TYPE_BULK, "popen", "ifconfig");
+    LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
+                       "popen", "ifconfig");
     return;
   }
 
@@ -261,10 +267,11 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
 #endif
         a4.sin_addr = v4;
         if (GNUNET_OK !=
-            proc (proc_cls,
-                  ifc,
-                  0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE),
-                  (const struct sockaddr *) &a4, sizeof (a4)))
+            proc (proc_cls, ifc, 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE),
+                  (const struct sockaddr *) &a4,
+                  NULL,
+                  NULL,
+                  sizeof (a4)))
           break;
         continue;
       }
@@ -278,10 +285,11 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
 #endif
         a6.sin6_addr = v6;
         if (GNUNET_OK !=
-            proc (proc_cls,
-                  ifc,
-                  0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE),
-                  (const struct sockaddr *) &a6, sizeof (a6)))
+            proc (proc_cls, ifc, 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE),
+                  (const struct sockaddr *) &a6,
+                  NULL,
+                  NULL,
+                  sizeof (a6)))
           break;
         continue;
       }