Index: pjproject/trunk/pjnath/src/pjnath/ice_strans.c
===================================================================
--- pjproject/trunk/pjnath/src/pjnath/ice_strans.c	(revision 5860)
+++ pjproject/trunk/pjnath/src/pjnath/ice_strans.c	(revision 5861)
@@ -518,8 +518,9 @@
 	return status;
 
-    /* Start STUN Binding resolution and add srflx candidate
-     * only if server is set
+    /* Start STUN Binding resolution and add srflx candidate only if server
+     * is set. When any error occur during STUN Binding resolution, let's
+     * just skip it and generate host candidates.
      */
-    if (stun_cfg->server.slen) {
+    while (stun_cfg->server.slen) {
 	pj_stun_sock_info stun_sock_info;
 
@@ -539,6 +540,10 @@
 	if (status != PJ_SUCCESS) {
 	    ///sess_dec_ref(ice_st);
+	    PJ_PERROR(5,(ice_st->obj_name, status,
+			 "Comp %d: srflx candidate (tpid=%d) failed in "
+			 "pj_stun_sock_start()",
+			 comp->comp_id, cand->transport_id));
 	    pj_log_pop_indent();
-	    return status;
+	    break;
 	}
 
@@ -547,6 +552,10 @@
 	if (status != PJ_SUCCESS) {
 	    ///sess_dec_ref(ice_st);
+	    PJ_PERROR(5,(ice_st->obj_name, status,
+			 "Comp %d: srflx candidate (tpid=%d) failed in "
+			 "pj_stun_sock_get_info()",
+			 comp->comp_id, cand->transport_id));
 	    pj_log_pop_indent();
-	    return status;
+	    break;
 	}
 
@@ -568,4 +577,7 @@
 
 	pj_log_pop_indent();
+
+	/* Not really a loop, just trying to avoid complex 'if' blocks */
+	break;
     }
 
@@ -575,13 +587,16 @@
     if (stun_cfg->max_host_cands) {
 	pj_stun_sock_info stun_sock_info;
-	unsigned i;
+	unsigned i, cand_cnt = 0;
 
 	/* Enumerate addresses */
 	status = pj_stun_sock_get_info(comp->stun[idx].sock, &stun_sock_info);
-	if (status != PJ_SUCCESS)
+	if (status != PJ_SUCCESS) {
+	    PJ_PERROR(4,(ice_st->obj_name, status,
+			 "Failed in querying STUN socket info"));
 	    return status;
-
-	for (i=0; i<stun_sock_info.alias_cnt &&
-		  i<stun_cfg->max_host_cands; ++i)
+	}
+
+	for (i = 0; i < stun_sock_info.alias_cnt &&
+		    cand_cnt < stun_cfg->max_host_cands; ++i)
 	{
 	    unsigned j;
@@ -614,6 +629,8 @@
 	    }
 
-	    /* Ignore IPv6 link-local address */
-	    if (stun_cfg->af == pj_AF_INET6()) {
+	    /* Ignore IPv6 link-local address, unless it is the default
+	     * address (first alias).
+	     */
+	    if (stun_cfg->af == pj_AF_INET6() && i != 0) {
 		const pj_in6_addr *a = &addr->ipv6.sin6_addr;
 		if (a->s6_addr[0] == 0xFE && (a->s6_addr[1] & 0xC0) == 0x80)
@@ -651,4 +668,5 @@
 	    } else {
 		comp->cand_cnt+=1;
+		cand_cnt++;
 	    }
             
@@ -676,5 +694,5 @@
     }
 
-    return PJ_SUCCESS;
+    return status;
 }
 
Index: pjproject/trunk/pjnath/src/pjnath/stun_sock.c
===================================================================
--- pjproject/trunk/pjnath/src/pjnath/stun_sock.c	(revision 5860)
+++ pjproject/trunk/pjnath/src/pjnath/stun_sock.c	(revision 5861)
@@ -427,4 +427,8 @@
 				    stun_sock, &dns_srv_resolver_cb, 
 				    &stun_sock->q);
+	if (status != PJ_SUCCESS) {
+	    PJ_PERROR(4,(stun_sock->obj_name, status,
+			 "Failed in pj_dns_srv_resolve()"));
+	}
 
 	/* Processing will resume when the DNS SRV callback is called */
@@ -441,4 +445,6 @@
 
 	    if (status != PJ_SUCCESS) {
+		PJ_PERROR(4,(stun_sock->obj_name, status,
+			     "Failed in pj_getaddrinfo()"));
 	        pj_grp_lock_release(stun_sock->grp_lock);
 		return status;
@@ -452,4 +458,8 @@
 	/* Start sending Binding request */
 	status = get_mapped_addr(stun_sock);
+	if (status != PJ_SUCCESS) {
+	    PJ_PERROR(4,(stun_sock->obj_name, status,
+			 "Failed in sending Binding request"));
+	}
     }
 
@@ -667,4 +677,6 @@
 	status = pj_gethostip(stun_sock->af, &def_addr);
 	if (status != PJ_SUCCESS) {
+	    PJ_PERROR(4,(stun_sock->obj_name, status,
+			 "Failed in getting default address for STUN info"));
 	    pj_grp_lock_release(stun_sock->grp_lock);
 	    return status;
@@ -678,6 +690,10 @@
 				      info->aliases);
 	if (status != PJ_SUCCESS) {
-	    pj_grp_lock_release(stun_sock->grp_lock);
-	    return status;
+	    /* If enumeration fails, just return the default address */
+	    PJ_PERROR(4,(stun_sock->obj_name, status,
+			 "Failed in enumerating interfaces for STUN info, "
+			 "returning default address only"));
+	    info->alias_cnt = 1;
+	    pj_sockaddr_cp(&info->aliases[0], &def_addr);
 	}
 
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 5860)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 5861)
@@ -928,6 +928,7 @@
 
 	    /* Configure STUN server */
-	    if (pj_sockaddr_has_addr(&pjsua_var.stun_srv) &&
-	    	pjsua_media_acc_is_using_stun(call_med->call->acc_id))
+	    if (pjsua_media_acc_is_using_stun(call_med->call->acc_id) &&
+		pj_sockaddr_has_addr(&pjsua_var.stun_srv) &&
+		pjsua_var.stun_srv.addr.sa_family == ice_cfg.stun_tp[i].af)
 	    {
 	    	ice_cfg.stun_tp[i].server = pj_str(stunip);
