gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r36020 - in gnunet/src: arm gns util


From: gnunet
Subject: [GNUnet-SVN] r36020 - in gnunet/src: arm gns util
Date: Mon, 29 Jun 2015 10:00:26 +0200

Author: grothoff
Date: 2015-06-29 10:00:26 +0200 (Mon, 29 Jun 2015)
New Revision: 36020

Modified:
   gnunet/src/arm/test_gnunet_service_arm.c
   gnunet/src/gns/gnunet-service-gns_resolver.c
   gnunet/src/util/gnunet-service-resolver.c
   gnunet/src/util/resolver_api.c
   gnunet/src/util/test_resolver_api.c
Log:
-fix #3870

Modified: gnunet/src/arm/test_gnunet_service_arm.c
===================================================================
--- gnunet/src/arm/test_gnunet_service_arm.c    2015-06-28 13:53:42 UTC (rev 
36019)
+++ gnunet/src/arm/test_gnunet_service_arm.c    2015-06-29 08:00:26 UTC (rev 
36020)
@@ -214,13 +214,54 @@
     strcpy (hostname,
            "www.gnu.org");
   }
-  if (NULL == gethostbyname (hostname))
+  /* trigger DNS lookup */
+#if HAVE_GETADDRINFO
   {
-    FPRINTF (stderr,
-             "Failed to resolve my hostname `%s', testcase not run.\n",
-             hostname);
-    return 0;
+    struct addrinfo *ai;
+    int ret;
+
+    if (0 != (ret = getaddrinfo (hostname, NULL, NULL, &ai)))
+    {
+      FPRINTF (stderr,
+               "Failed to resolve my hostname `%s', testcase not run.\n",
+               hostname);
+      return 0;
+    }
+    freeaddrinfo (ai);
   }
+#elif HAVE_GETHOSTBYNAME2
+  {
+    struct hostent *host;
+
+    host = gethostbyname2 (hostname, AF_INET);
+    if (NULL == host)
+      host = gethostbyname2 (hostname, AF_INET6);
+    if (NULL == host)
+      {
+        FPRINTF (stderr,
+                 "Failed to resolve my hostname `%s', testcase not run.\n",
+                 hostname);
+        return 0;
+      }
+  }
+#elif HAVE_GETHOSTBYNAME
+  {
+    struct hostent *host;
+
+    host = gethostbyname (hostname);
+    if (NULL == host)
+      {
+        FPRINTF (stderr,
+                 "Failed to resolve my hostname `%s', testcase not run.\n",
+                 hostname);
+        return 0;
+      }
+  }
+#else
+  FPRINTF (stderr,
+           "libc fails to have resolver function, testcase not run.\n");
+  return 0;
+#endif
   GNUNET_log_setup ("test-gnunet-service-arm",
                    "WARNING",
                    NULL);

Modified: gnunet/src/gns/gnunet-service-gns_resolver.c
===================================================================
--- gnunet/src/gns/gnunet-service-gns_resolver.c        2015-06-28 13:53:42 UTC 
(rev 36019)
+++ gnunet/src/gns/gnunet-service-gns_resolver.c        2015-06-29 08:00:26 UTC 
(rev 36020)
@@ -168,7 +168,7 @@
 
   /**
    * Expiration time for the DNS record, 0 if we didn't
-   * get anything useful (i.e. 'gethostbyname' was used).
+   * get anything useful (i.e. 'gethostbyname()' was used).
    */
   uint64_t expiration_time;
 

Modified: gnunet/src/util/gnunet-service-resolver.c
===================================================================
--- gnunet/src/util/gnunet-service-resolver.c   2015-06-28 13:53:42 UTC (rev 
36019)
+++ gnunet/src/util/gnunet-service-resolver.c   2015-06-29 08:00:26 UTC (rev 
36020)
@@ -365,10 +365,11 @@
   freeaddrinfo (result);
   return GNUNET_OK;
 }
-#endif
 
 
-#if HAVE_GETHOSTBYNAME2
+#elif HAVE_GETHOSTBYNAME2
+
+
 static int
 gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc,
                         const char *hostname,
@@ -424,10 +425,10 @@
   }
   return GNUNET_OK;
 }
-#endif
 
+#elif HAVE_GETHOSTBYNAME
 
-#if HAVE_GETHOSTBYNAME
+
 static int
 gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc,
                        const char *hostname)
@@ -478,12 +479,10 @@
 #if HAVE_GETADDRINFO
   if (ret == GNUNET_NO)
     ret = getaddrinfo_resolve (tc, hostname, af);
-#endif
-#if HAVE_GETHOSTBYNAME2
+#elif HAVE_GETHOSTBYNAME2
   if (ret == GNUNET_NO)
     ret = gethostbyname2_resolve (tc, hostname, af);
