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 1470
 	he=0;
1471 1471
 	len=0;
1472 1472
 
1473
+	/* check if it's an ip address */
1474
+	if (((ip=str2ip(name))!=0)
1475
+#ifdef	USE_IPV6
1476
+			  || ((ip=str2ip6(name))!=0)
1477
+#endif
1478
+			 ){
1479
+		/* we are lucky, this is an ip address */
1480
+		/* set proto if needed - default udp */
1481
+		if ((proto)&&(*proto==PROTO_NONE))
1482
+			*proto=PROTO_UDP;
1483
+		/* set port if needed - default 5060/5061 */
1484
+		if ((port)&&(*port==0))
1485
+			*port=((proto) && (*proto==PROTO_TLS))?SIPS_PORT:SIP_PORT;
1486
+		he=ip_addr2he(name, ip);
1487
+		return he;
1488
+	}
1489
+
1473 1490
 	if ((name->len+SRV_MAX_PREFIX_LEN+1)>MAX_DNS_NAME){
1474 1491
 		LOG(L_WARN, "WARNING: no_naptr_srv_sip_resolvehost: domain name too long"
1475 1492
 						" (%d), unable to perform SRV lookup\n", name->len);