summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-06-29 08:00:26 +0000
committerChristian Grothoff <christian@grothoff.org>2015-06-29 08:00:26 +0000
commit65f518e8036699fa3c574266d39e3cd1263af9e8 (patch)
tree7564ed41e2620563bfa7e6dc89dac98cde4c88a1 /src
parent2a6b06943962c4978a0afb89f1eed141e142a76f (diff)
-fix #3870
Diffstat (limited to 'src')
-rw-r--r--src/arm/test_gnunet_service_arm.c51
-rw-r--r--src/gns/gnunet-service-gns_resolver.c2
-rw-r--r--src/util/gnunet-service-resolver.c15
-rw-r--r--src/util/resolver_api.c57
-rw-r--r--src/util/test_resolver_api.c42
5 files changed, 105 insertions, 62 deletions
diff --git a/src/arm/test_gnunet_service_arm.c b/src/arm/test_gnunet_service_arm.c
index 3e4b9db49..199ea6d85 100644
--- a/src/arm/test_gnunet_service_arm.c
+++ b/src/arm/test_gnunet_service_arm.c
@@ -214,13 +214,54 @@ main (int argc, char *av[])
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);
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index 058c64e44..12bbd4991 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -168,7 +168,7 @@ struct DnsResult
/**
* 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;
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c
index ec56292a8..ebfdc7c4c 100644
--- a/src/util/gnunet-service-resolver.c
+++ b/src/util/gnunet-service-resolver.c
@@ -365,10 +365,11 @@ getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc,
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 @@ gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc,
}
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 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client,
#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
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c
index 3469739e1..c1d8c8836 100644
--- a/src/util/resolver_api.c
+++ b/src/util/resolver_api.c
@@ -1004,7 +1004,6 @@ GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa,
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 @@ GNUNET_RESOLVER_local_fqdn_get ()
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
}
diff --git a/src/util/test_resolver_api.c b/src/util/test_resolver_api.c
index 1979067f0..0652625f5 100644
--- a/src/util/test_resolver_api.c
+++ b/src/util/test_resolver_api.c
@@ -137,45 +137,6 @@ check_127 (void *cls, const struct sockaddr *sa, socklen_t salen)
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 @@ run (void *cls, char *const *args, const char *cfgfile,
* 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);
/*