diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-06-07 17:57:19 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-06-07 17:57:19 +0000 |
commit | 84d6a0db5e92d043dcf0914378e681579cabd682 (patch) | |
tree | 91c36f55b18c2c4049d2ec8ca8401265fab276e8 /src/util | |
parent | 8fc6aab8c74124130c95d58192072a7eba59028c (diff) | |
download | gnunet-84d6a0db5e92d043dcf0914378e681579cabd682.tar.gz gnunet-84d6a0db5e92d043dcf0914378e681579cabd682.zip |
-return IP in dotted decimal if reverse lookup fails
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/gnunet-service-resolver.c | 59 | ||||
-rw-r--r-- | src/util/resolver_api.c | 27 |
2 files changed, 66 insertions, 20 deletions
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c index 1ca37f8c8..067dfefc9 100644 --- a/src/util/gnunet-service-resolver.c +++ b/src/util/gnunet-service-resolver.c | |||
@@ -101,6 +101,7 @@ getnameinfo_resolve (struct IPCache *cache) | |||
101 | struct sockaddr_in v4; | 101 | struct sockaddr_in v4; |
102 | struct sockaddr_in6 v6; | 102 | struct sockaddr_in6 v6; |
103 | size_t salen; | 103 | size_t salen; |
104 | int ret; | ||
104 | 105 | ||
105 | switch (cache->af) | 106 | switch (cache->af) |
106 | { | 107 | { |
@@ -131,13 +132,19 @@ getnameinfo_resolve (struct IPCache *cache) | |||
131 | } | 132 | } |
132 | 133 | ||
133 | if (0 == | 134 | if (0 == |
134 | getnameinfo (sa, salen, | 135 | (ret = getnameinfo (sa, salen, |
135 | hostname, sizeof (hostname), | 136 | hostname, sizeof (hostname), |
136 | NULL, | 137 | NULL, |
137 | 0, 0)) | 138 | 0, 0))) |
138 | { | 139 | { |
139 | cache->addr = GNUNET_strdup (hostname); | 140 | cache->addr = GNUNET_strdup (hostname); |
140 | } | 141 | } |
142 | else | ||
143 | { | ||
144 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
145 | "getnameinfo failed: %s\n", | ||
146 | gai_strerror (ret)); | ||
147 | } | ||
141 | } | 148 | } |
142 | #endif | 149 | #endif |
143 | 150 | ||
@@ -160,6 +167,12 @@ gethostbyaddr_resolve (struct IPCache *cache) | |||
160 | { | 167 | { |
161 | cache->addr = GNUNET_strdup (ent->h_name); | 168 | cache->addr = GNUNET_strdup (ent->h_name); |
162 | } | 169 | } |
170 | else | ||
171 | { | ||
172 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
173 | "gethostbyaddr failed: %s\n", | ||
174 | hstrerror (h_errno)); | ||
175 | } | ||
163 | } | 176 | } |
164 | #endif | 177 | #endif |
165 | 178 | ||
@@ -269,6 +282,9 @@ get_ip_as_string (struct GNUNET_SERVER_Client *client, | |||
269 | GNUNET_SERVER_transmit_context_append_data (tc, pos->addr, | 282 | GNUNET_SERVER_transmit_context_append_data (tc, pos->addr, |
270 | strlen (pos->addr) + 1, | 283 | strlen (pos->addr) + 1, |
271 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 284 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
285 | else | ||
286 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
287 | "Reverse lookup failed\n"); | ||
272 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | 288 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, |
273 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 289 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
274 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | 290 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
@@ -307,7 +323,8 @@ getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc, | |||
307 | 323 | ||
308 | if (0 != (s = getaddrinfo (hostname, NULL, &hints, &result))) | 324 | if (0 != (s = getaddrinfo (hostname, NULL, &hints, &result))) |
309 | { | 325 | { |
310 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Could not resolve `%s' (%s): %s\n"), | 326 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
327 | _("Could not resolve `%s' (%s): %s\n"), | ||
311 | hostname, | 328 | hostname, |
312 | (af == | 329 | (af == |
313 | AF_INET) ? "IPv4" : ((af == AF_INET6) ? "IPv6" : "any"), | 330 | AF_INET) ? "IPv4" : ((af == AF_INET6) ? "IPv6" : "any"), |
@@ -354,7 +371,8 @@ getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc, | |||
354 | #if HAVE_GETHOSTBYNAME2 | 371 | #if HAVE_GETHOSTBYNAME2 |
355 | static int | 372 | static int |
356 | gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc, | 373 | gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc, |
357 | const char *hostname, int af) | 374 | const char *hostname, |
375 | int af) | ||
358 | { | 376 | { |
359 | struct hostent *hp; | 377 | struct hostent *hp; |
360 | int ret1; | 378 | int ret1; |
@@ -417,10 +435,11 @@ gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc, | |||
417 | struct hostent *hp; | 435 | struct hostent *hp; |
418 | 436 | ||
419 | hp = GETHOSTBYNAME (hostname); | 437 | hp = GETHOSTBYNAME (hostname); |
420 | if (hp == NULL) | 438 | if (NULL == hp) |
421 | { | 439 | { |
422 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 440 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
423 | _("Could not find IP of host `%s': %s\n"), hostname, | 441 | _("Could not find IP of host `%s': %s\n"), |
442 | hostname, | ||
424 | hstrerror (h_errno)); | 443 | hstrerror (h_errno)); |
425 | return GNUNET_SYSERR; | 444 | return GNUNET_SYSERR; |
426 | } | 445 | } |
@@ -497,14 +516,15 @@ handle_get (void *cls, | |||
497 | if (msize < sizeof (struct GNUNET_RESOLVER_GetMessage)) | 516 | if (msize < sizeof (struct GNUNET_RESOLVER_GetMessage)) |
498 | { | 517 | { |
499 | GNUNET_break (0); | 518 | GNUNET_break (0); |
500 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 519 | GNUNET_SERVER_receive_done (client, |
520 | GNUNET_SYSERR); | ||
501 | return; | 521 | return; |
502 | } | 522 | } |
503 | msg = (const struct GNUNET_RESOLVER_GetMessage *) message; | 523 | msg = (const struct GNUNET_RESOLVER_GetMessage *) message; |
504 | size = msize - sizeof (struct GNUNET_RESOLVER_GetMessage); | 524 | size = msize - sizeof (struct GNUNET_RESOLVER_GetMessage); |
505 | direction = ntohl (msg->direction); | 525 | direction = ntohl (msg->direction); |
506 | af = ntohl (msg->af); | 526 | af = ntohl (msg->af); |
507 | if (direction == GNUNET_NO) | 527 | if (GNUNET_NO == direction) |
508 | { | 528 | { |
509 | /* IP from hostname */ | 529 | /* IP from hostname */ |
510 | const char *hostname; | 530 | const char *hostname; |
@@ -513,10 +533,12 @@ handle_get (void *cls, | |||
513 | if (hostname[size - 1] != '\0') | 533 | if (hostname[size - 1] != '\0') |
514 | { | 534 | { |
515 | GNUNET_break (0); | 535 | GNUNET_break (0); |
516 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 536 | GNUNET_SERVER_receive_done (client, |
537 | GNUNET_SYSERR); | ||
517 | return; | 538 | return; |
518 | } | 539 | } |
519 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Resolver asked to look up `%s'.\n", | 540 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
541 | "Resolver asked to look up `%s'.\n", | ||
520 | hostname); | 542 | hostname); |
521 | get_ip_from_hostname (client, hostname, af); | 543 | get_ip_from_hostname (client, hostname, af); |
522 | return; | 544 | return; |
@@ -528,7 +550,8 @@ handle_get (void *cls, | |||
528 | if (size != sizeof (struct in_addr)) | 550 | if (size != sizeof (struct in_addr)) |
529 | { | 551 | { |
530 | GNUNET_break (0); | 552 | GNUNET_break (0); |
531 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 553 | GNUNET_SERVER_receive_done (client, |
554 | GNUNET_SYSERR); | ||
532 | return; | 555 | return; |
533 | } | 556 | } |
534 | break; | 557 | break; |
@@ -536,13 +559,15 @@ handle_get (void *cls, | |||
536 | if (size != sizeof (struct in6_addr)) | 559 | if (size != sizeof (struct in6_addr)) |
537 | { | 560 | { |
538 | GNUNET_break (0); | 561 | GNUNET_break (0); |
539 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 562 | GNUNET_SERVER_receive_done (client, |
563 | GNUNET_SYSERR); | ||
540 | return; | 564 | return; |
541 | } | 565 | } |
542 | break; | 566 | break; |
543 | default: | 567 | default: |
544 | GNUNET_break (0); | 568 | GNUNET_break (0); |
545 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 569 | GNUNET_SERVER_receive_done (client, |
570 | GNUNET_SYSERR); | ||
546 | return; | 571 | return; |
547 | } | 572 | } |
548 | { | 573 | { |
@@ -590,7 +615,9 @@ main (int argc, char *const *argv) | |||
590 | 615 | ||
591 | ret = | 616 | ret = |
592 | (GNUNET_OK == | 617 | (GNUNET_OK == |
593 | GNUNET_SERVICE_run (argc, argv, "resolver", GNUNET_SERVICE_OPTION_NONE, | 618 | GNUNET_SERVICE_run (argc, argv, |
619 | "resolver", | ||
620 | GNUNET_SERVICE_OPTION_NONE, | ||
594 | &run, NULL)) ? 0 : 1; | 621 | &run, NULL)) ? 0 : 1; |
595 | while (NULL != (pos = cache_head)) | 622 | while (NULL != (pos = cache_head)) |
596 | { | 623 | { |
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c index 493fe046e..3469739e1 100644 --- a/src/util/resolver_api.c +++ b/src/util/resolver_api.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009-2014 Christian Grothoff (and other contributing authors) | 3 | Copyright (C) 2009-2015 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -78,13 +78,13 @@ static struct GNUNET_TIME_Relative backoff; | |||
78 | /** | 78 | /** |
79 | * Task for reconnecting. | 79 | * Task for reconnecting. |
80 | */ | 80 | */ |
81 | static struct GNUNET_SCHEDULER_Task * r_task; | 81 | static struct GNUNET_SCHEDULER_Task *r_task; |
82 | 82 | ||
83 | /** | 83 | /** |
84 | * Task ID of shutdown task; only present while we have a | 84 | * Task ID of shutdown task; only present while we have a |
85 | * connection to the resolver service. | 85 | * connection to the resolver service. |
86 | */ | 86 | */ |
87 | static struct GNUNET_SCHEDULER_Task * s_task; | 87 | static struct GNUNET_SCHEDULER_Task *s_task; |
88 | 88 | ||
89 | 89 | ||
90 | /** | 90 | /** |
@@ -401,13 +401,27 @@ handle_response (void *cls, | |||
401 | size = ntohs (msg->size); | 401 | size = ntohs (msg->size); |
402 | if (size == sizeof (struct GNUNET_MessageHeader)) | 402 | if (size == sizeof (struct GNUNET_MessageHeader)) |
403 | { | 403 | { |
404 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
405 | "Received empty response from DNS service\n"); | ||
404 | /* message contains not data, just header; end of replies */ | 406 | /* message contains not data, just header; end of replies */ |
405 | /* check if request was canceled */ | 407 | /* check if request was canceled */ |
406 | if (GNUNET_SYSERR != rh->was_transmitted) | 408 | if (GNUNET_SYSERR != rh->was_transmitted) |
407 | { | 409 | { |
410 | /* no reverse lookup was successful, return IP as string */ | ||
408 | if (NULL != rh->name_callback) | 411 | if (NULL != rh->name_callback) |
412 | { | ||
413 | if (GNUNET_NO == rh->received_response) | ||
414 | { | ||
415 | nret = no_resolve (rh->af, | ||
416 | &rh[1], | ||
417 | rh->data_len); | ||
418 | rh->name_callback (rh->cls, nret); | ||
419 | GNUNET_free (nret); | ||
420 | } | ||
421 | /* finally, make termination call */ | ||
409 | rh->name_callback (rh->cls, | 422 | rh->name_callback (rh->cls, |
410 | NULL); | 423 | NULL); |
424 | } | ||
411 | if (NULL != rh->addr_callback) | 425 | if (NULL != rh->addr_callback) |
412 | rh->addr_callback (rh->cls, | 426 | rh->addr_callback (rh->cls, |
413 | NULL, | 427 | NULL, |
@@ -495,6 +509,8 @@ handle_response (void *cls, | |||
495 | reconnect (); | 509 | reconnect (); |
496 | return; | 510 | return; |
497 | } | 511 | } |
512 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
513 | "Received IP from DNS service\n"); | ||
498 | if (GNUNET_SYSERR != rh->was_transmitted) | 514 | if (GNUNET_SYSERR != rh->was_transmitted) |
499 | rh->addr_callback (rh->cls, | 515 | rh->addr_callback (rh->cls, |
500 | sa, | 516 | sa, |
@@ -810,7 +826,8 @@ handle_lookup_timeout (void *cls, | |||
810 | * @return handle that can be used to cancel the request, NULL on error | 826 | * @return handle that can be used to cancel the request, NULL on error |
811 | */ | 827 | */ |
812 | struct GNUNET_RESOLVER_RequestHandle * | 828 | struct GNUNET_RESOLVER_RequestHandle * |
813 | GNUNET_RESOLVER_ip_get (const char *hostname, int af, | 829 | GNUNET_RESOLVER_ip_get (const char *hostname, |
830 | int af, | ||
814 | struct GNUNET_TIME_Relative timeout, | 831 | struct GNUNET_TIME_Relative timeout, |
815 | GNUNET_RESOLVER_AddressCallback callback, | 832 | GNUNET_RESOLVER_AddressCallback callback, |
816 | void *callback_cls) | 833 | void *callback_cls) |
@@ -938,10 +955,12 @@ GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa, | |||
938 | switch (sa->sa_family) | 955 | switch (sa->sa_family) |
939 | { | 956 | { |
940 | case AF_INET: | 957 | case AF_INET: |
958 | GNUNET_assert (salen == sizeof (struct sockaddr_in)); | ||
941 | ip_len = sizeof (struct in_addr); | 959 | ip_len = sizeof (struct in_addr); |
942 | ip = &((const struct sockaddr_in*)sa)->sin_addr; | 960 | ip = &((const struct sockaddr_in*)sa)->sin_addr; |
943 | break; | 961 | break; |
944 | case AF_INET6: | 962 | case AF_INET6: |
963 | GNUNET_assert (salen == sizeof (struct sockaddr_in6)); | ||
945 | ip_len = sizeof (struct in6_addr); | 964 | ip_len = sizeof (struct in6_addr); |
946 | ip = &((const struct sockaddr_in6*)sa)->sin6_addr; | 965 | ip = &((const struct sockaddr_in6*)sa)->sin6_addr; |
947 | break; | 966 | break; |