Index: /pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c
===================================================================
--- /pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c	(revision 5994)
+++ /pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c	(revision 5995)
@@ -1231,4 +1231,5 @@
 {
     pjsua_transport_id transport_id = -1;
+    pjsua_transport_id udp6_tp_id = -1, tcp6_tp_id = -1, tls6_tp_id = -1;
     pjsua_transport_config tcp_cfg;
     unsigned i;
@@ -1259,4 +1260,7 @@
 	return status;
     }
+    
+    if (app_config.ipv6)
+    	app_config.cfg.stun_try_ipv6 = PJ_TRUE;
 
     /* Initialize application callbacks */
@@ -1585,4 +1589,5 @@
 	if (status != PJ_SUCCESS)
 	    goto on_error;
+	udp6_tp_id = transport_id;
 
 	/* Add local account */
@@ -1650,4 +1655,5 @@
 	if (status != PJ_SUCCESS)
 	    goto on_error;
+	tcp6_tp_id = transport_id;
 
 	/* Add local account */
@@ -1689,4 +1695,5 @@
 	if (status != PJ_SUCCESS)
 	    goto on_error;
+	tls6_tp_id = transport_id;
 	
 	/* Add local account */
@@ -1751,4 +1758,56 @@
 	app_config.acc_cfg[i].reg_retry_interval = 300;
 	app_config.acc_cfg[i].reg_first_retry_interval = 60;
+	if (app_config.ipv6) {
+	    pj_str_t *dst_uri = NULL;
+	    pj_str_t tmp;
+	    pjsip_uri *uri;
+
+	    // Uncomment this for testing in a NAT64 network
+	    // app_config.acc_cfg[i].nat64_opt = PJSUA_NAT64_ENABLED;
+	    app_config.acc_cfg[i].ipv6_media_use = PJSUA_IPV6_ENABLED;
+
+	    if ((app_config.cfg.outbound_proxy_cnt > 0) &&
+	        (app_config.acc_cfg[i].reg_use_proxy == 1 /* outbound */ ||
+	         app_config.acc_cfg[i].reg_use_proxy == 3 /* all */))
+	    {
+	    	dst_uri = &app_config.cfg.outbound_proxy[0];
+	    } else if ((app_config.acc_cfg[i].proxy_cnt > 0) &&
+	        (app_config.acc_cfg[i].reg_use_proxy == 2 /* acc */ ||
+	         app_config.acc_cfg[i].reg_use_proxy == 3 /* all */))
+	    {
+	    	dst_uri = &app_config.acc_cfg[i].proxy[0];
+	    } else if (app_config.acc_cfg[i].reg_uri.slen > 0) {
+	    	dst_uri = &app_config.acc_cfg[i].reg_uri;
+	    }
+	    
+	    pj_strdup_with_null(app_config.pool, &tmp, dst_uri);
+
+	    uri = pjsip_parse_uri(app_config.pool, tmp.ptr, tmp.slen, 0);
+	    if (uri != NULL) {
+		pjsip_sip_uri *sip_uri;
+		pjsip_transport_type_e tp_type = PJSIP_TRANSPORT_UNSPECIFIED;	
+		
+		sip_uri = (pjsip_sip_uri*)pjsip_uri_get_uri(uri);
+
+    		/* Get transport type of the URI */
+    		if (PJSIP_URI_SCHEME_IS_SIPS(sip_uri)) {
+		    tp_type = PJSIP_TRANSPORT_TLS;
+    		} else if (sip_uri->transport_param.slen == 0) {
+		    tp_type = PJSIP_TRANSPORT_UDP;
+    		} else {
+		    tp_type = pjsip_transport_get_type_from_name(
+		    		  &sip_uri->transport_param);
+		    tp_type &= ~ PJSIP_TRANSPORT_IPV6;
+		}
+		
+		if (tp_type == PJSIP_TRANSPORT_UDP) {
+	    	    app_config.acc_cfg[i].transport_id = udp6_tp_id;
+		} else if (tp_type == PJSIP_TRANSPORT_TCP) {
+	    	    app_config.acc_cfg[i].transport_id = tcp6_tp_id;
+		} else if (tp_type == PJSIP_TRANSPORT_TLS) {
+	    	    app_config.acc_cfg[i].transport_id = tls6_tp_id;
+		}
+	    }
+	}
 
 	app_config_init_video(&app_config.acc_cfg[i]);
Index: /pjproject/trunk/pjsip/src/pjsip/sip_resolve.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsip/sip_resolve.c	(revision 5994)
+++ /pjproject/trunk/pjsip/src/pjsip/sip_resolve.c	(revision 5995)
@@ -277,5 +277,13 @@
 	    svr_addr.count = 1;
 	    if (ip_addr_ver == 4) {
-	        if (af == pj_AF_INET6()) {
+	        if (af == pj_AF_INET()) {
+		    pj_sockaddr_init(pj_AF_INET(), &svr_addr.entry[0].addr, 
+				     NULL, 0);
+		    pj_inet_pton(pj_AF_INET(), &target->addr.host,
+			     	 &svr_addr.entry[0].addr.ipv4.sin_addr);
+		}
+
+	        if (af == pj_AF_INET6() || PJSIP_MAX_RESOLVED_ADDRESSES > 1)
+	        {
 	            /* Generate a synthesized IPv6 address, if possible. */
 		    unsigned int count = 1;
@@ -288,20 +296,20 @@
 		    	ai[0].ai_addr.addr.sa_family == pj_AF_INET6())
 		    {
+		    	unsigned idx = 0;
+		    	
+		    	if (target->type == PJSIP_TRANSPORT_UNSPECIFIED) {
+		    	    idx = 1;
+		    	    svr_addr.count++;
+		    	}
 			pj_sockaddr_init(pj_AF_INET6(),
-					 &svr_addr.entry[0].addr,
+					 &svr_addr.entry[idx].addr,
 					 NULL, 0);
-			svr_addr.entry[0].addr.ipv6.sin6_addr =
+			svr_addr.entry[idx].addr.ipv6.sin6_addr =
 			    ai[0].ai_addr.ipv6.sin6_addr;
-		    } else {
-		        pj_sockaddr_init(pj_AF_INET(),
-		        		 &svr_addr.entry[0].addr, NULL, 0);
-		        pj_inet_pton(pj_AF_INET(), &target->addr.host,
-			     	     &svr_addr.entry[0].addr.ipv4.sin_addr);
+		    } else if (af == pj_AF_INET6()) {
+		    	svr_addr.count = 0;
+			status = PJ_ERESOLVE;
+			goto on_error;
 		    }
-		} else {
-		    pj_sockaddr_init(pj_AF_INET(), &svr_addr.entry[0].addr, 
-				     NULL, 0);
-		    pj_inet_pton(pj_AF_INET(), &target->addr.host,
-			     	 &svr_addr.entry[0].addr.ipv4.sin_addr);
 		}
 	    } else {
