From bbedb19ff73ee8aed26ebcd2a852ee8f82d1c497 Mon Sep 17 00:00:00 2001 From: Riza Sulistyo Date: Tue, 25 Mar 2014 04:08:44 +0000 Subject: Re #1752: Add option to resolve hostname when trying to get network interface. git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4802 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip/include/pjsip/sip_config.h | 20 ++++++++++++++++++++ pjsip/src/pjsip/sip_config.c | 3 ++- pjsip/src/pjsip/sip_transport.c | 29 ++++++++++++++++++----------- 3 files changed, 40 insertions(+), 12 deletions(-) (limited to 'pjsip') diff --git a/pjsip/include/pjsip/sip_config.h b/pjsip/include/pjsip/sip_config.h index fc7604cb..27575c8c 100644 --- a/pjsip/include/pjsip/sip_config.h +++ b/pjsip/include/pjsip/sip_config.h @@ -137,6 +137,14 @@ typedef struct pjsip_cfg_t */ pj_bool_t req_has_via_alias; + /** + * Resolve hostname when trying to get the network interface to be put + * in Via or Contact header. + * + * Default is PJSIP_RESOLVE_HOSTNAME_TO_GET_INTERFACE. + */ + pj_bool_t resolve_hostname_to_get_interface; + } endpt; /** Transaction layer settings. */ @@ -363,6 +371,18 @@ PJ_INLINE(pjsip_cfg_t*) pjsip_cfg(void) # define PJSIP_REQ_HAS_VIA_ALIAS PJ_TRUE #endif +/** + * Resolve hostname when trying to get the network interface to be put in Via + * or Contact header. + * + * This option can also be controlled at run-time by the + * \a resolve_hostname_to_get_interface setting in pjsip_cfg_t. + * + * Default is PJ_FALSE. + */ +#ifndef PJSIP_RESOLVE_HOSTNAME_TO_GET_INTERFACE +# define PJSIP_RESOLVE_HOSTNAME_TO_GET_INTERFACE PJ_FALSE +#endif /** * Accept call replace in early state when invite is not initiated diff --git a/pjsip/src/pjsip/sip_config.c b/pjsip/src/pjsip/sip_config.c index a72aeea2..3897a054 100644 --- a/pjsip/src/pjsip/sip_config.c +++ b/pjsip/src/pjsip/sip_config.c @@ -32,7 +32,8 @@ pjsip_cfg_t pjsip_sip_cfg_var = PJSIP_DONT_SWITCH_TO_TCP, PJSIP_DONT_SWITCH_TO_TLS, PJSIP_FOLLOW_EARLY_MEDIA_FORK, - PJSIP_REQ_HAS_VIA_ALIAS + PJSIP_REQ_HAS_VIA_ALIAS, + PJSIP_RESOLVE_HOSTNAME_TO_GET_INTERFACE }, /* Transaction settings */ diff --git a/pjsip/src/pjsip/sip_transport.c b/pjsip/src/pjsip/sip_transport.c index 4d32bbdc..66e5d1bb 100644 --- a/pjsip/src/pjsip/sip_transport.c +++ b/pjsip/src/pjsip/sip_transport.c @@ -1291,19 +1291,26 @@ static pj_status_t get_net_interface(pjsip_transport_type_e tp_type, { int af; pj_sockaddr itf_addr; - pj_status_t status; + pj_status_t status = -1; af = (tp_type & PJSIP_TRANSPORT_IPV6)? PJ_AF_INET6 : PJ_AF_INET; - status = pj_getipinterface(af, dst, &itf_addr, PJ_FALSE, NULL); - if (status != PJ_SUCCESS) { - /* If it fails, e.g: on WM6 (http://support.microsoft.com/kb/129065), - * just fallback using pj_gethostip(), see ticket #1660. - */ - PJ_LOG(5,(THIS_FILE,"Warning: unable to determine local " - "interface, fallback to default interface!")); - status = pj_gethostip(af, &itf_addr); - if (status != PJ_SUCCESS) - return status; + + if (pjsip_cfg()->endpt.resolve_hostname_to_get_interface) { + status = pj_getipinterface(af, dst, &itf_addr, PJ_TRUE, NULL); + } + + if (status != PJ_SUCCESS) { + status = pj_getipinterface(af, dst, &itf_addr, PJ_FALSE, NULL); + if (status != PJ_SUCCESS) { + /* If it fails, e.g: on WM6(http://support.microsoft.com/kb/129065), + * just fallback using pj_gethostip(), see ticket #1660. + */ + PJ_LOG(5,(THIS_FILE,"Warning: unable to determine local " + "interface, fallback to default interface!")); + status = pj_gethostip(af, &itf_addr); + if (status != PJ_SUCCESS) + return status; + } } /* Print address */ -- cgit v1.2.3