diff options
author | Benny Prijono <bennylp@teluu.com> | 2008-07-07 21:31:02 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2008-07-07 21:31:02 +0000 |
commit | 07852fec4400363969a010259ed304d0abeee92b (patch) | |
tree | bb84548918a47eec368c2317e2847c09dbdc481a | |
parent | 1e3d62ad8a16f5f14a1f5d74e5234f06f3d1471b (diff) |
Configuration option to include/exclude loopback interface in enum_ip_interface(), and always include loopback address in the proxy sample (thanks Filippo Zangheri for the suggestion)
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@2112 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r-- | pjlib/include/pj/config.h | 11 | ||||
-rw-r--r-- | pjlib/src/pj/ip_helper_generic.c | 9 | ||||
-rw-r--r-- | pjlib/src/pj/ip_helper_win32.c | 4 | ||||
-rw-r--r-- | pjsip-apps/src/samples/proxy.h | 5 |
4 files changed, 22 insertions, 7 deletions
diff --git a/pjlib/include/pj/config.h b/pjlib/include/pj/config.h index 6c470b28..2940d1aa 100644 --- a/pjlib/include/pj/config.h +++ b/pjlib/include/pj/config.h @@ -603,6 +603,17 @@ /** + * Specify whether #pj_enum_ip_interface() function should exclude + * loopback interfaces. + * + * Default: 1 + */ +#ifndef PJ_IP_HELPER_IGNORE_LOOPBACK_IF +# define PJ_IP_HELPER_IGNORE_LOOPBACK_IF 1 +#endif + + +/** * Has semaphore functionality? * * Default: 1 diff --git a/pjlib/src/pj/ip_helper_generic.c b/pjlib/src/pj/ip_helper_generic.c index 6eaba54a..6a3d19e7 100644 --- a/pjlib/src/pj/ip_helper_generic.c +++ b/pjlib/src/pj/ip_helper_generic.c @@ -85,14 +85,17 @@ static pj_status_t if_enum_by_af(int af, continue; /* Skip when interface is down */ } +#if PJ_IP_HELPER_IGNORE_LOOPBACK_IF if (it->ifa_flags & IFF_LOOPBACK) { TRACE_((THIS_FILE, " loopback interface")); continue; /* Skip loopback interface */ } +#endif if (ad==NULL) { TRACE_((THIS_FILE, " NULL address ignored")); - continue; /* reported to happen on Linux 2.6.25.9 */ + continue; /* reported to happen on Linux 2.6.25.9 + with ppp interface */ } if (ad->sa_family != af) { @@ -188,10 +191,12 @@ static pj_status_t if_enum_by_af(int af, continue; /* Skip when interface is down */ } +#if PJ_IP_HELPER_IGNORE_LOOPBACK_IF if (itf->ifr_flags & IFF_LOOPBACK) { TRACE_((THIS_FILE, " loopback interface")); continue; /* Skip loopback interface */ } +#endif /* Ignore 0.0.0.0/8 address. This is a special address * which doesn't seem to have practical use. @@ -259,10 +264,12 @@ static pj_status_t if_enum_by_af(int af, unsigned *p_cnt, pj_sockaddr ifs[]) continue; /* Skip when interface is down */ } +#if PJ_IP_HELPER_IGNORE_LOOPBACK_IF if (ifreq.ifr_flags & IFF_LOOPBACK) { TRACE_((THIS_FILE, " loopback interface")); continue; /* Skip loopback interface */ } +#endif /* Note: SIOCGIFADDR does not work for IPv6! */ if ((rc=ioctl(sock, SIOCGIFADDR, &ifreq)) != 0) { diff --git a/pjlib/src/pj/ip_helper_win32.c b/pjlib/src/pj/ip_helper_win32.c index 2fc64e01..122ae9b7 100644 --- a/pjlib/src/pj/ip_helper_win32.c +++ b/pjlib/src/pj/ip_helper_win32.c @@ -40,10 +40,6 @@ #include <pj/errno.h> #include <pj/string.h> -#ifndef PJ_IP_HELPER_IGNORE_LOOPBACK_IF -# define PJ_IP_HELPER_IGNORE_LOOPBACK_IF 1 -#endif - typedef DWORD (WINAPI *PFN_GetIpAddrTable)(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder); diff --git a/pjsip-apps/src/samples/proxy.h b/pjsip-apps/src/samples/proxy.h index 25a62874..54f1db09 100644 --- a/pjsip-apps/src/samples/proxy.h +++ b/pjsip-apps/src/samples/proxy.h @@ -271,11 +271,12 @@ static pj_status_t init_proxy(void) } } - /* No need to add this, this should have been added above. + /* Add loopback address. */ +#if PJ_IP_HELPER_IGNORE_LOOPBACK_IF global.name[global.name_cnt].host = pj_str("127.0.0.1"); global.name[global.name_cnt].port = global.port; global.name_cnt++; - */ +#endif global.name[global.name_cnt].host = *pj_gethostname(); global.name[global.name_cnt].port = global.port; |