gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r7052 - in GNUnet: . src/util/network src/util/network_clie


From: gnunet
Subject: [GNUnet-SVN] r7052 - in GNUnet: . src/util/network src/util/network_client
Date: Wed, 4 Jun 2008 22:40:19 -0600 (MDT)

Author: grothoff
Date: 2008-06-04 22:40:18 -0600 (Wed, 04 Jun 2008)
New Revision: 7052

Modified:
   GNUnet/configure.ac
   GNUnet/src/util/network/dns.c
   GNUnet/src/util/network_client/tcpio.c
Log:
even more fail-safe dns resolution

Modified: GNUnet/configure.ac
===================================================================
--- GNUnet/configure.ac 2008-06-05 04:15:38 UTC (rev 7051)
+++ GNUnet/configure.ac 2008-06-05 04:40:18 UTC (rev 7052)
@@ -804,7 +804,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 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 
getnameinfo getaddrinfo inet_ntoa localtime_r nl_langinfo putenv realpath 
strndup])
+AC_CHECK_FUNCS([floor gethostname memmove rmdir strncasecmp strrchr strtol 
atoll dup2 fdatasync ftruncate 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 
getnameinfo getaddrinfo inet_ntoa localtime_r nl_langinfo putenv realpath 
strndup gethostbyname2 gethostbyname])
 
 # restore LIBS
 LIBS=$SAVE_LIBS

Modified: GNUnet/src/util/network/dns.c
===================================================================
--- GNUnet/src/util/network/dns.c       2008-06-05 04:15:38 UTC (rev 7051)
+++ GNUnet/src/util/network/dns.c       2008-06-05 04:40:18 UTC (rev 7052)
@@ -194,6 +194,7 @@
                  inet4, INET_ADDRSTRLEN);
       ret = GNUNET_strdup (inet4);
       break;
+#ifdef AF_INET6
     case AF_INET6:
       if (salen != sizeof (struct sockaddr_in6))
         return NULL;
@@ -202,6 +203,7 @@
                  inet6, INET6_ADDRSTRLEN);
       ret = GNUNET_strdup (inet6);
       break;
+#endif
     default:
       ret = NULL;
       break;
@@ -425,7 +427,8 @@
   int s;
   struct addrinfo hints;
   struct addrinfo *result;
-
+  struct in6_addr * out;
+ 
   memset (&hints, 0, sizeof (struct addrinfo));
 // FIXME in PlibC
 #ifndef MINGW
@@ -441,6 +444,48 @@
 
   if (0 != (s = getaddrinfo (hostname, NULL, &hints, &result)))
     {
+      if (domain == AF_INET6)
+       {
+         /* try v4 resolving + mapping */
+         hints.ai_family = AF_INET;
+         if (0 == getaddrinfo (hostname, NULL, &hints, &result))
+           {         
+             GNUNET_GE_ASSERT(NULL, result->ai_addrlen == sizeof(struct 
sockaddr_in));
+             if (NULL == *sa)
+               {                 
+                 *sa = GNUNET_malloc (sizeof(struct sockaddr_in6));
+                 *socklen = sizeof(struct sockaddr_in6);
+                 memset(*sa, 0, sizeof(struct sockaddr_in6));
+                 (*sa)->sa_family = AF_INET6;
+                 out = &((struct sockaddr_in6*)*sa)->sin6_addr;
+                 memcpy (*sa, result->ai_addr, result->ai_addrlen);            
  
+                 ((unsigned int *) out)[2] = htonl (0xffff);
+                 memcpy (&((char *) out)[sizeof (struct in6_addr) -
+                                         sizeof (struct in_addr)],
+                         &result->ai_addr,
+                         sizeof (struct in_addr)); 
+                 freeaddrinfo (result);
+                 return GNUNET_OK;
+               }
+             if (result->ai_addrlen > *socklen)
+               {
+                 freeaddrinfo (result);
+                 return GNUNET_SYSERR;
+               }
+             *socklen = sizeof(struct sockaddr_in6);
+             memset(*sa, 0, sizeof(struct sockaddr_in6));
+             (*sa)->sa_family = AF_INET6;
+             out = &((struct sockaddr_in6*)*sa)->sin6_addr;
+             memcpy (*sa, result->ai_addr, result->ai_addrlen);                
  
+             ((unsigned int *) out)[2] = htonl (0xffff);
+             memcpy (&((char *) out)[sizeof (struct in6_addr) -
+                                     sizeof (struct in_addr)],
+                     &result->ai_addr,
+                     sizeof (struct in_addr)); 
+             freeaddrinfo (result);
+             return GNUNET_OK;
+           }
+       }
       GNUNET_GE_LOG (ectx,
                      GNUNET_GE_WARNING | GNUNET_GE_USER |
                      GNUNET_GE_BULK,
@@ -503,18 +548,19 @@
 #if HAVE_GETADDRINFO
   if (ret == GNUNET_NO)
     ret = getaddrinfo_resolve (ectx, hostname, domain, sa, socklen);
-#endif
+#else
 #if HAVE_GETHOSTBYNAME2
   if (ret == GNUNET_NO)
     ret = gethostbyname2_resolve (ectx, hostname, domain, sa, socklen);
-#endif
+#else
 #if HAVE_GETHOSTBYNAME
   if ((ret == GNUNET_NO) && ((domain == AF_UNSPEC) || (domain == PF_INET)))
     ret = gethostbyname_resolve (ectx, hostname, sa, socklen);
-#endif
-#if !defined(HAVE_GETADDRINFO) && !defined(HAVE_GETHOSTBYNAME2) && 
!defined(HAVE_GETHOSTBYNAME)
+#else
 #error No resolver function available
 #endif
+#endif
+#endif
   GNUNET_mutex_unlock (lock);
   if (ret == GNUNET_NO)
     ret = GNUNET_SYSERR;        /* no further options */

Modified: GNUnet/src/util/network_client/tcpio.c
===================================================================
--- GNUnet/src/util/network_client/tcpio.c      2008-06-05 04:15:38 UTC (rev 
7051)
+++ GNUnet/src/util/network_client/tcpio.c      2008-06-05 04:40:18 UTC (rev 
7052)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2001, 2002, 2006 Christian Grothoff (and other contributing authors)
+     (C) 2001, 2002, 2006, 2008 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
@@ -247,7 +247,16 @@
 {
   /* list of address families to try for connecting,
      in order of preference */
-  static int addr_families[] = { AF_UNSPEC, AF_INET6, AF_INET, -1 };
+  static int addr_families[] = { 
+#ifdef AF_UNSPEC
+    AF_UNSPEC, 
+#endif
+#ifdef AF_INET6
+    AF_INET6, 
+#endif
+    AF_INET,
+    -1 
+  };
   GNUNET_CronTime select_start;
   struct sockaddr *soaddr;
   socklen_t socklen;
@@ -324,8 +333,13 @@
         }
       else
         {
+#ifdef PF_INET6
           ((struct sockaddr_in6 *) soaddr)->sin6_port = htons (port);
           osock = SOCKET (PF_INET6, SOCK_STREAM, 0);
+#else
+         osock = -1;
+         errno = EAFNOSUPPORT;
+#endif
         }
       if (osock == -1)
         {





reply via email to

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