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/gnunet-service-resolver.c | |
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/gnunet-service-resolver.c')
-rw-r--r-- | src/util/gnunet-service-resolver.c | 59 |
1 files changed, 43 insertions, 16 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 | { |