summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiza Sulistyo <riza@teluu.com>2014-03-25 04:08:44 +0000
committerRiza Sulistyo <riza@teluu.com>2014-03-25 04:08:44 +0000
commitbbedb19ff73ee8aed26ebcd2a852ee8f82d1c497 (patch)
tree4bf08f3b5ce15f63a0b3926c388ff64525bd6cb5
parenta0208cda15419a29925b3947f6f1e09ff8cb7f1a (diff)
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
-rw-r--r--pjsip/include/pjsip/sip_config.h20
-rw-r--r--pjsip/src/pjsip/sip_config.c3
-rw-r--r--pjsip/src/pjsip/sip_transport.c29
3 files changed, 40 insertions, 12 deletions
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 */