Browse code

msrp: proper parsing ipv6 host part in uri

- enclose ipv6 address in square brackets for msrp pv
- related to #2472

Daniel-Constantin Mierla authored on 09/09/2020 11:01:36
Showing 2 changed files
... ...
@@ -491,10 +491,25 @@ int msrp_parse_uri(char *start, int len, msrp_uri_t *uri)
491 491
 	}
492 492
 	hook = &uri->host;
493 493
 	hook->s = s;
494
+	if(*s == '[')
495
+	{
496
+		/* IPv6 */
497
+		p = q_memchr(s, ']', e - s);
498
+		if(p == NULL)
499
+		{
500
+			goto error;
501
+		}
502
+		s = p + 1;
503
+		hook->len = s - hook->s;
504
+	}
494 505
 	p = q_memchr(s, ':', e - s);
495 506
 	if(p!=NULL)
496 507
 	{
497
-		hook->len = p - hook->s;
508
+		if(hook->len == 0)
509
+		{
510
+			/* host len was not set yet */
511
+			hook->len = p - hook->s;
512
+		}
498 513
 		hook = &uri->port;
499 514
 		s = p+1;
500 515
 		if(s>=e) goto error;
... ...
@@ -283,7 +283,7 @@ int pv_get_msrp(sip_msg_t *msg,  pv_param_t *param, pv_value_t *res)
283 283
 				memcpy(p, "msrp://", 7);
284 284
 				p+=7;
285 285
 			}
286
-			strcpy(p, ip_addr2a(&mf->tcpinfo->rcv->src_ip));
286
+			strcpy(p, ip_addr2strz(&mf->tcpinfo->rcv->src_ip));
287 287
 			strcat(p, ":");
288 288
 			strcat(p, int2str(mf->tcpinfo->rcv->src_port, NULL));
289 289
 			s.len = strlen(s.s);