Replace whois by jwhois.
[ipfire-2.x.git] / src / patches / jwhois-4.0-connect.patch
1 This fixes somewhat reversed logic of trying to connect to WHOIS server.
2 Tue Nov 20 2007, Lubomir Kundrak <lkundrak@redhat.com>
3
4 --- jwhois-4.0/src/utils.c.connect 2007-06-26 09:00:20.000000000 +0200
5 +++ jwhois-4.0/src/utils.c 2007-11-20 17:05:33.000000000 +0100
6 @@ -247,7 +247,7 @@ make_connect(const char *host, int port)
7 {
8 return -1;
9 }
10 - while (res)
11 + for (; res; res = res->ai_next)
12 {
13 sa = res->ai_addr;
14 sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
15 @@ -266,15 +266,15 @@ make_connect(const char *host, int port)
16 flags = fcntl(sockfd, F_GETFL, 0);
17 if (fcntl(sockfd, F_SETFL, flags|O_NONBLOCK) == -1)
18 {
19 + close (sockfd);
20 return -1;
21 }
22
23 -
24 error = connect(sockfd, res->ai_addr, res->ai_addrlen);
25 -
26 if (error < 0 && errno != EINPROGRESS)
27 {
28 - break;
29 + close (sockfd);
30 + continue;
31 }
32
33 FD_ZERO(&fdset);
34 @@ -283,18 +283,20 @@ make_connect(const char *host, int port)
35 error = select(FD_SETSIZE, NULL, &fdset, NULL, &timeout);
36 if (error == 0)
37 {
38 - break;
39 + close (sockfd);
40 + return -1;
41 }
42
43 retlen = sizeof(retval);
44 error = getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &retval, &retlen);
45 if (error < 0 || retval)
46 {
47 - break;
48 + close (sockfd);
49 + return -1;
50 }
51 - res = res->ai_next;
52 +
53 + break;
54 }
55 - if (error < 0 || retval) return -1;
56 #endif
57
58 return sockfd;