summaryrefslogtreecommitdiff
path: root/pjsip
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2006-09-14 18:51:01 +0000
committerBenny Prijono <bennylp@teluu.com>2006-09-14 18:51:01 +0000
commitb6b613a4e59e2177a2e899dc4e21ab660c05de3d (patch)
treeab3821c5de8972a5006c4590ec631ff40ef61e15 /pjsip
parente015ebe064c6f5120ef2af2b73ce52796a06f790 (diff)
Fix the local IP address resolution issue in PJSIP, PJMEDIA, and PJSUA, by adding a new API pj_gethostip() to resolve the default local IP address of local host. This new function will work even when local hostname resolution is not set correctly, by detecting the default IP interface in the system.
Also fix compile warnings in iLBC. git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@721 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip')
-rw-r--r--pjsip/src/pjsip/sip_transport_tcp.c8
-rw-r--r--pjsip/src/pjsip/sip_transport_udp.c14
-rw-r--r--pjsip/src/pjsua-lib/pjsua_core.c8
-rw-r--r--pjsip/src/pjsua-lib/pjsua_media.c16
4 files changed, 15 insertions, 31 deletions
diff --git a/pjsip/src/pjsip/sip_transport_tcp.c b/pjsip/src/pjsip/sip_transport_tcp.c
index 2adfa184..4d9132d1 100644
--- a/pjsip/src/pjsip/sip_transport_tcp.c
+++ b/pjsip/src/pjsip/sip_transport_tcp.c
@@ -249,15 +249,13 @@ PJ_DEF(pj_status_t) pjsip_tcp_transport_start( pjsip_endpoint *endpt,
* as the transport's address.
*/
if (listener_addr->sin_addr.s_addr == 0) {
- const pj_str_t *hostname;
- struct pj_hostent he;
+ pj_in_addr hostip;
- hostname = pj_gethostname();
- status = pj_gethostbyname(hostname, &he);
+ status = pj_gethostip(&hostip);
if (status != PJ_SUCCESS)
goto on_error;
- listener_addr->sin_addr = *(pj_in_addr*)he.h_addr;
+ listener_addr->sin_addr = hostip;
}
pj_ansi_snprintf(listener->obj_name, sizeof(listener->obj_name),
diff --git a/pjsip/src/pjsip/sip_transport_udp.c b/pjsip/src/pjsip/sip_transport_udp.c
index 027a6df2..7f0ac4f5 100644
--- a/pjsip/src/pjsip/sip_transport_udp.c
+++ b/pjsip/src/pjsip/sip_transport_udp.c
@@ -652,15 +652,13 @@ PJ_DEF(pj_status_t) pjsip_udp_transport_start( pjsip_endpoint *endpt,
* of local hostname.
*/
if (tmp_addr.sin_addr.s_addr == PJ_INADDR_ANY) {
- pj_hostent he;
- const pj_str_t *hostname = pj_gethostname();
- status = pj_gethostbyname(hostname, &he);
- if (status != PJ_SUCCESS) {
- pj_sock_close(sock);
+ pj_in_addr hostip;
+
+ status = pj_gethostip(&hostip);
+ if (status != PJ_SUCCESS)
return status;
- }
- pj_strcpy2(&bound_name.host,
- pj_inet_ntoa(*(pj_in_addr*)he.h_addr));
+
+ pj_strcpy2(&bound_name.host, pj_inet_ntoa(hostip));
} else {
/* Otherwise use bound address. */
pj_strcpy2(&bound_name.host, pj_inet_ntoa(tmp_addr.sin_addr));
diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c
index ea4b0635..d26094ab 100644
--- a/pjsip/src/pjsua-lib/pjsua_core.c
+++ b/pjsip/src/pjsua-lib/pjsua_core.c
@@ -812,20 +812,16 @@ static pj_status_t create_sip_udp_sock(pj_in_addr bound_addr,
} else {
- const pj_str_t *hostname = pj_gethostname();
- struct pj_hostent he;
+ pj_bzero(p_pub_addr, sizeof(pj_sockaddr_in));
- status = pj_gethostbyname(hostname, &he);
+ status = pj_gethostip(&p_pub_addr->sin_addr);
if (status != PJ_SUCCESS) {
- pjsua_perror(THIS_FILE, "Unable to resolve local host", status);
pj_sock_close(sock);
return status;
}
- pj_bzero(p_pub_addr, sizeof(pj_sockaddr_in));
p_pub_addr->sin_family = PJ_AF_INET;
p_pub_addr->sin_port = pj_htons((pj_uint16_t)port);
- p_pub_addr->sin_addr = *(pj_in_addr*)he.h_addr;
}
*p_sock = sock;
diff --git a/pjsip/src/pjsua-lib/pjsua_media.c b/pjsip/src/pjsua-lib/pjsua_media.c
index 0e24e4de..e37275a2 100644
--- a/pjsip/src/pjsua-lib/pjsua_media.c
+++ b/pjsip/src/pjsua-lib/pjsua_media.c
@@ -286,23 +286,15 @@ static pj_status_t create_rtp_rtcp_sock(const pjsua_transport_config *cfg,
sock[1] = PJ_INVALID_SOCKET;
} else {
- const pj_str_t *hostname;
- pj_sockaddr_in addr;
+ pj_in_addr addr;
/* Get local IP address. */
- hostname = pj_gethostname();
-
- pj_bzero( &addr, sizeof(addr));
- addr.sin_family = PJ_AF_INET;
- status = pj_sockaddr_in_set_str_addr( &addr, hostname);
- if (status != PJ_SUCCESS) {
- pjsua_perror(THIS_FILE, "Unresolvable local hostname",
- status);
+ status = pj_gethostip(&addr);
+ if (status != PJ_SUCCESS)
goto on_error;
- }
for (i=0; i<2; ++i)
- pj_memcpy(&mapped_addr[i], &addr, sizeof(addr));
+ mapped_addr[i].sin_addr = addr;
mapped_addr[0].sin_port=pj_htons((pj_uint16_t)rtp_port);
mapped_addr[1].sin_port=pj_htons((pj_uint16_t)(rtp_port+1));