-#endif
-#if HAVE_GETHOSTBYNAME
+#elif HAVE_GETHOSTBYNAME
   if ((ret == GNUNET_NO) && ((af == AF_UNSPEC) || (af == PF_INET)))
     gethostbyname_resolve (tc, hostname);
 #endif

Modified: gnunet/src/util/resolver_api.c
===================================================================
--- gnunet/src/util/resolver_api.c      2015-06-28 13:53:42 UTC (rev 36019)
+++ gnunet/src/util/resolver_api.c      2015-06-29 08:00:26 UTC (rev 36020)
@@ -1004,7 +1004,6 @@
 char *
 GNUNET_RESOLVER_local_fqdn_get ()
 {
-  struct hostent *host;
   char hostname[GNUNET_OS_get_hostname_max_length () + 1];
 
   if (0 != gethostname (hostname, sizeof (hostname) - 1))
@@ -1016,15 +1015,57 @@
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Resolving our FQDN `%s'\n",
        hostname);
-  host = gethostbyname (hostname);
-  if (NULL == host)
+#if HAVE_GETADDRINFO
   {
-    LOG (GNUNET_ERROR_TYPE_ERROR,
-         _("Could not resolve our FQDN : %s\n"),
-         hstrerror (h_errno));
-    return NULL;
+    struct addrinfo *ai;
+    int ret;
+    char *rval;
+
+    if (0 != (ret = getaddrinfo (hostname, NULL, NULL, &ai)))
+    {
+      LOG (GNUNET_ERROR_TYPE_ERROR,
+           _("Could not resolve our FQDN: %s\n"),
+           gai_strerror (ret));
+      return NULL;
+    }
+    rval = GNUNET_strdup (ai->ai_canonname);
+    freeaddrinfo (ai);
+    return rval;
   }
-  return GNUNET_strdup (host->h_name);
+#elif HAVE_GETHOSTBYNAME2
+  {
+    struct hostent *host;
+
+    host = gethostbyname2 (hostname, AF_INET);
+    if (NULL == host)
+      host = gethostbyname2 (hostname, AF_INET6);
+    if (NULL == host)
+      {
+        LOG (GNUNET_ERROR_TYPE_ERROR,
+             _("Could not resolve our FQDN: %s\n"),
+             hstrerror (h_errno));
+        return NULL;
+      }
+    return GNUNET_strdup (host->h_name);
+  }
+#elif HAVE_GETHOSTBYNAME
+  {
+    struct hostent *host;
+
+    host = gethostbyname (hostname);
+    if (NULL == host)
+      {
+        LOG (GNUNET_ERROR_TYPE_ERROR,
+             _("Could not resolve our FQDN: %s\n"),
+             hstrerror (h_errno));
+        return NULL;
+      }
+    return GNUNET_strdup (host->h_name);
+  }
+#else
+  /* fallback: just hope name is already FQDN */
+  return GNUNET_strdup (hostname);
+#endif
 }
 
 

Modified: gnunet/src/util/test_resolver_api.c
===================================================================
--- gnunet/src/util/test_resolver_api.c 2015-06-28 13:53:42 UTC (rev 36019)
+++ gnunet/src/util/test_resolver_api.c 2015-06-29 08:00:26 UTC (rev 36020)
@@ -137,45 +137,6 @@
 
 
 static void
-check_local_fqdn (void *cls, const char *gnunet_fqdn)
-{
-  int result = 0;
-
-  struct hostent *host;
-  char hostname[GNUNET_OS_get_hostname_max_length () + 1];
-
-  if (0 != gethostname (hostname, sizeof (hostname) - 1))
-  {
-    GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
-                         "gethostname");
-    return;
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Resolving our FQDN `%s'\n",
-              hostname);
-  host = gethostbyname (hostname);
-  if (NULL == host)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Could not resolve our FQDN: %s %u\n",
-                hstrerror (h_errno),
-                h_errno);
-    return;
-  }
-
-  GNUNET_assert (0 != host);
-
-  result = strcmp (host->h_name, gnunet_fqdn);
-  if (0 != result)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Local resolved and resolver resolved fqdns are not equal\n");
-  }
-  GNUNET_assert (0 == result);
-}
-
-
-static void
 check_rootserver_ip (void *cls, const struct sockaddr *sa, socklen_t salen)
 {
   int *ok = cls;
@@ -252,7 +213,8 @@
    * Looking up our own fqdn
    */
   own_fqdn = GNUNET_RESOLVER_local_fqdn_get ();
-  check_local_fqdn (NULL, own_fqdn);
+  /* can't really check, only thing we can safely
+     compare against is our own identical logic... */
   GNUNET_free_non_null (own_fqdn);
 
   /*




reply via email to

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