LRN: Fix automake deps to allow -j* builds again
[oweals/gnunet.git] / src / util / os_network.c
index cb5ccb12a5be9a56a0ee9bde98f089c60e54d4de..ccf326c05e8a64c962ef7783467ef20c8834a984 100644 (file)
 
 /**
  * @brief Enumerate all network interfaces
- * @param callback the callback function
+ *
+ * @param proc the callback function
+ * @param proc_cls closure for proc
  */
 void
 GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
-                                   void *cls)
+                                   void *proc_cls)
 {
 #ifdef MINGW
   PMIB_IFTABLE pTable;
@@ -62,7 +64,6 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
         {
           char szEntry[1001];
           DWORD dwIP = 0;
-          int iItm;
           PIP_ADAPTER_INFO pAdapterInfo;
           PIP_ADAPTER_INFO pAdapter = NULL;
           DWORD dwRetVal = 0;
@@ -84,6 +85,7 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
               BYTE bPhysAddr[MAXLEN_PHYSADDR];
               char *pszIfName = NULL;
               char dst[INET_ADDRSTRLEN];
+              struct sockaddr_in sa;
 
               /* Get friendly interface name */
               pAdapterInfo =
@@ -135,21 +137,28 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
                       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;
 
               if (pszIfName)
                 free (pszIfName);
 
+              sa.sin_family = AF_INET;
+#if HAVE_SOCKADDR_IN_SIN_LEN
+             sa.sin_len = (u_char) sizeof (struct sockaddr_in);
+#endif
+              sa.sin_addr.S_un.S_addr = dwIP;
+
               if (GNUNET_OK !=
-                  proc (cls,
+                  proc (proc_cls,
                         szEntry,
-                        pAddrTable->table[dwIfIdx].dwIndex == dwExternalNIC,
-                        NULL /* FIXME: pass actual IP address! */ ,
-                        0))
+                        pTable->table[dwIfIdx].dwIndex == dwExternalNIC,
+                        (const struct sockaddr *) &sa,
+                        sizeof (sa)))
                 break;
             }
         }
@@ -157,18 +166,16 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
       GlobalFree (pTable);
     }
 
-  return GNUNET_YES;
+  return;
 
 #elif HAVE_GETIFADDRS && HAVE_FREEIFADDRS
 
   struct ifaddrs *ifa_first;
+  struct ifaddrs *ifa_ptr;
   socklen_t alen;
 
   if (getifaddrs (&ifa_first) == 0)
     {
-      struct ifaddrs *ifa_ptr;
-
-      ifa_ptr = ifa_first;
       for (ifa_ptr = ifa_first; ifa_ptr != NULL; ifa_ptr = ifa_ptr->ifa_next)
         {
           if (ifa_ptr->ifa_name != NULL &&
@@ -181,7 +188,7 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
                 alen = sizeof (struct sockaddr_in);
               else
                 alen = sizeof (struct sockaddr_in6);
-              if (GNUNET_OK != proc (cls,
+              if (GNUNET_OK != proc (proc_cls,
                                      ifa_ptr->ifa_name,
                                      0 == strcmp (ifa_ptr->ifa_name,
                                                   GNUNET_DEFAULT_INTERFACE),
@@ -252,9 +259,12 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
             {
               memset (&a4, 0, sizeof (a4));
               a4.sin_family = AF_INET;
+#if HAVE_SOCKADDR_IN_SIN_LEN
+             a4.sin_len = (u_char) sizeof (struct sockaddr_in);
+#endif
               a4.sin_addr = v4;
               if (GNUNET_OK !=
-                  proc (cls,
+                  proc (proc_cls,
                         ifc,
                         0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE),
                         (const struct sockaddr *) &a4, sizeof (a4)))
@@ -266,10 +276,12 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
             {
               memset (&a6, 0, sizeof (a6));
               a6.sin6_family = AF_INET6;
+#if HAVE_SOCKADDR_IN_SIN_LEN
+             a6.sin6_len = (u_char) sizeof (struct sockaddr_in6);
+#endif
               a6.sin6_addr = v6;
-              fprintf (stderr, "procing %s\n", addrstr);
               if (GNUNET_OK !=
-                  proc (cls,
+                  proc (proc_cls,
                         ifc,
                         0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE),
                         (const struct sockaddr *) &a6, sizeof (a6)))