Fixed ticket #151: pj_gethostip() should fallback to default interface when 127.x.x.x is returned, not just 127.0.0.1 (thanks Andrey Kuprianov)
git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@1025 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjlib/src/pj/addr_resolv_sock.c b/pjlib/src/pj/addr_resolv_sock.c
index a292bec..04c0152 100644
--- a/pjlib/src/pj/addr_resolv_sock.c
+++ b/pjlib/src/pj/addr_resolv_sock.c
@@ -59,12 +59,8 @@
{
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);
#ifdef _MSC_VER
/* Get rid of "uninitialized he variable" with MS compilers */
@@ -78,11 +74,12 @@
}
- /* If we end up with 127.0.0.1, resolve the IP by getting the default
+ /* If we end up with 127.x.x.x, resolve the IP by getting the default
* interface to connect to some public host.
*/
- if (status != PJ_SUCCESS || addr->s_addr == loopip.s_addr) {
+ if (status != PJ_SUCCESS || (pj_ntohl(addr->s_addr) >> 24)==127) {
pj_sock_t fd;
+ pj_str_t cp;
pj_sockaddr_in a;
int len;