Index: /pjproject/branches/symbian/pjlib/include/pj/addr_resolv.h
===================================================================
--- /pjproject/branches/symbian/pjlib/include/pj/addr_resolv.h	(revision 790)
+++ /pjproject/branches/symbian/pjlib/include/pj/addr_resolv.h	(revision 791)
@@ -25,5 +25,5 @@
  */
 
-#include <pj/types.h>
+#include <pj/sock.h>
 
 PJ_BEGIN_DECL
@@ -84,4 +84,15 @@
 PJ_DECL(pj_status_t) pj_gethostbyname(const pj_str_t *name, pj_hostent *he);
 
+/**
+ * Resolve the primary IP address of local host. 
+ *
+ * @param ip_addr   On successful resolution, this will be filled up with
+ *		    the host IP address, in network byte order.
+ *
+ * @return	    PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pj_gethostip(pj_in_addr *ip_addr);
+
+
 
 /** @} */
Index: /pjproject/branches/symbian/pjlib/src/pj/addr_resolv_symbian.cpp
===================================================================
--- /pjproject/branches/symbian/pjlib/src/pj/addr_resolv_symbian.cpp	(revision 790)
+++ /pjproject/branches/symbian/pjlib/src/pj/addr_resolv_symbian.cpp	(revision 791)
@@ -20,4 +20,5 @@
 #include <pj/assert.h>
 #include <pj/errno.h>
+#include <pj/string.h>
 #include <pj/unicode.h>
 
@@ -78,2 +79,64 @@
 }
 
+
+/* Resolve the IP address of local machine */
+pj_status_t pj_gethostip(pj_in_addr *addr)
+{
+    const pj_str_t *hostname = pj_gethostname();
+    struct pj_hostent he;
+    pj_str_t cp;
+    pj_in_addr loopip;
+    pj_status_t status;
+
+    cp = pj_str("127.0.0.1");
+    loopip = pj_inet_addr(&cp);
+
+    /* Try with resolving local hostname first */
+    status = pj_gethostbyname(hostname, &he);
+    if (status == PJ_SUCCESS) {
+	*addr = *(pj_in_addr*)he.h_addr;
+    }
+
+
+    /* If we end up with 127.0.0.1 or 0.0.0.0, resolve the IP by getting 
+     * the default interface to connect to some public host.
+     */
+    if (status!=PJ_SUCCESS || addr->s_addr == loopip.s_addr || !addr->s_addr) {
+	pj_sock_t fd;
+	pj_sockaddr_in a;
+	int len;
+
+	status = pj_sock_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, &fd);
+	if (status != PJ_SUCCESS) {
+	    return status;
+	}
+
+	cp = pj_str("1.1.1.1");
+	pj_sockaddr_in_init(&a, &cp, 53);
+
+	status = pj_sock_connect(fd, &a, sizeof(a));
+	if (status != PJ_SUCCESS) {
+	    pj_sock_close(fd);
+	    return status;
+	}
+
+	len = sizeof(a);
+	status = pj_sock_getsockname(fd, &a, &len);
+	if (status != PJ_SUCCESS) {
+	    pj_sock_close(fd);
+	    return status;
+	}
+
+	pj_sock_close(fd);
+	
+	*addr = a.sin_addr;
+
+	if (a.sin_addr.s_addr == 0)
+	    return PJ_ENOTFOUND;
+    }
+
+    return status;
+}
+
+
+
Index: /pjproject/branches/symbian/pjsip/src/pjsip/sip_transport_udp.c
===================================================================
--- /pjproject/branches/symbian/pjsip/src/pjsip/sip_transport_udp.c	(revision 790)
+++ /pjproject/branches/symbian/pjsip/src/pjsip/sip_transport_udp.c	(revision 791)
@@ -579,5 +579,5 @@
  */
 PJ_DEF(pj_status_t) pjsip_udp_transport_start( pjsip_endpoint *endpt,
-					       const pj_sockaddr_in *local,
+					       const pj_sockaddr_in *local_a,
 					       const pjsip_host_port *a_name,
 					       unsigned async_cnt,
@@ -587,7 +587,8 @@
     pj_status_t status;
     char addr_buf[16];
+    pj_sockaddr_in tmp_addr;
     pjsip_host_port bound_name;
 
-    PJ_ASSERT_RETURN(local != NULL, PJ_EINVAL);
+    PJ_ASSERT_RETURN(endpt && async_cnt, PJ_EINVAL);
 
     status = pj_sock_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, &sock);
@@ -595,5 +596,10 @@
 	return status;
 
-    status = pj_sock_bind(sock, local, sizeof(*local));
+    if (local_a == NULL) {
+	pj_sockaddr_in_init(&tmp_addr, NULL, 0);
+	local_a = &tmp_addr;
+    }
+
+    status = pj_sock_bind(sock, local_a, sizeof(*local_a));
     if (status != PJ_SUCCESS) {
 	pj_sock_close(sock);
@@ -605,24 +611,31 @@
 	 * Build a name based on bound address.
 	 */
+	int addr_len;
+
+	addr_len = sizeof(tmp_addr);
+	status = pj_sock_getsockname(sock, &tmp_addr, &addr_len);
+	if (status != PJ_SUCCESS) {
+	    pj_sock_close(sock);
+	    return status;
+	}
+
 	a_name = &bound_name;
 	bound_name.host.ptr = addr_buf;
-	bound_name.port = pj_ntohs(local->sin_port);
+	bound_name.port = pj_ntohs(tmp_addr.sin_port);
 
 	/* If bound address specifies "0.0.0.0", get the IP address
 	 * of local hostname.
 	 */
-	if (local->sin_addr.s_addr == PJ_INADDR_ANY) {
-	    pj_hostent he;
-	    const pj_str_t *hostname = pj_gethostname();
-	    status = pj_gethostbyname(hostname, &he);
-	    if (status != PJ_SUCCESS) {
-		pj_sock_close(sock);
+	if (tmp_addr.sin_addr.s_addr == PJ_INADDR_ANY) {
+	    pj_in_addr hostip;
+
+	    status = pj_gethostip(&hostip);
+	    if (status != PJ_SUCCESS)
 		return status;
-	    }
-	    pj_strcpy2(&bound_name.host, 
-		       pj_inet_ntoa(*(pj_in_addr*)he.h_addr));
+
+	    pj_strcpy2(&bound_name.host, pj_inet_ntoa(hostip));
 	} else {
 	    /* Otherwise use bound address. */
-	    pj_strcpy2(&bound_name.host, pj_inet_ntoa(local->sin_addr));
+	    pj_strcpy2(&bound_name.host, pj_inet_ntoa(tmp_addr.sin_addr));
 	}
 	
