Browse Source

* Fix bot linking so it does not use IPv6 if not supported.

Bryan Drewery 16 years ago
parent
commit
ab05d15e22
2 changed files with 20 additions and 3 deletions
  1. 1 0
      doc/UPDATES
  2. 19 3
      src/botnet.c

+ 1 - 0
doc/UPDATES

@@ -1,4 +1,5 @@
 * Fix cmd_relay so it does not use IPv6 if not supported.
+* Fix bot linking so it does not use IPv6 if not supported.
 
 1.3 - http://wraith.botpack.net/milestone/1.3
 * Binary / shell / startup changes

+ 19 - 3
src/botnet.c

@@ -1048,13 +1048,29 @@ static void botlink_dns_callback(int id, void *client_data, const char *host, bd
 //    idx = dcc[i].u.dns->ibuf;
 //  }
 
-  if (!ips.size()) {
+  bd::String ip_from_dns;
+
+  if (ips.size()) {
+#ifdef USE_IPV6
+    /* If IPv6 is available use it, otherwise fall back on IPv4 */
+    if (conf.bot->net.v6)
+      ip_from_dns = dns_find_ip(ips, AF_INET6);
+    if (!ip_from_dns)
+#endif /* USE_IPV6 */
+    {
+      /* Use IPv4 if no ipv6 is available */
+      ip_from_dns = dns_find_ip(ips, AF_INET);
+    }
+  }
+
+  if (!ips.size() || !ip_from_dns) {
+    putlog(LOG_BOTS, "*", "Could not link to %s (DNS error).\n", dcc[i].nick);
     lostdcc(i);
     return;
   }
 
-  dcc[i].addr = inet_addr(bd::String(ips[0]).c_str());
-  strlcpy(dcc[i].host, bd::String(ips[0]).c_str(), sizeof(dcc[i].host));
+  dcc[i].addr = inet_addr(ip_from_dns.c_str());
+  strlcpy(dcc[i].host, ip_from_dns.c_str(), sizeof(dcc[i].host));
 
   botlink_real(i);
 }