--- channels/chan_sip.c.orig 2007-08-20 11:07:46.695095949 +0200 +++ channels/chan_sip.c 2007-08-21 15:13:51.000000000 +0200 @@ -4872,6 +4872,7 @@ int vpeercapability = 0, vpeernoncodeccapability = 0; struct sockaddr_in sin; /*!< media socket address */ struct sockaddr_in vsin; /*!< Video socket address */ + struct sockaddr_in rsin; /*!< RTP socket address */ const char *codecs; struct hostent *hp; /*!< RTP Audio host IP */ @@ -5032,7 +5033,9 @@ /* RTP addresses and ports for audio and video */ sin.sin_family = AF_INET; vsin.sin_family = AF_INET; + rsin.sin_family = AF_INET; memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr)); + memcpy(&rsin.sin_addr, hp->h_addr, sizeof(rsin.sin_addr)); if (vhp) memcpy(&vsin.sin_addr, vhp->h_addr, sizeof(vsin.sin_addr)); @@ -5040,6 +5043,20 @@ if (p->udptl) { if (udptlportno > 0) { sin.sin_port = htons(udptlportno); + + if ((ast_test_flag(&p->flags[0], SIP_NAT)) == SIP_NAT) { + ast_rtp_get_peer(p->rtp, &rsin); + if (strcasecmp(ast_inet_ntoa(rsin.sin_addr), "0.0.0.0") != 0) { + sin.sin_addr = rsin.sin_addr; + if (debug) + ast_log(LOG_DEBUG,"Peer T.38 UDPTL is behind NAT, using RTP port %s:%d\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); + } else { + sin.sin_addr = p->recv.sin_addr; + if (debug) + ast_log(LOG_DEBUG,"Peer T.38 UDPTL is behind NAT, using SIP port %s:%d\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); + } + } + ast_udptl_set_peer(p->udptl, &sin); if (debug) ast_log(LOG_DEBUG,"Peer T.38 UDPTL is at port %s:%d\n",ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));