summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiza Sulistyo <riza@teluu.com>2013-02-27 14:43:38 +0000
committerRiza Sulistyo <riza@teluu.com>2013-02-27 14:43:38 +0000
commit78d22f7f7eb6f1fd0e22947828e41618611826b3 (patch)
tree8a8db5cc37be9a99759c5b631c2dfbf151391a4e
parentc64940521176044a358eb0faca6f30db7828e6c2 (diff)
Re #1613: backported to 1.x
git-svn-id: http://svn.pjsip.org/repos/pjproject/branches/1.x@4403 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjlib/src/pj/ip_helper_generic.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/pjlib/src/pj/ip_helper_generic.c b/pjlib/src/pj/ip_helper_generic.c
index 26ef0e7e..b85e336d 100644
--- a/pjlib/src/pj/ip_helper_generic.c
+++ b/pjlib/src/pj/ip_helper_generic.c
@@ -165,9 +165,6 @@ static pj_status_t if_enum_by_af(int af,
return PJ_RETURN_OS_ERROR(oserr);
}
- /* Done with socket */
- pj_sock_close(sock);
-
/* Interface interfaces */
ifr = (struct ifreq*) ifc.ifc_req;
count = ifc.ifc_len / sizeof(struct ifreq);
@@ -177,6 +174,7 @@ static pj_status_t if_enum_by_af(int af,
*p_cnt = 0;
for (i=0; i<count; ++i) {
struct ifreq *itf = &ifr[i];
+ struct ifreq iff = *itf;
struct sockaddr *ad = &itf->ifr_addr;
TRACE_((THIS_FILE, " checking interface %s", itf->ifr_name));
@@ -188,13 +186,19 @@ static pj_status_t if_enum_by_af(int af,
continue;
}
- if ((itf->ifr_flags & IFF_UP)==0) {
+ if (ioctl(sock, SIOCGIFFLAGS, &iff) != 0) {
+ TRACE_((THIS_FILE, " ioctl(SIOCGIFFLAGS) failed: %s",
+ get_os_errmsg()));
+ continue; /* Failed to get flags, continue */
+ }
+
+ if ((iff.ifr_flags & IFF_UP)==0) {
TRACE_((THIS_FILE, " interface is down"));
continue; /* Skip when interface is down */
}
#if PJ_IP_HELPER_IGNORE_LOOPBACK_IF
- if (itf->ifr_flags & IFF_LOOPBACK) {
+ if (iff.ifr_flags & IFF_LOOPBACK) {
TRACE_((THIS_FILE, " loopback interface"));
continue; /* Skip loopback interface */
}
@@ -220,10 +224,14 @@ static pj_status_t if_enum_by_af(int af,
(*p_cnt)++;
}
+ /* Done with socket */
+ pj_sock_close(sock);
+
TRACE_((THIS_FILE, "done, found %d address(es)", *p_cnt));
return (*p_cnt != 0) ? PJ_SUCCESS : PJ_ENOTFOUND;
}
+
#elif defined(PJ_HAS_NET_IF_H) && PJ_HAS_NET_IF_H != 0
/* Note: this does not work with IPv6 */
static pj_status_t if_enum_by_af(int af, unsigned *p_cnt, pj_sockaddr ifs[])