--- orig/iconvircproxy-1.6.3.1/ircproxy.cc	2009-06-07 00:43:11.000000000 +0600
+++ iconvircproxy-1.6.3.1-rm/ircproxy.cc	2009-10-14 00:26:10.995050364 +0600
@@ -1,3 +1,4 @@
+#include <stdlib.h>
 #include <sys/fcntl.h>
 #include <sys/stat.h>
 
@@ -438,6 +439,28 @@
     }
 };
 
+struct sockaddr *ResolveHost(const char *name, int family)
+{
+  struct addrinfo *ai = NULL, hints;
+
+  memset(&hints, 0, sizeof(hints));
+  hints.ai_family = family;
+  hints.ai_flags = AI_ADDRCONFIG;
+  
+  if (!getaddrinfo(name, NULL, &hints, &ai) && ai) {
+    void *tmp;
+
+    tmp = malloc(ai->ai_addrlen);
+    memcpy(tmp, ai->ai_addr, ai->ai_addrlen);
+
+    freeaddrinfo(ai);
+
+    return (struct sockaddr*) tmp;
+  }
+
+  return NULL;
+}
+
 static bool ReadWrite(SockStream& inf, SockStream& outf)
 {
     std::string line = inf.ReadLine();
@@ -457,27 +480,21 @@
 
 static SockStream ConnectIRC()
 {
-    struct sockaddr_in MyAddr;
+    struct sockaddr *sa = NULL;
     
-    struct hostent *HostName = gethostbyname(GetServer().c_str());
-    if(!HostName)
-    {
-        throw "ConnectIRC::gethostbyname";
-    }
-
-    memset(&MyAddr, 0, sizeof(MyAddr));
+    if (!(sa = ResolveHost(GetServer().c_str(), AF_UNSPEC))) {
+        throw "ConnectIRC::ResolveHost";
+    }    
 
-    MyAddr.sin_family = AF_INET;
-    MyAddr.sin_port = htons(GetServerPort());
-    memcpy(&MyAddr.sin_addr, HostName->h_addr, HostName->h_length);
-
-    int Plug = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+    ((struct sockaddr_in*) sa)->sin_port = htons(GetServerPort());
+    
+    int Plug = socket(sa->sa_family, SOCK_STREAM, IPPROTO_TCP);
     if(Plug < 0)
     {
         throw "ConnectIRC::socket";
     }
     
-    if(connect(Plug, (struct sockaddr*)&MyAddr, sizeof(MyAddr)) == -1)
+    if(connect(Plug, sa, (sa->sa_family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6)) == -1)
     {
         close(Plug);
         throw "ConnectIRC::connect";
@@ -498,7 +515,6 @@
 #endif
 }
 
-
 #ifndef WIN32
 /* POSIX version */
 static void ClientLoop(SockStream& user, SockStream& server)
@@ -682,15 +698,14 @@
 #ifndef WIN32
     for(int fd=0;fd<512;++fd) { if(fd != STDERR_FILENO) close(fd); }
 #endif
-    struct sockaddr_in MyAddr, They;
+    struct sockaddr_in6 MyAddr, They;
     
     memset(&MyAddr, 0, sizeof(MyAddr));
 
-    MyAddr.sin_family = AF_INET;
-    MyAddr.sin_port = htons(GetListenPort());
-    MyAddr.sin_addr.s_addr = htonl(INADDR_ANY); /* auto-fill with my IP, network long  */
+    MyAddr.sin6_family = AF_INET6;
+    MyAddr.sin6_port = htons(GetListenPort());
 
-    int Plug = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+    int Plug = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
     if(Plug < 0) { ReportSocketError("main::socket"); return -errno; }
     
 #ifndef WIN32
@@ -699,7 +714,7 @@
     setsockopt(Plug, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof flag);
 #endif
 
-    if(bind(Plug, (struct sockaddr *)&MyAddr, sizeof(struct sockaddr)))
+    if(bind(Plug, (struct sockaddr *)&MyAddr, sizeof(MyAddr)))
     {
         ReportSocketError("main::bind");
         close(Plug);

