gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r4150 - in GNUnet: . src/include src/transports src/transpo


From: grothoff
Subject: [GNUnet-SVN] r4150 - in GNUnet: . src/include src/transports src/transports/upnp
Date: Mon, 1 Jan 2007 16:46:39 -0800 (PST)

Author: grothoff
Date: 2007-01-01 16:46:35 -0800 (Mon, 01 Jan 2007)
New Revision: 4150

Modified:
   GNUnet/configure.ac
   GNUnet/src/include/platform.h
   GNUnet/src/transports/ip.c
   GNUnet/src/transports/upnp/ip.c
Log:
cleaner

Modified: GNUnet/configure.ac
===================================================================
--- GNUnet/configure.ac 2007-01-01 17:01:11 UTC (rev 4149)
+++ GNUnet/configure.ac 2007-01-02 00:46:35 UTC (rev 4150)
@@ -434,13 +434,6 @@
 # Checks for headers that are only required on some systems or opional (and 
where we do NOT abort if they are not there)
 AC_CHECK_HEADERS([langinfo.h sys/param.h sys/mount.h sys/statvfs.h sys/vfs.h 
arpa/inet.h fcntl.h libintl.h netdb.h netinet/in.h sys/ioctl.h sys/socket.h 
sys/time.h unistd.h kstat.h sys/sysinfo.h kvm.h sys/file.h sys/resource.h 
iconv.h ifaddrs.h])
 
-# Check for net/if.h, which on OS X requires sys/socket.h first
-AC_CHECK_HEADERS([sys/socket.h net/if.h], [], [],
-     [[#ifdef HAVE_SYS_SOCKET_H
-     # include <sys/socket.h>
-     #endif
-     ]])
-
 # Check for GMP header (and abort if not present)
 AC_CHECK_HEADERS([gmp.h],,AC_MSG_ERROR([Compiling GNUnet requires gmp.h (from 
the GNU MP library, libgmp)]))
 

Modified: GNUnet/src/include/platform.h
===================================================================
--- GNUnet/src/include/platform.h       2007-01-01 17:01:11 UTC (rev 4149)
+++ GNUnet/src/include/platform.h       2007-01-02 00:46:35 UTC (rev 4150)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2001, 2002, 2003, 2004, 2005 Christian Grothoff (and other 
contributing authors)
+     (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 Christian Grothoff (and 
other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -131,7 +131,11 @@
 #endif
 #ifdef OSX
 #include <semaphore.h>
+#include <net/if.h>
+#if HAVE_IFADDRS_H
+#include <ifaddrs.h>
 #endif
+#endif
 #ifdef LINUX
 #include <net/if.h>
 #endif

Modified: GNUnet/src/transports/ip.c
===================================================================
--- GNUnet/src/transports/ip.c  2007-01-01 17:01:11 UTC (rev 4149)
+++ GNUnet/src/transports/ip.c  2007-01-02 00:46:35 UTC (rev 4150)
@@ -42,12 +42,6 @@
 #include "platform.h"
 #include "gnunet_util.h"
 #include "ip.h"
-#if HAVE_IFADDRS_H
-#if HAVE_NET_IF_H
-#include <net/if.h>
-#endif
-#include <ifaddrs.h>
-#endif
 
 /* maximum length of hostname */
 #define MAX_HOSTNAME 1024

Modified: GNUnet/src/transports/upnp/ip.c
===================================================================
--- GNUnet/src/transports/upnp/ip.c     2007-01-01 17:01:11 UTC (rev 4149)
+++ GNUnet/src/transports/upnp/ip.c     2007-01-02 00:46:35 UTC (rev 4150)
@@ -41,7 +41,6 @@
 #include "platform.h"
 #include "gnunet_util.h"
 #include "ip.h"
-
 /* maximum length of hostname */
 #define MAX_HOSTNAME 1024
 
@@ -67,6 +66,59 @@
   return ret;
 }
 
+#if HAVE_GETIFADDRS && HAVE_FREEIFADDRS
+static int getAddressFromGetIfAddrs(struct GC_Configuration * cfg,
+                                   struct GE_Context * ectx,
+                                   IPaddr * identity) {
+  char * interfaces;
+  struct ifaddrs *ifa_first;
+
+  if (-1 == GC_get_configuration_value_string(cfg,
+                                             "NETWORK",
+                                             "INTERFACE",
+                                             "eth0",
+                                             &interfaces)) {
+    GE_LOG(ectx,
+          GE_ERROR | GE_BULK | GE_USER,
+          _("No interface specified in section `%s' under `%s'!\n"),
+          "NETWORK",
+          "INTERFACE");
+    return SYSERR; /* that won't work! */
+  }
+
+  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 && 
+          ifa_ptr->ifa_addr != NULL && 
+          (ifa_ptr->ifa_flags & IFF_UP) != 0) {
+        if (strcmp(interfaces, (char *)ifa_ptr->ifa_name) != 0)
+          continue;
+        if (ifa_ptr->ifa_addr->sa_family != AF_INET)
+          continue;
+        memcpy(identity,
+               &(((struct sockaddr_in *)ifa_ptr->ifa_addr)->sin_addr),
+               sizeof(struct in_addr));
+        freeifaddrs(ifa_first);
+        FREE(interfaces);
+        return OK;
+      }
+    }
+    freeifaddrs(ifa_first);
+  }
+  GE_LOG(ectx,
+        GE_WARNING | GE_USER | GE_BULK,
+        _("Could not obtain IP for interface `%s' using `%s'.\n"),
+        interfaces,
+        "getifaddrs");
+  FREE(interfaces);
+  return SYSERR;
+}
+#endif
+
+
 #if LINUX || SOMEBSD || MINGW
 #define MAX_INTERFACES 16
 static int getAddressFromIOCTL(struct GC_Configuration * cfg,
@@ -330,7 +382,14 @@
                                  &address))
       retval = OK;
 #endif
+#if HAVE_GETIFADDRS && HAVE_FREEIFADDRS
   if (retval == SYSERR)
+    if (OK == getAddressFromGetIfAddrs(cfg, 
+                                       ectx,
+                                      address))
+      retval = OK;
+#endif
+  if (retval == SYSERR)
     retval = getAddressFromHostname(ectx,
                                    &address);
   if (retval == SYSERR)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]