Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 5383)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 5384)
@@ -843,4 +843,6 @@
     /* Create ICE stream transport configuration */
     pj_ice_strans_cfg_default(&ice_cfg);
+    pj_bzero(&ice_cfg.stun, sizeof(ice_cfg.stun));
+    pj_bzero(&ice_cfg.turn, sizeof(ice_cfg.turn));
     pj_stun_config_init(&ice_cfg.stun_cfg, &pjsua_var.cp.factory, 0,
 		        pjsip_endpt_get_ioqueue(pjsua_var.endpt),
@@ -851,5 +853,5 @@
     ice_cfg.opt = acc_cfg->ice_cfg.ice_opt;
 
-    /* Check if STUN transport is configured */
+    /* If STUN transport is configured, initialize STUN transport settings */
     if ((pj_sockaddr_has_addr(&pjsua_var.stun_srv) &&
 	 pjsua_media_acc_is_using_stun(call_med->call->acc_id)) ||
@@ -865,43 +867,58 @@
     }
 
-    /* Configure STUN settings */
-    if (pj_sockaddr_has_addr(&pjsua_var.stun_srv) &&
-	pjsua_media_acc_is_using_stun(call_med->call->acc_id))
-    {
-	pj_sockaddr_print(&pjsua_var.stun_srv, stunip, sizeof(stunip), 0);
-	ice_cfg.stun_tp[0].server = pj_str(stunip);
-	ice_cfg.stun_tp[0].port = pj_sockaddr_get_port(&pjsua_var.stun_srv);
-    }
-    if (acc_cfg->ice_cfg.ice_max_host_cands >= 0) {
-	ice_cfg.stun_tp[0].max_host_cands =
-				    acc_cfg->ice_cfg.ice_max_host_cands;
-	if (use_ipv6)
-	    ice_cfg.stun_tp[1].max_host_cands =
-				    acc_cfg->ice_cfg.ice_max_host_cands;
-    }
-
-    /* Copy binding port setting to STUN setting */
-    pj_sockaddr_init(ice_cfg.stun_tp[0].af, &ice_cfg.stun_tp[0].cfg.bound_addr,
-		     &cfg->bound_addr, (pj_uint16_t)cfg->port);
-    ice_cfg.stun_tp[0].cfg.port_range = (pj_uint16_t)cfg->port_range;
-    if (cfg->port != 0 && ice_cfg.stun_tp[0].cfg.port_range == 0) {
-	ice_cfg.stun_tp[0].cfg.port_range = 
-				 (pj_uint16_t)(pjsua_var.ua_cfg.max_calls * 10);
-    }
-    if (use_ipv6) {
-	pj_str_t IN6_ADDR_ANY = {"0", 1};
-	pj_sockaddr_init(pj_AF_INET6(), &ice_cfg.stun_tp[1].cfg.bound_addr,
-			 &IN6_ADDR_ANY, (pj_uint16_t)cfg->port);
-	ice_cfg.stun_tp[1].cfg.port_range = ice_cfg.stun_tp[0].cfg.port_range;
-    }
-
-    /* Copy QoS setting to STUN setting */
-    ice_cfg.stun_tp[0].cfg.qos_type = cfg->qos_type;
-    pj_memcpy(&ice_cfg.stun_tp[0].cfg.qos_params, &cfg->qos_params,
-	      sizeof(cfg->qos_params));
-    if (use_ipv6) {
-	ice_cfg.stun_tp[1].cfg.qos_type = cfg->qos_type;
-	pj_memcpy(&ice_cfg.stun_tp[1].cfg.qos_params, &cfg->qos_params,
+    /* Configure STUN transport settings */
+    if (ice_cfg.stun_tp_cnt) {
+	unsigned i;
+
+	/* Configure STUN server (currently only for IPv4) */
+	if (pj_sockaddr_has_addr(&pjsua_var.stun_srv) &&
+	    pjsua_media_acc_is_using_stun(call_med->call->acc_id))
+	{
+	    pj_sockaddr_print(&pjsua_var.stun_srv, stunip, sizeof(stunip), 0);
+	    ice_cfg.stun_tp[0].server = pj_str(stunip);
+	    ice_cfg.stun_tp[0].port = 
+				    pj_sockaddr_get_port(&pjsua_var.stun_srv);
+	}
+
+	/* Configure max host candidates */
+	if (acc_cfg->ice_cfg.ice_max_host_cands >= 0) {
+	    for (i = 0; i < ice_cfg.stun_tp_cnt; ++i)
+		ice_cfg.stun_tp[i].max_host_cands =
+				acc_cfg->ice_cfg.ice_max_host_cands;
+	}
+
+	/* Configure binding address */
+	pj_sockaddr_init(ice_cfg.stun_tp[0].af,
+			 &ice_cfg.stun_tp[0].cfg.bound_addr,
+			 &cfg->bound_addr, (pj_uint16_t)cfg->port);
+	ice_cfg.stun_tp[0].cfg.port_range = (pj_uint16_t)cfg->port_range;
+	if (cfg->port != 0 && ice_cfg.stun_tp[0].cfg.port_range == 0) {
+	    ice_cfg.stun_tp[0].cfg.port_range = 
+			    (pj_uint16_t)(pjsua_var.ua_cfg.max_calls * 10);
+	}
+	if (use_ipv6 && ice_cfg.stun_tp_cnt > 1) {
+	    pj_str_t IN6_ADDR_ANY = {"0", 1};
+	    pj_sockaddr_init(pj_AF_INET6(),
+			     &ice_cfg.stun_tp[1].cfg.bound_addr,
+			     &IN6_ADDR_ANY, (pj_uint16_t)cfg->port);
+	    ice_cfg.stun_tp[1].cfg.port_range =
+			    ice_cfg.stun_tp[0].cfg.port_range;
+	}
+
+	/* Configure QoS setting */
+	ice_cfg.stun_tp[0].cfg.qos_type = cfg->qos_type;
+	pj_memcpy(&ice_cfg.stun_tp[0].cfg.qos_params, &cfg->qos_params,
 		  sizeof(cfg->qos_params));
+	if (use_ipv6 && ice_cfg.stun_tp_cnt > 1) {
+	    ice_cfg.stun_tp[1].cfg.qos_type = cfg->qos_type;
+	    pj_memcpy(&ice_cfg.stun_tp[1].cfg.qos_params, &cfg->qos_params,
+		      sizeof(cfg->qos_params));
+	}
+
+	/* Configure max packet size */
+	ice_cfg.stun_tp[0].cfg.max_pkt_size = PJMEDIA_MAX_MRU;
+	if (use_ipv6 && ice_cfg.stun_tp_cnt > 1)
+	    ice_cfg.stun_tp[1].cfg.max_pkt_size = PJMEDIA_MAX_MRU;
+
     }
 
@@ -936,12 +953,7 @@
 	    ice_cfg.turn_tp[0].cfg.port_range = 
 				 (pj_uint16_t)(pjsua_var.ua_cfg.max_calls * 10);
-    }
-
-    /* Configure packet size for STUN and TURN sockets */
-    ice_cfg.stun_tp[0].cfg.max_pkt_size = PJMEDIA_MAX_MRU;
-    ice_cfg.turn_tp[0].cfg.max_pkt_size = PJMEDIA_MAX_MRU;
-
-    if (use_ipv6) {
-	ice_cfg.stun_tp[1].cfg.max_pkt_size = PJMEDIA_MAX_MRU;
+
+	/* Configure max packet size */
+	ice_cfg.turn_tp[0].cfg.max_pkt_size = PJMEDIA_MAX_MRU;
     }
 
