summaryrefslogtreecommitdiff
path: root/pjsip/src/pjsua-lib/pjsua_media.c
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2006-09-26 13:21:02 +0000
committerBenny Prijono <bennylp@teluu.com>2006-09-26 13:21:02 +0000
commit506917fa7dfa0cec64586417feb081b6dcf1f97e (patch)
tree9627c2f90727f171fbe2c82fcb256a6efb8b0c12 /pjsip/src/pjsua-lib/pjsua_media.c
parentdecb295824ef9cf2df5683d11b1c40fb6eff6ab5 (diff)
Added support for specifying IP address in PJSUA-LIB/pjsua.
This option can be used for example to select the IP interface of SIP/RTP/RTCP transports, or to specify the public IP address of NAT/router in case port forwarding is used. For SIP transports, this feature works for both UDP and TCP transports. Changes: - added public_ip field in pjsua_transport_config, and change SIP and media transport creation to consider this option. - added --ip-addr option in pjsua - added pjsip_tcp_transport_start2() which allows specifying alternate TCP published address when creating TCP transports. git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@742 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip/src/pjsua-lib/pjsua_media.c')
-rw-r--r--pjsip/src/pjsua-lib/pjsua_media.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/pjsip/src/pjsua-lib/pjsua_media.c b/pjsip/src/pjsua-lib/pjsua_media.c
index e37275a2..13ff542c 100644
--- a/pjsip/src/pjsua-lib/pjsua_media.c
+++ b/pjsip/src/pjsua-lib/pjsua_media.c
@@ -209,6 +209,7 @@ static pj_status_t create_rtp_rtcp_sock(const pjsua_transport_config *cfg,
};
int i;
static pj_uint16_t rtp_port;
+ pj_sockaddr_in bound_addr;
pj_sockaddr_in mapped_addr[2];
pj_status_t status = PJ_SUCCESS;
pj_sock_t sock[2];
@@ -219,6 +220,15 @@ static pj_status_t create_rtp_rtcp_sock(const pjsua_transport_config *cfg,
for (i=0; i<2; ++i)
sock[i] = PJ_INVALID_SOCKET;
+ bound_addr.sin_addr.s_addr = PJ_INADDR_ANY;
+ if (cfg->bound_addr.slen) {
+ status = pj_sockaddr_in_set_str_addr(&bound_addr, &cfg->bound_addr);
+ if (status != PJ_SUCCESS) {
+ pjsua_perror(THIS_FILE, "Unable to resolve transport bind address",
+ status);
+ return status;
+ }
+ }
/* Loop retry to bind RTP and RTCP sockets. */
for (i=0; i<RTP_RETRY; ++i, rtp_port += 2) {
@@ -230,7 +240,8 @@ static pj_status_t create_rtp_rtcp_sock(const pjsua_transport_config *cfg,
return status;
}
- status = pj_sock_bind_in(sock[0], cfg->ip_addr.s_addr, rtp_port);
+ status = pj_sock_bind_in(sock[0], bound_addr.sin_addr.s_addr,
+ rtp_port);
if (status != PJ_SUCCESS) {
pj_sock_close(sock[0]);
sock[0] = PJ_INVALID_SOCKET;
@@ -245,7 +256,7 @@ static pj_status_t create_rtp_rtcp_sock(const pjsua_transport_config *cfg,
return status;
}
- status = pj_sock_bind_in(sock[1], cfg->ip_addr.s_addr,
+ status = pj_sock_bind_in(sock[1], bound_addr.sin_addr.s_addr,
(pj_uint16_t)(rtp_port+1));
if (status != PJ_SUCCESS) {
pj_sock_close(sock[0]);
@@ -285,6 +296,20 @@ static pj_status_t create_rtp_rtcp_sock(const pjsua_transport_config *cfg,
pj_sock_close(sock[1]);
sock[1] = PJ_INVALID_SOCKET;
+ } else if (cfg->public_addr.slen) {
+
+ status = pj_sockaddr_in_init(&mapped_addr[0], &cfg->public_addr,
+ (pj_uint16_t)rtp_port);
+ if (status != PJ_SUCCESS)
+ goto on_error;
+
+ status = pj_sockaddr_in_init(&mapped_addr[1], &cfg->public_addr,
+ (pj_uint16_t)(rtp_port+1));
+ if (status != PJ_SUCCESS)
+ goto on_error;
+
+ break;
+
} else {
pj_in_addr addr;