[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r4149 - in GNUnet: . src/transports
From: |
grothoff |
Subject: |
[GNUnet-SVN] r4149 - in GNUnet: . src/transports |
Date: |
Mon, 1 Jan 2007 09:01:14 -0800 (PST) |
Author: grothoff
Date: 2007-01-01 09:01:11 -0800 (Mon, 01 Jan 2007)
New Revision: 4149
Modified:
GNUnet/configure.ac
GNUnet/src/transports/ip.c
GNUnet/src/transports/ip6.c
Log:
Add interface specific IP discovery for OS X (and others.) The
*FromIOCTL stuff should also work on OS X, but in practice didn't - no
idea why. The code from transports/ip.c seems to be duplicated under
upnp/. I wasn't sure why was that done, so I didn't duplicate this code
in there. Only tested on OS X, so needs some testing, especially because
of the autoconf usage.
hl
Modified: GNUnet/configure.ac
===================================================================
--- GNUnet/configure.ac 2007-01-01 08:27:12 UTC (rev 4148)
+++ GNUnet/configure.ac 2007-01-01 17:01:11 UTC (rev 4149)
@@ -432,8 +432,15 @@
AC_CHECK_HEADERS([fcntl.h math.h errno.h limits.h stdio.h locale.h sys/stat.h
sys/types.h pthread.h],,AC_MSG_ERROR([Compiling GNUnet requires standard UNIX
headers files]))
# 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])
+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)]))
@@ -461,7 +468,7 @@
AC_HEADER_SYS_WAIT
AC_TYPE_OFF_T
AC_TYPE_UID_T
-AC_CHECK_FUNCS([floor gethostname memmove rmdir strncasecmp strrchr strtol
atoll dup2 fdatasync ftruncate gethostbyname gettimeofday memset mkdir mkfifo
select socket strcasecmp strchr strdup strerror strstr clock_gettime getrusage
rand uname setlocale getcwd mktime gmtime_r gmtime strlcpy strlcat ftruncate
stat64 sbrk mmap mremap setrlimit gethostbyaddr initgroups])
+AC_CHECK_FUNCS([floor gethostname memmove rmdir strncasecmp strrchr strtol
atoll dup2 fdatasync ftruncate gethostbyname gettimeofday memset mkdir mkfifo
select socket strcasecmp strchr strdup strerror strstr clock_gettime getrusage
rand uname setlocale getcwd mktime gmtime_r gmtime strlcpy strlcat ftruncate
stat64 sbrk mmap mremap setrlimit gethostbyaddr initgroups getifaddrs
freeifaddrs])
# restore LIBS
LIBS=$SAVE_LIBS
Modified: GNUnet/src/transports/ip.c
===================================================================
--- GNUnet/src/transports/ip.c 2007-01-01 08:27:12 UTC (rev 4148)
+++ GNUnet/src/transports/ip.c 2007-01-01 17:01:11 UTC (rev 4149)
@@ -35,12 +35,19 @@
*
* @author Christian Grothoff
* @author Tzvetan Horozov
+ * @author Heikki Lindholm
*/
#include <stdlib.h>
#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
@@ -67,6 +74,58 @@
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,
@@ -329,7 +388,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);
return retval;
Modified: GNUnet/src/transports/ip6.c
===================================================================
--- GNUnet/src/transports/ip6.c 2007-01-01 08:27:12 UTC (rev 4148)
+++ GNUnet/src/transports/ip6.c 2007-01-01 17:01:11 UTC (rev 4149)
@@ -28,12 +28,19 @@
*
* @author Christian Grothoff
* @author Tzvetan Horozov
+ * @author Heikki Lindholm
*/
#include <stdlib.h>
#include "platform.h"
#include "gnunet_util.h"
#include "ip6.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
@@ -80,6 +87,58 @@
return OK;
}
+#if HAVE_GETIFADDRS && HAVE_FREEIFADDRS
+static int getAddress6FromGetIfAddrs(struct GC_Configuration * cfg,
+ struct GE_Context * ectx,
+ IP6addr * 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_INET6)
+ continue;
+ memcpy(identity,
+ &(((struct sockaddr_in6 *)ifa_ptr->ifa_addr)->sin6_addr),
+ sizeof(struct in6_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
+
/**
* Get the IP address for the local machine.
* @return SYSERR on error, OK on success
@@ -125,7 +184,14 @@
}
FREE(ipString);
}
+#if HAVE_GETIFADDRS && HAVE_FREEIFADDRS
if (retval == SYSERR)
+ if (OK == getAddress6FromGetIfAddrs(cfg,
+ ectx,
+ address))
+ retval = OK;
+#endif
+ if (retval == SYSERR)
retval = getAddress6FromHostname(ectx,
address);
return retval;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r4149 - in GNUnet: . src/transports,
grothoff <=