aboutsummaryrefslogtreecommitdiff
path: root/src/util/resolver_api.c
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/util/resolver_api.c
parent2a6b06943962c4978a0afb89f1eed141e142a76f (diff)
-fix #3870
Diffstat (limited to 'src/util/resolver_api.c')
-rw-r--r--src/util/resolver_api.c57
1 files changed, 49 insertions, 8 deletions
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c
index 3469739e1f..c1d8c8836f 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
}