Package: xchat
Version: 2.6.4-2
Tags: patch

Hi,

on the OFTC irc network we notice that xchat clients do not usually pick
a random server out of the rotation but instead a significant percentage
of new connects all go to the same server, and other servers from the
rotation are ignored.

The reason is that getaddrinfo(), which xchat uses to resolve hostname,
does not do a round robin, but sorts the hosts in some weird order.
We don't think this is wanted by xchat, and we certainly would prefer if
xchat just picked a random node.


xchat already has a means to randomize dns rotations, but it only does
it when LOOKUPD is defined.   I guess it would make sense to randomize
all the time, so this patch removes the ifdef.

Please apply to the Debian package and please also convince upstream to
merge.

Thank you.
-- 
                           |  .''`.  ** Debian GNU/Linux **
      Peter Palfrader      | : :' :      The  universal
 http://www.palfrader.org/ | `. `'      Operating System
                           |   `-    http://www.debian.org/
diff -Nur xchat-2.6.4/src/common/network.c 
xchat-2.6.4.proper.randomize/src/common/network.c
--- xchat-2.6.4/src/common/network.c    2006-08-30 22:12:19.060000000 +0200
+++ xchat-2.6.4.proper.randomize/src/common/network.c   2006-08-30 
22:25:02.531000000 +0200
@@ -24,7 +24,7 @@
 #include <unistd.h>
 #include <glib.h>
 
-#include "../../config.h"                                /* grab USE_IPV6 and 
LOOKUPD defines */
+#include "../../config.h"                                /* grab USE_IPV6 
defines */
 
 #define WANTSOCKET
 #define WANTARPA
@@ -104,16 +104,13 @@
                return NULL;
 
        memset (&ns->addr, 0, sizeof (ns->addr));
-#ifdef LOOKUPD
+
        int count = 0;
        while (ns->ip4_hostent->h_addr_list[count]) count++;
        memcpy (&ns->addr.sin_addr,
                        ns->ip4_hostent->h_addr_list[RAND_INT(count)],
                        ns->ip4_hostent->h_length);
-#else
-       memcpy (&ns->addr.sin_addr, ns->ip4_hostent->h_addr,
-                         ns->ip4_hostent->h_length);
-#endif
+
        ns->addr.sin_port = htons (port);
        ns->addr.sin_family = AF_INET;
 
@@ -211,7 +208,6 @@
        if (ret != 0)
                return NULL;
 
-#ifdef LOOKUPD /* See note about lookupd above the IPv4 version of 
net_resolve. */
        struct addrinfo *tmp;
        int count = 0;
 
@@ -221,7 +217,6 @@
        count = RAND_INT(count);
        
        while (count--) ns->ip6_hostent = ns->ip6_hostent->ai_next;
-#endif
 
        /* find the numeric IP number */
        ipstring[0] = 0;
diff -Nur xchat-2.6.4/src/common/server.c 
xchat-2.6.4.proper.randomize/src/common/server.c
--- xchat-2.6.4/src/common/server.c     2006-05-27 17:51:38.000000000 +0200
+++ xchat-2.6.4.proper.randomize/src/common/server.c    2006-08-30 
22:30:44.768000000 +0200
@@ -1672,9 +1672,9 @@
                                                                                
(LPTHREAD_START_ROUTINE)server_child,
                                                                                
serv, 0, (DWORD *)&pid));
 #else
-#ifdef LOOKUPD
-       rand(); /* CL: net_resolve calls rand() when LOOKUPD is set, so prepare 
a different seed for each child. This method giver a bigger variation in seed 
values than calling srand(time(0)) in the child itself. */
-#endif
+
+       rand(); /* CL: net_resolve calls rand(), so prepare a different seed 
for each child. This method giver a bigger variation in seed values than 
calling srand(time(0)) in the child itself. */
+
        switch (pid = fork ())
        {
        case -1:
diff -Nur xchat-2.6.4.proper.randomize/configure.in 
xchat-2.6.4.proper.randomize.cleanup/configure.in
--- xchat-2.6.4.proper.randomize/configure.in   2006-06-05 16:06:22.000000000 
+0200
+++ xchat-2.6.4.proper.randomize.cleanup/configure.in   2006-08-30 
22:27:58.832000000 +0200
@@ -708,12 +708,6 @@
        AC_DEFINE(socklen_t, int)
 fi
 
-dnl Mac OS X and Darwin use lookupd, which caches DNS queries by default
-AC_EGREP_CPP(lookupd, dnl
-[#if (defined(__APPLE__) && defined(__MACH__))
-       lookupd
-#endif], AC_DEFINE([LOOKUPD],1,[Define to 1 if the system uses lookupd]))
-
 dnl freebsd needs this
 LIBS="$LIBS $INTLLIBS"
 CFLAGS="$CFLAGS $CPPFLAGS"

Reply via email to