diff -u channels/chan_iax2.c channels/chan_iax2.c --- channels/chan_iax2.c 12 May 2005 21:20:36 -0000 +++ channels/chan_iax2.c 16 May 2005 10:04:16 -0000 @@ -7817,19 +7817,30 @@ { struct sockaddr_in sin; int nonlocal = 1; - socklen_t sinlen = sizeof(sin); int port = IAX_DEFAULT_PORTNO; int sockfd = defaultsockfd; - - /* Get port number */ - if (getsockname(defaultsockfd, - (struct sockaddr*)&sin, - &sinlen) >= 0 && - sinlen == sizeof(sin)) { - port = ntohs(sin.sin_port); + char *tmp; + char *portstr; + + tmp = ast_strdupa(srcaddr); + if (!tmp) { + ast_log(LOG_WARNING, "Out of memory!\n"); + return -1; + } + + + portstr = strchr(tmp, ':'); + if (portstr) { + int i; + + *portstr = '\0'; + portstr++; + i = atoi(portstr); + if (i > 0) + port = i; } - if (!ast_get_ip(&sin, srcaddr)) { + if (!ast_get_ip(&sin, tmp)) { struct ast_netsock *sock; int res;