aboutsummaryrefslogtreecommitdiff
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)
downloadgnunet-65f518e8036699fa3c574266d39e3cd1263af9e8.tar.gz
gnunet-65f518e8036699fa3c574266d39e3cd1263af9e8.zip
-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[])
214 strcpy (hostname, 214 strcpy (hostname,
215 "www.gnu.org"); 215 "www.gnu.org");
216 } 216 }
217 if (NULL == gethostbyname (hostname)) 217 /* trigger DNS lookup */
218#if HAVE_GETADDRINFO
218 { 219 {
219 FPRINTF (stderr, 220 struct addrinfo *ai;
220 "Failed to resolve my hostname `%s', testcase not run.\n", 221 int ret;
221 hostname); 222
222 return 0; 223 if (0 != (ret = getaddrinfo (hostname, NULL, NULL, &ai)))
224 {
225 FPRINTF (stderr,
226 "Failed to resolve my hostname `%s', testcase not run.\n",
227 hostname);
228 return 0;
229 }
230 freeaddrinfo (ai);
231 }
232#elif HAVE_GETHOSTBYNAME2
233 {
234 struct hostent *host;
235
236 host = gethostbyname2 (hostname, AF_INET);
237 if (NULL == host)
238 host = gethostbyname2 (hostname, AF_INET6);
239 if (NULL == host)
240 {
241 FPRINTF (stderr,
242 "Failed to resolve my hostname `%s', testcase not run.\n",
243 hostname);
244 return 0;
245 }
246 }
247#elif HAVE_GETHOSTBYNAME
248 {
249 struct hostent *host;
250
251 host = gethostbyname (hostname);
252 if (NULL == host)
253 {
254 FPRINTF (stderr,
255 "Failed to resolve my hostname `%s', testcase not run.\n",
256 hostname);
257 return 0;
258 }
223 } 259 }
260#else
261 FPRINTF (stderr,
262 "libc fails to have resolver function, testcase not run.\n");
263 return 0;
264#endif
224 GNUNET_log_setup ("test-gnunet-service-arm", 265 GNUNET_log_setup ("test-gnunet-service-arm",
225 "WARNING", 266 "WARNING",
226 NULL); 267 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
168 168
169 /** 169 /**
170 * Expiration time for the DNS record, 0 if we didn't 170 * Expiration time for the DNS record, 0 if we didn't
171 * get anything useful (i.e. 'gethostbyname' was used). 171 * get anything useful (i.e. 'gethostbyname()' was used).
172 */ 172 */
173 uint64_t expiration_time; 173 uint64_t expiration_time;
174 174
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,
365 freeaddrinfo (result); 365 freeaddrinfo (result);
366 return GNUNET_OK; 366 return GNUNET_OK;
367} 367}
368#endif
369 368
370 369
371#if HAVE_GETHOSTBYNAME2 370#elif HAVE_GETHOSTBYNAME2
371
372
372static int 373static int
373gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc, 374gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc,
374 const char *hostname, 375 const char *hostname,
@@ -424,10 +425,10 @@ gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc,
424 } 425 }
425 return GNUNET_OK; 426 return GNUNET_OK;
426} 427}
427#endif 428
429#elif HAVE_GETHOSTBYNAME
428 430
429 431
430#if HAVE_GETHOSTBYNAME
431static int 432static int
432gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc, 433gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc,
433 const char *hostname) 434 const char *hostname)
@@ -478,12 +479,10 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client,
478#if HAVE_GETADDRINFO 479#if HAVE_GETADDRINFO
479 if (ret == GNUNET_NO) 480 if (ret == GNUNET_NO)
480 ret = getaddrinfo_resolve (tc, hostname, af); 481 ret = getaddrinfo_resolve (tc, hostname, af);
481#endif 482#elif HAVE_GETHOSTBYNAME2
482#if HAVE_GETHOSTBYNAME2
483 if (ret == GNUNET_NO) 483 if (ret == GNUNET_NO)
484 ret = gethostbyname2_resolve (tc, hostname, af); 484 ret = gethostbyname2_resolve (tc, hostname, af);
485#endif 485#elif HAVE_GETHOSTBYNAME
486#if HAVE_GETHOSTBYNAME
487 if ((ret == GNUNET_NO) && ((af == AF_UNSPEC) || (af == PF_INET))) 486 if ((ret == GNUNET_NO) && ((af == AF_UNSPEC) || (af == PF_INET)))
488 gethostbyname_resolve (tc, hostname); 487 gethostbyname_resolve (tc, hostname);
489#endif 488#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,
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
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)
137 137
138 138
139static void 139static void
140check_local_fqdn (void *cls, const char *gnunet_fqdn)
141{
142 int result = 0;
143
144 struct hostent *host;
145 char hostname[GNUNET_OS_get_hostname_max_length () + 1];
146
147 if (0 != gethostname (hostname, sizeof (hostname) - 1))
148 {
149 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
150 "gethostname");
151 return;
152 }
153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
154 "Resolving our FQDN `%s'\n",
155 hostname);
156 host = gethostbyname (hostname);
157 if (NULL == host)
158 {
159 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
160 "Could not resolve our FQDN: %s %u\n",
161 hstrerror (h_errno),
162 h_errno);
163 return;
164 }
165
166 GNUNET_assert (0 != host);
167
168 result = strcmp (host->h_name, gnunet_fqdn);
169 if (0 != result)
170 {
171 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
172 "Local resolved and resolver resolved fqdns are not equal\n");
173 }
174 GNUNET_assert (0 == result);
175}
176
177
178static void
179check_rootserver_ip (void *cls, const struct sockaddr *sa, socklen_t salen) 140check_rootserver_ip (void *cls, const struct sockaddr *sa, socklen_t salen)
180{ 141{
181 int *ok = cls; 142 int *ok = cls;
@@ -252,7 +213,8 @@ run (void *cls, char *const *args, const char *cfgfile,
252 * Looking up our own fqdn 213 * Looking up our own fqdn
253 */ 214 */
254 own_fqdn = GNUNET_RESOLVER_local_fqdn_get (); 215 own_fqdn = GNUNET_RESOLVER_local_fqdn_get ();
255 check_local_fqdn (NULL, own_fqdn); 216 /* can't really check, only thing we can safely
217 compare against is our own identical logic... */
256 GNUNET_free_non_null (own_fqdn); 218 GNUNET_free_non_null (own_fqdn);
257 219
258 /* 220 /*