Index: /pjproject/trunk/pjlib/include/pj/addr_resolv.h
===================================================================
--- /pjproject/trunk/pjlib/include/pj/addr_resolv.h	(revision 720)
+++ /pjproject/trunk/pjlib/include/pj/addr_resolv.h	(revision 721)
@@ -22,8 +22,8 @@
 /**
  * @file addr_resolv.h
- * @brief Address resolve (pj_gethostbyname()).
+ * @brief IP address resolution.
  */
 
-#include <pj/types.h>
+#include <pj/sock.h>
 
 PJ_BEGIN_DECL
@@ -85,4 +85,15 @@
 
 
+/**
+ * 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/trunk/pjlib/src/pj/addr_resolv_sock.c
===================================================================
--- /pjproject/trunk/pjlib/src/pj/addr_resolv_sock.c	(revision 720)
+++ /pjproject/trunk/pjlib/src/pj/addr_resolv_sock.c	(revision 721)
@@ -20,6 +20,6 @@
 #include <pj/assert.h>
 #include <pj/string.h>
+#include <pj/errno.h>
 #include <pj/compat/socket.h>
-#include <pj/errno.h>
 
 
@@ -50,2 +50,59 @@
 }
 
+/* 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, resolve the IP by getting the default
+     * interface to connect to some public host.
+     */
+    if (status != PJ_SUCCESS || addr->s_addr == loopip.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;
+    }
+
+    return status;
+}
+
+
Index: /pjproject/trunk/pjmedia/src/pjmedia-codec/ilbc/iCBSearch.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia-codec/ilbc/iCBSearch.c	(revision 720)
+++ /pjproject/trunk/pjmedia/src/pjmedia-codec/ilbc/iCBSearch.c	(revision 721)
@@ -128,5 +128,6 @@
                pp=buf+LPC_FILTERORDER+lMem-lTarget;
                for (j=0; j<lTarget; j++) {
-                   *ppe+=(*pp)*(*pp++);
+                   *ppe+=(*pp)*(*pp);
+		   ++pp;
                }
 
@@ -323,5 +324,6 @@
                pp=cbvectors+lMem-lTarget;
                for (j=0; j<lTarget; j++) {
-                   *ppe+=(*pp)*(*pp++);
+                   *ppe+=(*pp)*(*pp);
+		   ++pp;
                }
 
Index: /pjproject/trunk/pjmedia/src/pjmedia/transport_udp.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/transport_udp.c	(revision 720)
+++ /pjproject/trunk/pjmedia/src/pjmedia/transport_udp.c	(revision 721)
@@ -246,11 +246,11 @@
     /* If address is 0.0.0.0, use host's IP address */
     if (tp->rtp_addr_name.sin_addr.s_addr == 0) {
-	pj_hostent he;
-	const pj_str_t *hostname = pj_gethostname();
-	status = pj_gethostbyname(hostname, &he);
-	if (status != PJ_SUCCESS) {
+	pj_in_addr hostip;
+
+	status = pj_gethostip(&hostip);
+	if (status != PJ_SUCCESS)
 	    goto on_error;
-	}
-	tp->rtp_addr_name.sin_addr = *(pj_in_addr*)he.h_addr;
+
+	tp->rtp_addr_name.sin_addr = hostip;
     }
 
Index: /pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c
===================================================================
--- /pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c	(revision 720)
+++ /pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c	(revision 721)
@@ -79,5 +79,7 @@
 static pj_str_t		uri_arg;
 
+#ifdef STEREO_DEMO
 static void stereo_demo();
+#endif
 
 /*****************************************************************************
Index: /pjproject/trunk/pjsip/src/pjsip/sip_transport_tcp.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsip/sip_transport_tcp.c	(revision 720)
+++ /pjproject/trunk/pjsip/src/pjsip/sip_transport_tcp.c	(revision 721)
@@ -250,13 +250,11 @@
      */
     if (listener_addr->sin_addr.s_addr == 0) {
-	const pj_str_t *hostname;
-	struct pj_hostent he;
-
-	hostname = pj_gethostname();
-	status = pj_gethostbyname(hostname, &he);
+	pj_in_addr hostip;
+
+	status = pj_gethostip(&hostip);
 	if (status != PJ_SUCCESS)
 	    goto on_error;
 
-	listener_addr->sin_addr = *(pj_in_addr*)he.h_addr;
+	listener_addr->sin_addr = hostip;
     }
 
Index: /pjproject/trunk/pjsip/src/pjsip/sip_transport_udp.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsip/sip_transport_udp.c	(revision 720)
+++ /pjproject/trunk/pjsip/src/pjsip/sip_transport_udp.c	(revision 721)
@@ -653,13 +653,11 @@
 	 */
 	if (tmp_addr.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);
+	    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. */
Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c	(revision 720)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c	(revision 721)
@@ -813,18 +813,14 @@
     } else {
 
-	const pj_str_t *hostname = pj_gethostname();
-	struct pj_hostent he;
-
-	status = pj_gethostbyname(hostname, &he);
+	pj_bzero(p_pub_addr, sizeof(pj_sockaddr_in));
+
+	status = pj_gethostip(&p_pub_addr->sin_addr);
 	if (status != PJ_SUCCESS) {
-	    pjsua_perror(THIS_FILE, "Unable to resolve local host", status);
 	    pj_sock_close(sock);
 	    return status;
 	}
 
-	pj_bzero(p_pub_addr, sizeof(pj_sockaddr_in));
 	p_pub_addr->sin_family = PJ_AF_INET;
 	p_pub_addr->sin_port = pj_htons((pj_uint16_t)port);
-	p_pub_addr->sin_addr = *(pj_in_addr*)he.h_addr;
     }
 
Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 720)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 721)
@@ -287,21 +287,13 @@
 
 	} else {
-	    const pj_str_t *hostname;
-	    pj_sockaddr_in addr;
+	    pj_in_addr addr;
 
 	    /* Get local IP address. */
-	    hostname = pj_gethostname();
-
-	    pj_bzero( &addr, sizeof(addr));
-	    addr.sin_family = PJ_AF_INET;
-	    status = pj_sockaddr_in_set_str_addr( &addr, hostname);
-	    if (status != PJ_SUCCESS) {
-		pjsua_perror(THIS_FILE, "Unresolvable local hostname", 
-			     status);
+	    status = pj_gethostip(&addr);
+	    if (status != PJ_SUCCESS)
 		goto on_error;
-	    }
 
 	    for (i=0; i<2; ++i)
-		pj_memcpy(&mapped_addr[i], &addr, sizeof(addr));
+		mapped_addr[i].sin_addr = addr;
 
 	    mapped_addr[0].sin_port=pj_htons((pj_uint16_t)rtp_port);
