Browse code

core: check for IP in no_naptr_srv_sip_resolvehost()

- catch IP addresses before attempting to do SRV query

Daniel-Constantin Mierla authored on 26/12/2012 11:32:00
Showing 1 changed files
... ...
@@ -1462,6 +1462,7 @@ struct hostent* no_naptr_srv_sip_resolvehost(str* name, unsigned short* port, ch
1462 1462
 		int proto_pref;
1463 1463
 	} srv_proto_list[PROTO_LAST], tmp_srv_element;
1464 1464
 	struct hostent* he;
1465
+	struct ip_addr* ip;
1465 1466
 	str srv_name;
1466 1467
 	static char tmp_srv[MAX_DNS_NAME]; /* tmp. buff. for SRV lookups */
1467 1468
 	int len;
... ...
@@ -1470,6 +1471,23 @@ struct hostent* no_naptr_srv_sip_resolvehost(str* name, unsigned short* port, ch
1470 1471
 	he=0;
1471 1472
 	len=0;
1472 1473
 
1474
+	/* check if it's an ip address */
1475
+	if (((ip=str2ip(name))!=0)
1476
+#ifdef	USE_IPV6
1477
+			  || ((ip=str2ip6(name))!=0)
1478
+#endif
1479
+			 ){
1480
+		/* we are lucky, this is an ip address */
1481
+		/* set proto if needed - default udp */
1482
+		if ((proto)&&(*proto==PROTO_NONE))
1483
+			*proto=PROTO_UDP;
1484
+		/* set port if needed - default 5060/5061 */
1485
+		if ((port)&&(*port==0))
1486
+			*port=((proto) && (*proto==PROTO_TLS))?SIPS_PORT:SIP_PORT;
1487
+		he=ip_addr2he(name, ip);
1488
+		return he;
1489
+	}
1490
+
1473 1491
 	if ((name->len+SRV_MAX_PREFIX_LEN+1)>MAX_DNS_NAME){
1474 1492
 		LOG(L_WARN, "WARNING: no_naptr_srv_sip_resolvehost: domain name too long"
1475 1493
 						" (%d), unable to perform SRV lookup\n", name->len);