diff options
author | Benny Prijono <bennylp@teluu.com> | 2007-02-14 14:36:13 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2007-02-14 14:36:13 +0000 |
commit | 39f601dab4c54ead07b1d1c8ee59f7aebe6bc019 (patch) | |
tree | 3c9dea3bf2aa29ff4479bb53ed9cacae11a6a828 | |
parent | 7f42602646dff69ae69acecec318fd6b32bbf8f5 (diff) |
Fixed ticket #101: PJSUA transport is not updated with correct port number if application specifies port is zero
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@947 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r-- | pjsip-apps/src/pjsua/pjsua_app.c | 17 | ||||
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_core.c | 17 |
2 files changed, 31 insertions, 3 deletions
diff --git a/pjsip-apps/src/pjsua/pjsua_app.c b/pjsip-apps/src/pjsua/pjsua_app.c index 641c32cc..5b2d649d 100644 --- a/pjsip-apps/src/pjsua/pjsua_app.c +++ b/pjsip-apps/src/pjsua/pjsua_app.c @@ -485,7 +485,7 @@ static pj_status_t parse_args(int argc, char *argv[], case OPT_LOCAL_PORT: /* local-port */ lval = pj_strtoul(pj_cstr(&tmp, pj_optarg)); - if (lval < 1 || lval > 65535) { + if (lval < 0 || lval > 65535) { PJ_LOG(1,(THIS_FILE, "Error: expecting integer value for " "--local-port")); @@ -2891,6 +2891,7 @@ on_exit: pj_status_t app_init(int argc, char *argv[]) { pjsua_transport_id transport_id = -1; + pjsua_transport_config tcp_cfg; unsigned i; pj_status_t status; @@ -2995,6 +2996,8 @@ pj_status_t app_init(int argc, char *argv[]) app_config.rec_port = pjsua_recorder_get_conf_port(app_config.rec_id); } + pj_memcpy(&tcp_cfg, &app_config.udp_cfg, sizeof(tcp_cfg)); + /* Add UDP transport unless it's disabled. */ if (!app_config.no_udp) { pjsua_acc_id aid; @@ -3009,12 +3012,22 @@ pj_status_t app_init(int argc, char *argv[]) pjsua_acc_add_local(transport_id, PJ_TRUE, &aid); //pjsua_acc_set_transport(aid, transport_id); pjsua_acc_set_online_status(current_acc, PJ_TRUE); + + if (app_config.udp_cfg.port == 0) { + pjsua_transport_info ti; + pj_sockaddr_in *a; + + pjsua_transport_get_info(transport_id, &ti); + a = (pj_sockaddr_in*)&ti.local_addr; + + tcp_cfg.port = pj_ntohs(a->sin_port); + } } /* Add TCP transport unless it's disabled */ if (!app_config.no_tcp) { status = pjsua_transport_create(PJSIP_TRANSPORT_TCP, - &app_config.udp_cfg, + &tcp_cfg, &transport_id); if (status != PJ_SUCCESS) goto on_error; diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c index 68da5cef..4b235d3b 100644 --- a/pjsip/src/pjsua-lib/pjsua_core.c +++ b/pjsip/src/pjsua-lib/pjsua_core.c @@ -841,6 +841,20 @@ static pj_status_t create_sip_udp_sock(pj_in_addr bound_addr, return status; } + /* If port is zero, get the bound port */ + if (port == 0) { + pj_sockaddr_in bound_addr; + int namelen = sizeof(bound_addr); + status = pj_sock_getsockname(sock, &bound_addr, &namelen); + if (status != PJ_SUCCESS) { + pjsua_perror(THIS_FILE, "getsockname() error", status); + pj_sock_close(sock); + return status; + } + + port = pj_ntohs(bound_addr.sin_port); + } + /* Copy and normalize STUN param */ if (use_stun) { pj_memcpy(&stun, stun_param, sizeof(*stun_param)); @@ -873,7 +887,8 @@ static pj_status_t create_sip_udp_sock(pj_in_addr bound_addr, * Public address is already specified, no need to resolve the * address, only set the port. */ - /* Do nothing */ + if (p_pub_addr->sin_port == 0) + p_pub_addr->sin_port = pj_htons((pj_uint16_t)port); } else { |