aboutsummaryrefslogtreecommitdiff
path: root/src/util/gnunet-service-resolver.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/gnunet-service-resolver.c')
-rw-r--r--src/util/gnunet-service-resolver.c71
1 files changed, 31 insertions, 40 deletions
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c
index f49ec3882..5d4c5c224 100644
--- a/src/util/gnunet-service-resolver.c
+++ b/src/util/gnunet-service-resolver.c
@@ -87,8 +87,9 @@ getnameinfo_resolve (struct IPCache *cache)
87{ 87{
88 char hostname[256]; 88 char hostname[256];
89 89
90 if (0 == getnameinfo (cache->sa, 90 if (0 ==
91 cache->salen, hostname, sizeof (hostname), NULL, 0, 0)) 91 getnameinfo (cache->sa, cache->salen, hostname, sizeof (hostname), NULL,
92 0, 0))
92 cache->addr = GNUNET_strdup (hostname); 93 cache->addr = GNUNET_strdup (hostname);
93} 94}
94#endif 95#endif
@@ -108,12 +109,14 @@ gethostbyaddr_resolve (struct IPCache *cache)
108 switch (cache->sa->sa_family) 109 switch (cache->sa->sa_family)
109 { 110 {
110 case AF_INET: 111 case AF_INET:
111 ent = gethostbyaddr (&((struct sockaddr_in *) cache->sa)->sin_addr, 112 ent =
112 sizeof (struct in_addr), AF_INET); 113 gethostbyaddr (&((struct sockaddr_in *) cache->sa)->sin_addr,
114 sizeof (struct in_addr), AF_INET);
113 break; 115 break;
114 case AF_INET6: 116 case AF_INET6:
115 ent = gethostbyaddr (&((struct sockaddr_in6 *) cache->sa)->sin6_addr, 117 ent =
116 sizeof (struct in6_addr), AF_INET6); 118 gethostbyaddr (&((struct sockaddr_in6 *) cache->sa)->sin6_addr,
119 sizeof (struct in6_addr), AF_INET6);
117 break; 120 break;
118 default: 121 default:
119 ent = NULL; 122 ent = NULL;
@@ -225,8 +228,7 @@ get_ip_as_string (struct GNUNET_SERVER_Client *client,
225 } 228 }
226 tc = GNUNET_SERVER_transmit_context_create (client); 229 tc = GNUNET_SERVER_transmit_context_create (client);
227 if (cache->addr != NULL) 230 if (cache->addr != NULL)
228 GNUNET_SERVER_transmit_context_append_data (tc, 231 GNUNET_SERVER_transmit_context_append_data (tc, cache->addr,
229 cache->addr,
230 strlen (cache->addr) + 1, 232 strlen (cache->addr) + 1,
231 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 233 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
232 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 234 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
@@ -256,11 +258,10 @@ getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc,
256 258
257 if (0 != (s = getaddrinfo (hostname, NULL, &hints, &result))) 259 if (0 != (s = getaddrinfo (hostname, NULL, &hints, &result)))
258 { 260 {
259 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 261 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Could not resolve `%s' (%s): %s\n"),
260 _("Could not resolve `%s' (%s): %s\n"), hostname, 262 hostname,
261 (domain == 263 (domain ==
262 AF_INET) ? "IPv4" : ((domain == 264 AF_INET) ? "IPv4" : ((domain == AF_INET6) ? "IPv6" : "any"),
263 AF_INET6) ? "IPv6" : "any"),
264 gai_strerror (s)); 265 gai_strerror (s));
265 if ((s == EAI_BADFLAGS) || (s == EAI_MEMORY) 266 if ((s == EAI_BADFLAGS) || (s == EAI_MEMORY)
266#ifndef MINGW 267#ifndef MINGW
@@ -278,8 +279,7 @@ getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc,
278 pos = result; 279 pos = result;
279 while (pos != NULL) 280 while (pos != NULL)
280 { 281 {
281 GNUNET_SERVER_transmit_context_append_data (tc, 282 GNUNET_SERVER_transmit_context_append_data (tc, pos->ai_addr,
282 pos->ai_addr,
283 pos->ai_addrlen, 283 pos->ai_addrlen,
284 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 284 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
285 pos = pos->ai_next; 285 pos = pos->ai_next;
@@ -314,8 +314,8 @@ gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc,
314 if (hp == NULL) 314 if (hp == NULL)
315 { 315 {
316 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 316 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
317 _("Could not find IP of host `%s': %s\n"), 317 _("Could not find IP of host `%s': %s\n"), hostname,
318 hostname, hstrerror (h_errno)); 318 hstrerror (h_errno));
319 return GNUNET_SYSERR; 319 return GNUNET_SYSERR;
320 } 320 }
321 GNUNET_assert (hp->h_addrtype == domain); 321 GNUNET_assert (hp->h_addrtype == domain);
@@ -328,9 +328,7 @@ gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc,
328 a4.sin_len = (u_char) sizeof (struct sockaddr_in); 328 a4.sin_len = (u_char) sizeof (struct sockaddr_in);
329#endif 329#endif
330 memcpy (&a4.sin_addr, hp->h_addr_list[0], hp->h_length); 330 memcpy (&a4.sin_addr, hp->h_addr_list[0], hp->h_length);
331 GNUNET_SERVER_transmit_context_append_data (tc, 331 GNUNET_SERVER_transmit_context_append_data (tc, &a4, sizeof (a4),
332 &a4,
333 sizeof (a4),
334 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 332 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
335 } 333 }
336 else 334 else
@@ -342,9 +340,7 @@ gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc,
342 a6.sin6_len = (u_char) sizeof (struct sockaddr_in6); 340 a6.sin6_len = (u_char) sizeof (struct sockaddr_in6);
343#endif 341#endif
344 memcpy (&a6.sin6_addr, hp->h_addr_list[0], hp->h_length); 342 memcpy (&a6.sin6_addr, hp->h_addr_list[0], hp->h_length);
345 GNUNET_SERVER_transmit_context_append_data (tc, 343 GNUNET_SERVER_transmit_context_append_data (tc, &a6, sizeof (a6),
346 &a6,
347 sizeof (a6),
348 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 344 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
349 } 345 }
350 return GNUNET_OK; 346 return GNUNET_OK;
@@ -363,8 +359,8 @@ gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc,
363 if (hp == NULL) 359 if (hp == NULL)
364 { 360 {
365 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 361 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
366 _("Could not find IP of host `%s': %s\n"), 362 _("Could not find IP of host `%s': %s\n"), hostname,
367 hostname, hstrerror (h_errno)); 363 hstrerror (h_errno));
368 return GNUNET_SYSERR; 364 return GNUNET_SYSERR;
369 } 365 }
370 if (hp->h_addrtype != AF_INET) 366 if (hp->h_addrtype != AF_INET)
@@ -379,9 +375,7 @@ gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc,
379 addr.sin_len = (u_char) sizeof (struct sockaddr_in); 375 addr.sin_len = (u_char) sizeof (struct sockaddr_in);
380#endif 376#endif
381 memcpy (&addr.sin_addr, hp->h_addr_list[0], hp->h_length); 377 memcpy (&addr.sin_addr, hp->h_addr_list[0], hp->h_length);
382 GNUNET_SERVER_transmit_context_append_data (tc, 378 GNUNET_SERVER_transmit_context_append_data (tc, &addr, sizeof (addr),
383 &addr,
384 sizeof (addr),
385 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 379 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
386 return GNUNET_OK; 380 return GNUNET_OK;
387} 381}
@@ -396,8 +390,8 @@ gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc,
396 * @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any" 390 * @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any"
397 */ 391 */
398static void 392static void
399get_ip_from_hostname (struct GNUNET_SERVER_Client *client, 393get_ip_from_hostname (struct GNUNET_SERVER_Client *client, const char *hostname,
400 const char *hostname, int domain) 394 int domain)
401{ 395{
402 int ret; 396 int ret;
403 struct GNUNET_SERVER_TransmitContext *tc; 397 struct GNUNET_SERVER_TransmitContext *tc;
@@ -430,8 +424,7 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client,
430 * @param message the actual message 424 * @param message the actual message
431 */ 425 */
432static void 426static void
433handle_get (void *cls, 427handle_get (void *cls, struct GNUNET_SERVER_Client *client,
434 struct GNUNET_SERVER_Client *client,
435 const struct GNUNET_MessageHeader *message) 428 const struct GNUNET_MessageHeader *message)
436{ 429{
437 uint16_t msize; 430 uint16_t msize;
@@ -464,8 +457,8 @@ handle_get (void *cls,
464 return; 457 return;
465 } 458 }
466#if DEBUG_RESOLVER 459#if DEBUG_RESOLVER
467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 460 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolver asked to look up `%s'.\n"),
468 _("Resolver asked to look up `%s'.\n"), hostname); 461 hostname);
469#endif 462#endif
470 get_ip_from_hostname (client, hostname, domain); 463 get_ip_from_hostname (client, hostname, domain);
471 } 464 }
@@ -527,8 +520,7 @@ handle_get (void *cls,
527 * @param cfg configuration to use 520 * @param cfg configuration to use
528 */ 521 */
529static void 522static void
530run (void *cls, 523run (void *cls, struct GNUNET_SERVER_Handle *server,
531 struct GNUNET_SERVER_Handle *server,
532 const struct GNUNET_CONFIGURATION_Handle *cfg) 524 const struct GNUNET_CONFIGURATION_Handle *cfg)
533{ 525{
534 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 526 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
@@ -552,11 +544,10 @@ main (int argc, char *const *argv)
552 int ret; 544 int ret;
553 struct IPCache *pos; 545 struct IPCache *pos;
554 546
555 ret = (GNUNET_OK == 547 ret =
556 GNUNET_SERVICE_run (argc, 548 (GNUNET_OK ==
557 argv, 549 GNUNET_SERVICE_run (argc, argv, "resolver", GNUNET_SERVICE_OPTION_NONE,
558 "resolver", GNUNET_SERVICE_OPTION_NONE, 550 &run, NULL)) ? 0 : 1;
559 &run, NULL)) ? 0 : 1;
560 551
561 while (head != NULL) 552 while (head != NULL)
562 { 553 {