Skip to content

Commit

Permalink
Fix parsing IPv6 TURN server in PJSUA (#3796)
Browse files Browse the repository at this point in the history
Change-Id: I185ee8658b6fce155d18ddd661f63e1c557de88f
  • Loading branch information
nanangizz authored and aberaud committed Jan 5, 2024
1 parent 8662eb4 commit 97c32ea
Showing 1 changed file with 7 additions and 29 deletions.
36 changes: 7 additions & 29 deletions pjsip/src/pjsua-lib/pjsua_media.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 97c32ea

Please sign in to comment.