From 8e2e31b4e69e0decbf0ad179012ff420322b6681 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Sat, 7 Jun 2008 11:14:32 +0000 Subject: Ignore 0.0.0.0/8 class IP address in interface enumeration function since this doesnt seem to have practical use for us (thanks Helmut Wolf) git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1996 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib/src/pj/ip_helper_generic.c | 43 ++++++++++++++++++++++++++++++++++++---- pjlib/src/pj/ip_helper_win32.c | 6 ++++++ 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/pjlib/src/pj/ip_helper_generic.c b/pjlib/src/pj/ip_helper_generic.c index c9ece26d..a8dbfef7 100644 --- a/pjlib/src/pj/ip_helper_generic.c +++ b/pjlib/src/pj/ip_helper_generic.c @@ -96,6 +96,17 @@ static pj_status_t if_enum_by_af(int af, continue; /* Skip when interface is down */ } + /* Ignore 0.0.0.0/8 address. This is a special address + * which doesn't seem to have practical use. + */ + if (af==pj_AF_INET() && + (pj_ntohl(((pj_sockaddr_in*)ad)->sin_addr.s_addr) >> 24) == 0) + { + TRACE_((THIS_FILE, " address %s ignored (0.0.0.0/8 class)", + get_addr(ad), ad->sa_family)); + continue; + } + TRACE_((THIS_FILE, " address %s (af=%d) added at index %d", get_addr(ad), ad->sa_family, *p_cnt)); @@ -177,6 +188,17 @@ static pj_status_t if_enum_by_af(int af, continue; /* Skip loopback interface */ } + /* Ignore 0.0.0.0/8 address. This is a special address + * which doesn't seem to have practical use. + */ + if (af==pj_AF_INET() && + (pj_ntohl(((pj_sockaddr_in*)ad)->sin_addr.s_addr) >> 24) == 0) + { + TRACE_((THIS_FILE, " address %s ignored (0.0.0.0/8 class)", + get_addr(ad), ad->sa_family)); + continue; + } + TRACE_((THIS_FILE, " address %s (af=%d) added at index %d", get_addr(ad), ad->sa_family, *p_cnt)); @@ -214,6 +236,7 @@ static pj_status_t if_enum_by_af(int af, unsigned *p_cnt, pj_sockaddr ifs[]) max_count = *p_cnt; *p_cnt = 0; for (i=0; if_list[i].if_index && *p_cntsa_family != af) { TRACE_((THIS_FILE, " address %s family %d ignored", get_addr(&ifreq.ifr_addr), ifreq.ifr_addr.sa_family)); continue; /* Not address family that we want, continue */ } + /* Ignore 0.0.0.0/8 address. This is a special address + * which doesn't seem to have practical use. + */ + if (af==pj_AF_INET() && + (pj_ntohl(((pj_sockaddr_in*)ad)->sin_addr.s_addr) >> 24) == 0) + { + TRACE_((THIS_FILE, " address %s ignored (0.0.0.0/8 class)", + get_addr(ad), ad->sa_family)); + continue; + } + /* Got an address ! */ TRACE_((THIS_FILE, " address %s (af=%d) added at index %d", - get_addr(&ifreq.ifr_addr), ifreq.ifr_addr.sa_family, *p_cnt)); + get_addr(ad), ad->sa_family, *p_cnt)); pj_bzero(&ifs[*p_cnt], sizeof(ifs[0])); - pj_memcpy(&ifs[*p_cnt], &ifreq.ifr_addr, - pj_sockaddr_get_len(&ifreq.ifr_addr)); + pj_memcpy(&ifs[*p_cnt], ad, pj_sockaddr_get_len(ad)); (*p_cnt)++; } diff --git a/pjlib/src/pj/ip_helper_win32.c b/pjlib/src/pj/ip_helper_win32.c index cb63adb8..76d44fa0 100644 --- a/pjlib/src/pj/ip_helper_win32.c +++ b/pjlib/src/pj/ip_helper_win32.c @@ -204,6 +204,12 @@ static pj_status_t enum_ipv4_interface(unsigned *p_cnt, if (pTab->table[i].dwAddr == 0) continue; + /* Ignore 0.0.0.0/8 address. This is a special address + * which doesn't seem to have practical use. + */ + if ((pj_ntohl(pTab->table[i].dwAddr) >> 24) == 0) + continue; + #if PJ_IP_HELPER_IGNORE_LOOPBACK_IF /* Investigate the type of this interface */ pj_bzero(&ifRow, sizeof(ifRow)); -- cgit v1.2.3