--- a/channels/chan_sip.c 2009-09-10 19:27:26.284475594 -0400 +++ b/channels/chan_sip.c 2009-09-10 23:56:13.660082898 -0400 @@ -3556,8 +3556,21 @@ static void ast_sip_ouraddrfor(struct in } externexpire = time(NULL) + externrefresh; } - if (externip.sin_addr.s_addr) + if (externip.sin_addr.s_addr) { *us = externip; + if (!externip.sin_port) { + switch(p->socket.type) { + case SIP_TRANSPORT_TCP: + us->sin_port = sip_tcp_desc.local_address.sin_port; + break; + case SIP_TRANSPORT_UDP: + us->sin_port = bindaddr.sin_port; + break; + case SIP_TRANSPORT_TLS: + us->sin_port = sip_tls_desc.local_address.sin_port; + } + } + } else ast_log(LOG_WARNING, "stun failed\n"); ast_debug(1, "Target address %s is not local, substituting externip\n", @@ -25160,17 +25173,11 @@ static int reload_config(enum channelrel if (ast_parse_arg(v->value, PARSE_INADDR, &externip)) ast_log(LOG_WARNING, "Invalid address for externip keyword: %s\n", v->value); externexpire = 0; - /* If no port was specified use the value of bindport */ - if (!externip.sin_port) - externip.sin_port = bindaddr.sin_port; } else if (!strcasecmp(v->name, "externhost")) { ast_copy_string(externhost, v->value, sizeof(externhost)); if (ast_parse_arg(externhost, PARSE_INADDR, &externip)) ast_log(LOG_WARNING, "Invalid address for externhost keyword: %s\n", externhost); externexpire = time(NULL); - /* If no port was specified use the value of bindport */ - if (!externip.sin_port) - externip.sin_port = bindaddr.sin_port; } else if (!strcasecmp(v->name, "externrefresh")) { if (sscanf(v->value, "%30d", &externrefresh) != 1) { ast_log(LOG_WARNING, "Invalid externrefresh value '%s', must be an integer >0 at line %d\n", v->value, v->lineno);