diff options
Diffstat (limited to 'src/nat/nat_stun.c')
-rw-r--r-- | src/nat/nat_stun.c | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/src/nat/nat_stun.c b/src/nat/nat_stun.c index 4aa9094ea..b914abb2e 100644 --- a/src/nat/nat_stun.c +++ b/src/nat/nat_stun.c | |||
@@ -461,9 +461,9 @@ stun_dns_callback (void *cls, | |||
461 | int reqlen; | 461 | int reqlen; |
462 | struct sockaddr_in server; | 462 | struct sockaddr_in server; |
463 | 463 | ||
464 | rh->dns_active = NULL; | ||
465 | if (NULL == addr) | 464 | if (NULL == addr) |
466 | { | 465 | { |
466 | rh->dns_active = NULL; | ||
467 | if (GNUNET_NO == rh->dns_success) | 467 | if (GNUNET_NO == rh->dns_success) |
468 | { | 468 | { |
469 | LOG (GNUNET_ERROR_TYPE_INFO, | 469 | LOG (GNUNET_ERROR_TYPE_INFO, |
@@ -471,8 +471,18 @@ stun_dns_callback (void *cls, | |||
471 | rh->stun_server); | 471 | rh->stun_server); |
472 | rh->cb (rh->cb_cls, | 472 | rh->cb (rh->cb_cls, |
473 | GNUNET_NAT_ERROR_NOT_ONLINE); | 473 | GNUNET_NAT_ERROR_NOT_ONLINE); |
474 | GNUNET_NAT_stun_make_request_cancel (rh); | ||
475 | } | 474 | } |
475 | else if (GNUNET_SYSERR == rh->dns_success) | ||
476 | { | ||
477 | rh->cb (rh->cb_cls, | ||
478 | GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR); | ||
479 | } | ||
480 | else | ||
481 | { | ||
482 | rh->cb (rh->cb_cls, | ||
483 | GNUNET_NAT_ERROR_SUCCESS); | ||
484 | } | ||
485 | GNUNET_NAT_stun_make_request_cancel (rh); | ||
476 | return; | 486 | return; |
477 | } | 487 | } |
478 | 488 | ||
@@ -487,31 +497,27 @@ stun_dns_callback (void *cls, | |||
487 | 497 | ||
488 | /*Craft the simplest possible STUN packet. A request binding*/ | 498 | /*Craft the simplest possible STUN packet. A request binding*/ |
489 | req = (struct stun_header *)reqdata; | 499 | req = (struct stun_header *)reqdata; |
490 | generate_request_id(req); | 500 | generate_request_id (req); |
491 | reqlen = 0; | 501 | reqlen = 0; |
492 | req->msgtype = 0; | 502 | req->msgtype = 0; |
493 | req->msglen = 0; | 503 | req->msglen = 0; |
494 | req->msglen = htons(reqlen); | 504 | req->msglen = htons (reqlen); |
495 | req->msgtype = htons(encode_message(STUN_REQUEST, STUN_BINDING)); | 505 | req->msgtype = htons (encode_message (STUN_REQUEST, |
506 | STUN_BINDING)); | ||
496 | 507 | ||
497 | /* Send the packet */ | 508 | /* Send the packet */ |
498 | if (-1 == GNUNET_NETWORK_socket_sendto (rh->sock, | 509 | if (-1 == |
499 | req, | 510 | GNUNET_NETWORK_socket_sendto (rh->sock, |
500 | ntohs(req->msglen) + sizeof(*req), | 511 | req, |
501 | (const struct sockaddr *) &server, | 512 | ntohs(req->msglen) + sizeof(*req), |
502 | sizeof (server))) | 513 | (const struct sockaddr *) &server, |
514 | sizeof (server))) | ||
503 | { | 515 | { |
504 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | 516 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, |
505 | "Fail to sendto"); | 517 | "sendto"); |
506 | rh->cb (rh->cb_cls, | 518 | rh->dns_success = GNUNET_SYSERR; |
507 | GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR); | ||
508 | GNUNET_NAT_stun_make_request_cancel (rh); | ||
509 | return; | 519 | return; |
510 | } | 520 | } |
511 | /* sending STUN request done, let's wait for replies... */ | ||
512 | rh->cb (rh->cb_cls, | ||
513 | GNUNET_NAT_ERROR_SUCCESS); | ||
514 | GNUNET_NAT_stun_make_request_cancel (rh); | ||
515 | } | 521 | } |
516 | 522 | ||
517 | 523 | ||
@@ -550,8 +556,6 @@ GNUNET_NAT_stun_make_request (const char *server, | |||
550 | &stun_dns_callback, rh); | 556 | &stun_dns_callback, rh); |
551 | if (NULL == rh->dns_active) | 557 | if (NULL == rh->dns_active) |
552 | { | 558 | { |
553 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | ||
554 | "Failed DNS"); | ||
555 | GNUNET_NAT_stun_make_request_cancel (rh); | 559 | GNUNET_NAT_stun_make_request_cancel (rh); |
556 | return NULL; | 560 | return NULL; |
557 | } | 561 | } |