aboutsummaryrefslogtreecommitdiff
path: root/src/util/resolver_api.c
diff options
context:
space:
mode:
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 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,
1004char * 1004char *
1005GNUNET_RESOLVER_local_fqdn_get () 1005GNUNET_RESOLVER_local_fqdn_get ()
1006{ 1006{
1007 struct hostent *host;
1008 char hostname[GNUNET_OS_get_hostname_max_length () + 1]; 1007 char hostname[GNUNET_OS_get_hostname_max_length () + 1];
1009 1008
1010 if (0 != gethostname (hostname, sizeof (hostname) - 1)) 1009 if (0 != gethostname (hostname, sizeof (hostname) - 1))
@@ -1016,15 +1015,57 @@ GNUNET_RESOLVER_local_fqdn_get ()
1016 LOG (GNUNET_ERROR_TYPE_DEBUG, 1015 LOG (GNUNET_ERROR_TYPE_DEBUG,
1017 "Resolving our FQDN `%s'\n", 1016 "Resolving our FQDN `%s'\n",
1018 hostname); 1017 hostname);
1019 host = gethostbyname (hostname); 1018#if HAVE_GETADDRINFO
1020 if (NULL == host)
1021 { 1019 {
1022 LOG (GNUNET_ERROR_TYPE_ERROR, 1020 struct addrinfo *ai;
1023 _("Could not resolve our FQDN : %s\n"), 1021 int ret;
1024 hstrerror (h_errno)); 1022 char *rval;
1025 return NULL; 1023
1024 if (0 != (ret = getaddrinfo (hostname, NULL, NULL, &ai)))
1025 {
1026 LOG (GNUNET_ERROR_TYPE_ERROR,
1027 _("Could not resolve our FQDN: %s\n"),
1028 gai_strerror (ret));
1029 return NULL;
1030 }
1031 rval = GNUNET_strdup (ai->ai_canonname);
1032 freeaddrinfo (ai);
1033 return rval;
1026 } 1034 }
1027 return GNUNET_strdup (host->h_name); 1035#elif HAVE_GETHOSTBYNAME2
1036 {
1037 struct hostent *host;
1038
1039 host = gethostbyname2 (hostname, AF_INET);
1040 if (NULL == host)
1041 host = gethostbyname2 (hostname, AF_INET6);
1042 if (NULL == host)
1043 {
1044 LOG (GNUNET_ERROR_TYPE_ERROR,
1045 _("Could not resolve our FQDN: %s\n"),
1046 hstrerror (h_errno));
1047 return NULL;
1048 }
1049 return GNUNET_strdup (host->h_name);
1050 }
1051#elif HAVE_GETHOSTBYNAME
1052 {
1053 struct hostent *host;
1054
1055 host = gethostbyname (hostname);
1056 if (NULL == host)
1057 {
1058 LOG (GNUNET_ERROR_TYPE_ERROR,
1059 _("Could not resolve our FQDN: %s\n"),
1060 hstrerror (h_errno));
1061 return NULL;
1062 }
1063 return GNUNET_strdup (host->h_name);
1064 }
1065#else
1066 /* fallback: just hope name is already FQDN */
1067 return GNUNET_strdup (hostname);
1068#endif
1028} 1069}
1029 1070
1030 1071