Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 338608) +++ channels/chan_sip.c (working copy) @@ -9104,6 +9104,36 @@ ast_rtp_lookup_mime_multiple2(s3, NULL, newnoncodeccapability, 0, 0)); } + /* If "nat = yes" and connection address equals "sent-by" address of + * the Via header, then send RTP media to same address as SIP responses + */ + if (ast_test_flag(&p->flags[0], SIP_NAT_FORCE_RPORT) && ast_test_flag(&p->flags[1], SIP_PAGE2_SYMMETRICRTP)) { + char via[512]; + char *c; + struct ast_sockaddr sent_by; + + ast_copy_string(via, sip_get_header(req, "Via"), sizeof(via)); + + c = strchr(via, ' '); + if (c) { + c = ast_skip_blanks(c + 1); + ast_sockaddr_resolve_first(&sent_by, c, PARSE_PORT_IGNORE); + + if (sa && !ast_sockaddr_cmp_addr(sa, &sent_by)) { + ast_sockaddr_copy(sa, &p->sa); + } + if (vsa && !ast_sockaddr_cmp_addr(vsa, &sent_by)) { + ast_sockaddr_copy(vsa, &p->sa); + } + if (tsa && !ast_sockaddr_cmp_addr(tsa, &sent_by)) { + ast_sockaddr_copy(tsa, &p->sa); + } + if (isa && !ast_sockaddr_cmp_addr(isa, &sent_by)) { + ast_sockaddr_copy(isa, &p->sa); + } + } + } + /* Setup audio address and port */ if (p->rtp) { if (portno > 0) {