diff --git a/src/switch_nat.c b/src/switch_nat.c index d88aed5cd0..d46c4c7f4a 100644 --- a/src/switch_nat.c +++ b/src/switch_nat.c @@ -134,12 +134,15 @@ static int get_pmp_pubaddr(char *pub_addr) char *pubaddr = NULL; fd_set fds; natpmp_t natpmp; + const char *err = NULL; + + if ((r = initnatpmp(&natpmp)) < 0) { + err = "init failed"; + goto end; + } - - initnatpmp(&natpmp); - r = sendpublicaddressrequest(&natpmp); - - if (r < 0) { + if ((r = sendpublicaddressrequest(&natpmp)) < 0) { + err = "pub addr req failed"; goto end; } @@ -150,16 +153,24 @@ static int get_pmp_pubaddr(char *pub_addr) FD_ZERO(&fds); FD_SET(natpmp.s, &fds); - getnatpmprequesttimeout(&natpmp, &timeout); - select(FD_SETSIZE, &fds, NULL, NULL, &timeout); + + if ((r = getnatpmprequesttimeout(&natpmp, &timeout)) < 0) { + err = "get timeout failed"; + goto end; + } + + if ((r = select(FD_SETSIZE, &fds, NULL, NULL, &timeout)) < 0) { + err = "select failed"; + goto end; + } r = readnatpmpresponseorretry(&natpmp, &response); } while(r == NATPMP_TRYAGAIN && i < max); if (r < 0) { + err = "general error"; goto end; } - pubaddr = inet_ntoa(response.pnu.publicaddress.addr); switch_copy_string(pub_addr, pubaddr, IP_LEN); nat_globals.nat_type = SWITCH_NAT_TYPE_PMP; @@ -168,6 +179,10 @@ static int get_pmp_pubaddr(char *pub_addr) end: + if (err) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error checking for PMP [%s]\n", err); + } + return r; }