diff -uNrd j5.dist/config.h j5/config.h
--- j5.dist/config.h	Tue Jul  2 10:57:50 2002
+++ j5/config.h	Tue Jul  2 11:11:40 2002
@@ -1,5 +1,7 @@
+#ifndef CONFIG_H
+#define CONFIG_H
 /* jupe configuration */
-#define SERVER_NAME      "127.0.0.1"    /* host and IP both work now */
+#define SERVER_NAME      "127.0.0.1"    /* host or IP, IPv4 or IPv6 */
 #define SERVER_PORT       6667
 #define SERVER_PASS	"blaf"          /* password in c/n */
 
@@ -13,3 +15,5 @@
 #undef PERSIST 				/* keep reconnecting and rejuping if
 					 * we are squit 
 					 */
+
+#endif
diff -uNrd j5.dist/io.c j5/io.c
--- j5.dist/io.c	Tue Jul  2 10:57:50 2002
+++ j5/io.c	Tue Jul  2 11:04:32 2002
@@ -14,51 +14,31 @@
 #include "io.h"
 #include "config.h"
 
+static struct addrinfo * gethostinfo(char const *host, int port);
+
 int SockOpen(const char *host, int clientPort)
 {
-    int sock;
-    struct sockaddr_in ad;
-    struct hostent *hp;
-
-    memset(&ad, 0, sizeof(ad));
-    ad.sin_family = AF_INET;
-
-    if ((hp = gethostbyname (host)) == NULL)
-        return -1;
-
-    /* vhost support code can be added here if desired */
-
-	/*
-	 * Add a check to make sure the address has a valid IPv4 or IPv6
-	 * length.  This prevents buffer spamming by a broken DNS.
-	 */
-	if (hp == NULL || (hp->h_length != 4 && hp->h_length != 8))
-	    return -1;
-
-	/*
-	 * FIXME: make this work for multihomed hosts.
-	 * We're toast if we get back multiple addresses and h_addrs[0]
-	 * (aka h_addr) is not one we can actually connect to; this happens
-	 * with multi-homed boxes.
-	 */
-	memcpy(&ad.sin_addr, hp->h_addr, hp->h_length);
-
-    ad.sin_port = htons(clientPort);
+    int sock = -1;
+    struct addrinfo *hostres, *res;
 
-    sock = socket(AF_INET, SOCK_STREAM, 0);
-    if (sock < 0)
-	return -errno;
-    
-    if (connect(sock, (struct sockaddr *) &ad, sizeof(ad)) < 0)
+    hostres = gethostinfo(host, clientPort);
+    for (res = hostres; res; res = res->ai_next)
     {
-	close(sock);
-	return -errno;
+      sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
+      if (sock < 0)
+        continue;
+      if (connect(sock, res->ai_addr, res->ai_addrlen) == 0)
+        break;
+      close(sock);
+      return -errno;
     }
-    
+    freeaddrinfo(hostres);
+    if (res == NULL)
+      return -1;
+
     return sock;
 }
 
-
 int SockPrintf(int sock, char *format,...)
 {
     va_list ap;
@@ -136,4 +116,22 @@
     printf("%s", cbuf);
     fflush(stdout);
 #endif
+}
+
+/* Stolen from FreeBSD's whois client, modified for jupe by W. Campbell */
+static struct addrinfo * gethostinfo(char const *host, int port)
+{
+        struct addrinfo hints, *res;
+        int error;
+        char portbuf[6];
+
+        memset(&hints, 0, sizeof(hints));
+        hints.ai_flags = 0;
+        hints.ai_family = AF_UNSPEC;
+        hints.ai_socktype = SOCK_STREAM;
+        snprintf(portbuf, 6, "%d", port);
+        error = getaddrinfo(host, portbuf, &hints, &res);
+        if (error)
+                return (NULL);
+        return (res);
 }

