diff options
author | Benny Prijono <bennylp@teluu.com> | 2008-06-07 11:14:32 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2008-06-07 11:14:32 +0000 |
commit | 8e2e31b4e69e0decbf0ad179012ff420322b6681 (patch) | |
tree | 51089a915b9d6148aa59a4d39132f5df3cc640ec /pjlib/src/pj/ip_helper_generic.c | |
parent | 204c24947f4f98d6d24a432d89024f8c0cdf2ca9 (diff) |
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
Diffstat (limited to 'pjlib/src/pj/ip_helper_generic.c')
-rw-r--r-- | pjlib/src/pj/ip_helper_generic.c | 43 |
1 files changed, 39 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_cnt<max_count; ++i) { + struct sockaddr *ad; int rc; strncpy(ifreq.ifr_name, if_list[i].if_name, IFNAMSIZ); @@ -243,20 +266,32 @@ static pj_status_t if_enum_by_af(int af, unsigned *p_cnt, pj_sockaddr ifs[]) continue; /* Failed to get address, continue */ } - if (ifreq.ifr_addr.sa_family != af) { + ad = (struct sockaddr*) &ifreq.ifr_addr; + + if (ad->sa_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)++; } |