summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pjlib/include/pj/addr_resolv.h15
-rw-r--r--pjlib/src/pj/addr_resolv_sock.c59
-rw-r--r--pjmedia/src/pjmedia-codec/ilbc/iCBSearch.c6
-rw-r--r--pjmedia/src/pjmedia/transport_udp.c12
-rw-r--r--pjsip-apps/src/pjsua/pjsua_app.c2
-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
9 files changed, 98 insertions, 42 deletions
diff --git a/pjlib/include/pj/addr_resolv.h b/pjlib/include/pj/addr_resolv.h
index 3d75798c..45194b30 100644
--- a/pjlib/include/pj/addr_resolv.h
+++ b/pjlib/include/pj/addr_resolv.h
@@ -21,10 +21,10 @@
/**
* @file addr_resolv.h
- * @brief Address resolve (pj_gethostbyname()).
+ * @brief IP address resolution.
*/
-#include <pj/types.h>
+#include <pj/sock.h>
PJ_BEGIN_DECL
@@ -84,6 +84,17 @@ typedef struct pj_hostent
PJ_DECL(pj_status_t) pj_gethostbyname(const pj_str_t *name, pj_hostent *he);
+/**
+ * Resolve the primary IP address of local host.
+ *
+ * @param ip_addr On successful resolution, this will be filled up with
+ * the host IP address, in network byte order.
+ *
+ * @return PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pj_gethostip(pj_in_addr *ip_addr);
+
+
/** @} */
PJ_END_DECL
diff --git a/pjlib/src/pj/addr_resolv_sock.c b/pjlib/src/pj/addr_resolv_sock.c
index 9b9eb6dc..36c1c574 100644
--- a/pjlib/src/pj/addr_resolv_sock.c
+++ b/pjlib/src/pj/addr_resolv_sock.c
@@ -19,8 +19,8 @@
#include <pj/addr_resolv.h>
#include <pj/assert.h>
#include <pj/string.h>
-#include <pj/compat/socket.h>
#include <pj/errno.h>
+#include <pj/compat/socket.h>
PJ_DEF(pj_status_t) pj_gethostbyname(const pj_str_t *hostname, pj_hostent *phe)
@@ -49,3 +49,60 @@ PJ_DEF(pj_status_t) pj_gethostbyname(const pj_str_t *hostname, pj_hostent *phe)
return PJ_SUCCESS;
}
+/* Resolve the IP address of local machine */
+pj_status_t pj_gethostip(pj_in_addr *addr)
+{
+ const pj_str_t *hostname = pj_gethostname();
+ struct pj_hostent he;
+ pj_str_t cp;
+ pj_in_addr loopip;
+ pj_status_t status;
+
+ cp = pj_str("127.0.0.1");
+ loopip = pj_inet_addr(&cp);
+
+ /* Try with resolving local hostname first */
+ status = pj_gethostbyname(hostname, &he);
+ if (status == PJ_SUCCESS) {
+ *addr = *(pj_in_addr*)he.h_addr;
+ }
+
+
+ /* If we end up with 127.0.0.1, resolve the IP by getting the default
+ * interface to connect to some public host.
+ */
+ if (status != PJ_SUCCESS || addr->s_addr == loopip.s_addr) {
+ pj_sock_t fd;
+ pj_sockaddr_in a;
+ int len;
+
+ status = pj_sock_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, &fd);
+ if (status != PJ_SUCCESS) {
+ return status;
+ }
+
+ cp = pj_str("1.1.1.1");
+ pj_sockaddr_in_init(&a, &cp, 53);
+
+ status = pj_sock_connect(fd, &a, sizeof(a));
+ if (status != PJ_SUCCESS) {
+ pj_sock_close(fd);
+ return status;
+ }
+
+ len = sizeof(a);
+ status = pj_sock_getsockname(fd, &a, &len);
+ if (status != PJ_SUCCESS) {
+ pj_sock_close(fd);
+ return status;
+ }
+
+ pj_sock_close(fd);
+
+ *addr = a.sin_addr;
+ }
+
+ return status;
+}
+
+
diff --git a/pjmedia/src/pjmedia-codec/ilbc/iCBSearch.c b/pjmedia/src/pjmedia-codec/ilbc/iCBSearch.c
index 0f65e449..dfbc50b7 100644
--- a/pjmedia/src/pjmedia-codec/ilbc/iCBSearch.c
+++ b/pjmedia/src/pjmedia-codec/ilbc/iCBSearch.c
@@ -127,7 +127,8 @@
*ppe=0.0;
pp=buf+LPC_FILTERORDER+lMem-lTarget;
for (j=0; j<lTarget; j++) {
- *ppe+=(*pp)*(*pp++);
+ *ppe+=(*pp)*(*pp);
+ ++pp;
}
if (*ppe>0.0) {
@@ -322,7 +323,8 @@
pp=cbvectors+lMem-lTarget;
for (j=0; j<lTarget; j++) {
- *ppe+=(*pp)*(*pp++);
+ *ppe+=(*pp)*(*pp);
+ ++pp;
}
ppi = cbvectors + lMem - 1 - lTarget;
diff --git a/pjmedia/src/pjmedia/transport_udp.c b/pjmedia/src/pjmedia/transport_udp.c
index a92c3edb..be67cfae 100644
--- a/pjmedia/src/pjmedia/transport_udp.c
+++ b/pjmedia/src/pjmedia/transport_udp.c
@@ -245,13 +245,13 @@ PJ_DEF(pj_status_t) pjmedia_transport_udp_attach( pjmedia_endpt *endpt,
/* If address is 0.0.0.0, use host's IP address */
if (tp->rtp_addr_name.sin_addr.s_addr == 0) {
- pj_hostent he;
- const pj_str_t *hostname = pj_gethostname();
- status = pj_gethostbyname(hostname, &he);
- if (status != PJ_SUCCESS) {
+ pj_in_addr hostip;
+
+ status = pj_gethostip(&hostip);
+ if (status != PJ_SUCCESS)
goto on_error;
- }
- tp->rtp_addr_name.sin_addr = *(pj_in_addr*)he.h_addr;
+
+ tp->rtp_addr_name.sin_addr = hostip;
}
/* Same with RTCP */
diff --git a/pjsip-apps/src/pjsua/pjsua_app.c b/pjsip-apps/src/pjsua/pjsua_app.c
index 2bb7d9d0..57b6ad2e 100644
--- a/pjsip-apps/src/pjsua/pjsua_app.c
+++ b/pjsip-apps/src/pjsua/pjsua_app.c
@@ -78,7 +78,9 @@ static struct app_config
static pjsua_call_id current_call;
static pj_str_t uri_arg;
+#ifdef STEREO_DEMO
static void stereo_demo();
+#endif
/*****************************************************************************
* Configuration manipulation
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));