--- jwhois-4.0-orig/src/utils.c	2007-06-26 10:00:20.000000000 +0300
+++ jwhois-4.0/src/utils.c	2011-06-18 11:52:56.692453113 +0300
@@ -191,7 +191,7 @@ make_connect(const char *host, int port)
 {
   int sockfd, error, flags, retval, retlen;
   fd_set fdset;
-  struct timeval timeout = { connect_timeout, 0 };
+  struct timeval timeout;
 
 #ifdef HAVE_GETADDRINFO
   struct addrinfo *res;
@@ -269,10 +269,9 @@ make_connect(const char *host, int port)
 	  return -1;
 	}
 
-
       error = connect(sockfd, res->ai_addr, res->ai_addrlen);
 
-      if (error < 0 && errno != EINPROGRESS)
+      if (error == 0 || (error < 0 && errno != EINPROGRESS))
 	{
 	  break;
 	}
@@ -280,21 +279,23 @@ make_connect(const char *host, int port)
       FD_ZERO(&fdset);
       FD_SET(sockfd, &fdset);
 
+      timeout.tv_sec = connect_timeout;
+      timeout.tv_usec = 0;
       error = select(FD_SETSIZE, NULL, &fdset, NULL, &timeout);
-      if (error == 0)
+      if (error == 1)
 	{
 	  break;
 	}
 
       retlen = sizeof(retval);
       error = getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &retval, &retlen);
+      close(sockfd);
       if (error < 0 || retval)
 	{
-	  break;
+	  return -1;
 	}
       res = res->ai_next;
     }
-  if (error < 0 || retval) return -1;
 #endif
 
   return sockfd;
