Explorar el Código

* When looking up own IPs, only as A or AAAA depending on what is needed

Bryan Drewery hace 16 años
padre
commit
0f9d6d570a
Se han modificado 2 ficheros con 12 adiciones y 12 borrados
  1. 6 6
      src/adns.c
  2. 6 6
      src/net.c

+ 6 - 6
src/adns.c

@@ -549,9 +549,9 @@ int egg_dns_lookup(const char *host, interval_t timeout, dns_callback_t callback
 	return(q->id);
 }
 
-bd::Array<bd::String> dns_send_blocking(dns_query_t* q, interval_t timeout) {
+bd::Array<bd::String> dns_send_blocking(dns_query_t* q, interval_t timeout, int type = DEFAULT_DNS_TYPE) {
 	bd::Array<bd::String> answer;
-	dns_send_query_blocking(q);
+	dns_send_query_blocking(q, type);
 
 	char buf[512] = "";
 	int atr;
@@ -598,7 +598,7 @@ read_more:
 	return answer;
 }
 
-bd::Array<bd::String> dns_blocking_loop(const char* what, interval_t timeout, const char* from, bool is_ip = 0) {
+bd::Array<bd::String> dns_blocking_loop(const char* what, interval_t timeout, const char* from, int type = DEFAULT_DNS_TYPE, bool is_ip = 0) {
 	/* Allocate our query struct. */
 	dns_query_t *q = NULL;
 	bd::Array<bd::String> answer;
@@ -611,7 +611,7 @@ try_again:
 
 	sdprintf("%s(%s, %d) -> %d", from, what, timeout, q->id);
 	if (cnt++ < nservers) {
-		answer = dns_send_blocking(q, timeout);
+		answer = dns_send_blocking(q, timeout, type);
 		// No answers received?? Blocking DNS demands an answer, check the next server.
 		if (answer.size() == 0 && cnt < nservers) {
 			dns_on_eof(dns_idx);
@@ -650,7 +650,7 @@ bd::Array<bd::String> dns_lookup_block(const char *host, interval_t timeout, int
 		return *(cache[cache_id].answer);
 	}
 
-	return dns_blocking_loop(host, timeout, "dns_lookup_block");
+	return dns_blocking_loop(host, timeout, "dns_lookup_block", type);
 }
 
 /* Perform a blocking dns reverse lookup. This does ip -> host. For host -> ip
@@ -683,7 +683,7 @@ bd::Array<bd::String> dns_reverse_block(const char *ip, interval_t timeout)
 		return *(cache[cache_id].answer);
 	}
 
-	return dns_blocking_loop(ip, timeout, "dns_reverse_block", 1);
+	return dns_blocking_loop(ip, timeout, "dns_reverse_block", 0, 1);
 }
 
 /* Perform an async dns reverse lookup. This does ip -> host. For host -> ip

+ 6 - 6
src/net.c

@@ -112,7 +112,7 @@ int sockprotocol(int sock)
 }
 
 /* AF_INET-independent resolving routine */
-static int get_ip(char *hostname, union sockaddr_union *so)
+static int get_ip(char *hostname, union sockaddr_union *so, int dns_type)
 {
   if (!hostname || (hostname && !hostname[0]))
     return 1;
@@ -120,7 +120,7 @@ static int get_ip(char *hostname, union sockaddr_union *so)
   memset(so, 0, sizeof(union sockaddr_union));
   debug1("get_ip(%s)", hostname);
 
-  bd::Array<bd::String> hosts = dns_lookup_block(hostname, 20);
+  bd::Array<bd::String> hosts = dns_lookup_block(hostname, 10, dns_type);
   if (hosts.length() == 0)
     return -1;
 
@@ -210,10 +210,10 @@ void cache_my_ip()
   memset(&cached_myip6_so, 0, sizeof(union sockaddr_union));
 
   if (conf.bot->net.ip6) {
-    if (get_ip(conf.bot->net.ip6, &cached_myip6_so))
+    if (get_ip(conf.bot->net.ip6, &cached_myip6_so, DNS_LOOKUP_AAAA))
       any = 1;
   } else if (conf.bot->net.host6) {
-    if (get_ip(conf.bot->net.host6, &cached_myip6_so))
+    if (get_ip(conf.bot->net.host6, &cached_myip6_so, DNS_LOOKUP_AAAA))
       any = 1;
   } else
     any = 1;
@@ -225,10 +225,10 @@ void cache_my_ip()
 #endif /* USE_IPV6 */
 
   if (conf.bot->net.ip) {
-    if (get_ip(conf.bot->net.ip, &cached_myip4_so))
+    if (get_ip(conf.bot->net.ip, &cached_myip4_so, DNS_LOOKUP_A))
       error = 1;
   } else if (conf.bot->net.host) {
-    if (get_ip(conf.bot->net.host, &cached_myip4_so))
+    if (get_ip(conf.bot->net.host, &cached_myip4_so, DNS_LOOKUP_A))
       error = 2;
   } else {
 /*