From 97c32ea5b5b75416a44c69ef98373f0ef142347f Mon Sep 17 00:00:00 2001 From: Nanang Izzuddin Date: Tue, 2 Jan 2024 10:54:21 +0700 Subject: [PATCH] Fix parsing IPv6 TURN server in PJSUA (#3796) Change-Id: I185ee8658b6fce155d18ddd661f63e1c557de88f --- pjsip/src/pjsua-lib/pjsua_media.c | 36 ++++++------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/pjsip/src/pjsua-lib/pjsua_media.c b/pjsip/src/pjsua-lib/pjsua_media.c index 72814bd2c..a64c78afa 100644 --- a/pjsip/src/pjsua-lib/pjsua_media.c +++ b/pjsip/src/pjsua-lib/pjsua_media.c @@ -957,32 +957,6 @@ static void on_ice_complete(pjmedia_transport *tp, } -/* Parse "HOST:PORT" format */ -static pj_status_t parse_host_port(const pj_str_t *host_port, - pj_str_t *host, pj_uint16_t *port) -{ - pj_str_t str_port; - - str_port.ptr = pj_strchr(host_port, ':'); - if (str_port.ptr != NULL) { - int iport; - - host->ptr = host_port->ptr; - host->slen = (str_port.ptr - host->ptr); - str_port.ptr++; - str_port.slen = host_port->slen - host->slen - 1; - iport = (int)pj_strtoul(&str_port); - if (iport < 1 || iport > 65535) - return PJ_EINVAL; - *port = (pj_uint16_t)iport; - } else { - *host = *host_port; - *port = 0; - } - - return PJ_SUCCESS; -} - /* Create ICE media transports (when ice is enabled) */ static pj_status_t create_ice_media_transport( const pjsua_transport_config *cfg, @@ -1160,9 +1134,13 @@ static pj_status_t create_ice_media_transport( } /* Configure TURN server */ - status = parse_host_port(&acc_cfg->turn_cfg.turn_server, - &ice_cfg.turn_tp[0].server, - &ice_cfg.turn_tp[0].port); + + /* Parse the server entry into host:port */ + status = pj_sockaddr_parse2(pj_AF_UNSPEC(), 0, + &acc_cfg->turn_cfg.turn_server, + &ice_cfg.turn_tp[0].server, + &ice_cfg.turn_tp[0].port, + NULL); if (status != PJ_SUCCESS || ice_cfg.turn_tp[0].server.slen == 0) { PJ_LOG(1,(THIS_FILE, "Invalid TURN server setting")); return PJ_EINVAL;