Index: /pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
===================================================================
--- /pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h	(revision 4542)
+++ /pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h	(revision 4543)
@@ -3032,4 +3032,16 @@
 
     /**
+     * This option controls whether the IP address in SDP should be replaced
+     * with the IP address found in Via header of the REGISTER response, ONLY
+     * when STUN and ICE are not used. If the value is FALSE (the original
+     * behavior), then the local IP address will be used. If TRUE, and when
+     * STUN and ICE are disabled, then the IP address found in registration
+     * response will be used.
+     *
+     * Default: PJ_FALSE (no)
+     */
+    pj_bool_t        allow_sdp_nat_rewrite;
+
+    /**
      * Control the use of SIP outbound feature. SIP outbound is described in
      * RFC 5626 to enable proxies or registrar to send inbound requests back
Index: /pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h
===================================================================
--- /pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h	(revision 4542)
+++ /pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h	(revision 4543)
@@ -230,4 +230,8 @@
     int		     reg_last_code; /**< Last status last register.	*/
 
+    pj_str_t         reg_mapped_addr;/**< Our addr as seen by reg srv.
+                                          Only if allow_sdp_nat_rewrite
+                                          is set                        */
+
     struct {
 	pj_bool_t	 active;    /**< Flag of reregister status.	*/
Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c	(revision 4542)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c	(revision 4543)
@@ -651,4 +651,5 @@
     acc->valid = PJ_FALSE;
     acc->contact.slen = 0;
+    acc->reg_mapped_addr.slen = 0;
     pj_bzero(&acc->via_addr, sizeof(acc->via_addr));
     acc->via_tp = NULL;
@@ -1256,4 +1257,5 @@
 	    acc->regc = NULL;
 	    acc->contact.slen = 0;
+	    acc->reg_mapped_addr.slen = 0;
 	}
     }
@@ -1464,4 +1466,11 @@
                                                &acc->via_addr, acc->via_tp);
         }
+    }
+
+    /* Save mapped address if needed */
+    if (acc->cfg.allow_sdp_nat_rewrite &&
+	pj_strcmp(&acc->reg_mapped_addr, via_addr))
+    {
+	pj_strdup(acc->pool, &acc->reg_mapped_addr, via_addr);
     }
 
@@ -1990,4 +1999,5 @@
 	acc->regc = NULL;
 	acc->contact.slen = 0;
+	acc->reg_mapped_addr.slen = 0;
 	
 	/* Stop keep-alive timer if any. */
@@ -2001,4 +2011,5 @@
 	acc->regc = NULL;
 	acc->contact.slen = 0;
+	acc->reg_mapped_addr.slen = 0;
 
 	/* Stop keep-alive timer if any. */
@@ -2015,4 +2026,5 @@
 	    acc->regc = NULL;
 	    acc->contact.slen = 0;
+	    acc->reg_mapped_addr.slen = 0;
 
 	    /* Stop keep-alive timer if any. */
@@ -2120,4 +2132,5 @@
 	acc->regc = NULL;
 	acc->contact.slen = 0;
+	acc->reg_mapped_addr.slen = 0;
     }
 
@@ -2168,4 +2181,5 @@
 	acc->regc = NULL;
 	acc->contact.slen = 0;
+	acc->reg_mapped_addr.slen = 0;
 	return status;
     }
Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 4542)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 4543)
@@ -240,9 +240,11 @@
     pj_status_t status = PJ_SUCCESS;
     char addr_buf[PJ_INET6_ADDRSTRLEN+10];
+    pjsua_acc *acc;
     pj_sock_t sock[2];
-    pjsua_acc *acc = &pjsua_var.acc[call_med->call->acc_id];
 
     use_ipv6 = (acc->cfg.ipv6_media_use != PJSUA_IPV6_DISABLED);
     af = use_ipv6 ? pj_AF_INET6() : pj_AF_INET();
+
+    acc = &pjsua_var.acc[call_med->call->acc_id];
 
     /* Make sure STUN server resolution has completed */
@@ -424,4 +426,17 @@
 
 	} else {
+	    if (acc->cfg.allow_sdp_nat_rewrite && acc->reg_mapped_addr.slen) {
+		pj_status_t status;
+
+		/* Take the address from mapped addr as seen by registrar */
+		status = pj_sockaddr_set_str_addr(af, &bound_addr,
+		                                  &acc->reg_mapped_addr);
+		if (status != PJ_SUCCESS) {
+		    /* just leave bound_addr with whatever it was
+		    pj_bzero(pj_sockaddr_get_addr(&bound_addr),
+		             pj_sockaddr_get_addr_len(&bound_addr));
+		     */
+		}
+	    }
 
 	    if (!pj_sockaddr_has_addr(&bound_addr)) {
