Explorar el Código

* Fix cmd_relay so it does not use IPv6 if not supported.

Bryan Drewery hace 16 años
padre
commit
15a2b2c7d5
Se han modificado 2 ficheros con 22 adiciones y 5 borrados
  1. 2 0
      doc/UPDATES
  2. 20 5
      src/botnet.c

+ 2 - 0
doc/UPDATES

@@ -1,3 +1,5 @@
+* Fix cmd_relay so it does not use IPv6 if not supported.
+
 1.3 - http://wraith.botpack.net/milestone/1.3
 * Binary / shell / startup changes
   * Binary error messages are no longer obscure numbers or fake segfaults. (Compile with OBSCURE_ERRORS to re-enable)

+ 20 - 5
src/botnet.c

@@ -1215,10 +1215,25 @@ static void tandem_relay_dns_callback(int id, void *client_data, const char *hos
     return;
   }
 
-  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) {
     struct chat_info *ci = dcc[idx].u.relay->chat;
 
-    dprintf(idx, "Could not relay to %s.\n", dcc[i].nick);
+    dprintf(idx, "Could not relay to %s (DNS error).\n", dcc[i].nick);
     dcc[idx].status = dcc[idx].u.relay->old_status;
     free(dcc[idx].u.relay);
     dcc[idx].u.chat = ci;
@@ -1228,7 +1243,7 @@ static void tandem_relay_dns_callback(int id, void *client_data, const char *hos
   }
 
 #ifdef USE_IPV6
-  int af = is_dotted_ip(bd::String(ips[0]).c_str());
+  int af = is_dotted_ip(ip_from_dns.c_str());
 
   dcc[i].sock = getsock(SOCK_STRONGCONN | SOCK_VIRTUAL, af);
 #else
@@ -1244,7 +1259,7 @@ static void tandem_relay_dns_callback(int id, void *client_data, const char *hos
 
   changeover_dcc(i, &DCC_FORK_RELAY, sizeof(struct relay_info));
 
-  dcc[i].addr = inet_addr(bd::String(ips[0]).c_str());
+  dcc[i].addr = inet_addr(ip_from_dns.c_str());
 
   dcc[i].u.relay->chat = (struct chat_info *) my_calloc(1, sizeof(struct chat_info));
   dcc[i].u.relay->sock = dcc[idx].sock;
@@ -1261,7 +1276,7 @@ static void tandem_relay_dns_callback(int id, void *client_data, const char *hos
   dcc[i].u.relay->chat->current_lines = 0;
   dcc[i].timeval = now;
 
-  if (open_telnet_raw(dcc[i].sock, bd::String(ips[0]).c_str(), dcc[i].port, 0) < 0) {
+  if (open_telnet_raw(dcc[i].sock, ip_from_dns.c_str(), dcc[i].port, 0) < 0) {
     dcc[i].sock = -1;
     failed_tandem_relay(i);
   }