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