git-svn: trunk@2956
Tomasz Kojm authored on 2007/03/21 01:11:12... | ... |
@@ -1,6 +1,11 @@ |
1 |
+Tue Mar 20 15:16:33 CET 2007 (tk) |
|
2 |
+--------------------------------- |
|
3 |
+ * freshclam/manager.c: close and re-open client socket for each connect |
|
4 |
+ attempt (bb#413), patch from Andy Fiddaman |
|
5 |
+ |
|
1 | 6 |
Tue Mar 20 14:17:35 CET 2007 (tk) |
2 | 7 |
--------------------------------- |
3 |
- * freshclam/mirman.c: fix --list-mirrors on Solaris/64, thanks to |
|
8 |
+ * freshclam/mirman.c: fix --list-mirrors on Solaris/64 (bb#414), thanks to |
|
4 | 9 |
Andy Fiddaman |
5 | 10 |
|
6 | 11 |
Mon Mar 19 23:31:38 CET 2007 (tk) |
... | ... |
@@ -77,20 +77,9 @@ |
77 | 77 |
#define closesocket(s) close(s) |
78 | 78 |
#endif |
79 | 79 |
|
80 |
-static int wwwconnect(const char *server, const char *proxy, int pport, char *ip, const char *localip, int ctimeout, struct mirdat *mdat) |
|
80 |
+static int getclientsock(const char *localip) |
|
81 | 81 |
{ |
82 |
- int socketfd = -1, port, i, ret; |
|
83 |
- struct sockaddr_in name; |
|
84 |
- struct hostent *host; |
|
85 |
- char ipaddr[16]; |
|
86 |
- unsigned char *ia; |
|
87 |
- const char *hostpt; |
|
88 |
- struct hostent *he = NULL; |
|
89 |
- |
|
90 |
- if(ip) |
|
91 |
- strcpy(ip, "???"); |
|
92 |
- |
|
93 |
- name.sin_family = AF_INET; |
|
82 |
+ int socketfd = -1; |
|
94 | 83 |
|
95 | 84 |
#ifdef PF_INET |
96 | 85 |
socketfd = socket(PF_INET, SOCK_STREAM, 0); |
... | ... |
@@ -104,6 +93,8 @@ static int wwwconnect(const char *server, const char *proxy, int pport, char *ip |
104 | 104 |
} |
105 | 105 |
|
106 | 106 |
if(localip) { |
107 |
+ struct hostent *he; |
|
108 |
+ |
|
107 | 109 |
if((he = gethostbyname(localip)) == NULL) { |
108 | 110 |
const char *herr; |
109 | 111 |
switch(h_errno) { |
... | ... |
@@ -131,6 +122,9 @@ static int wwwconnect(const char *server, const char *proxy, int pport, char *ip |
131 | 131 |
logg("^Using standard local ip address and port for fetching.\n"); |
132 | 132 |
} else { |
133 | 133 |
struct sockaddr_in client; |
134 |
+ unsigned char *ia; |
|
135 |
+ char ipaddr[16]; |
|
136 |
+ |
|
134 | 137 |
memset ((char *) &client, 0, sizeof(struct sockaddr_in)); |
135 | 138 |
client.sin_family = AF_INET; |
136 | 139 |
client.sin_addr = *(struct in_addr *) he->h_addr_list[0]; |
... | ... |
@@ -144,6 +138,28 @@ static int wwwconnect(const char *server, const char *proxy, int pport, char *ip |
144 | 144 |
} |
145 | 145 |
} |
146 | 146 |
} |
147 |
+ |
|
148 |
+ return socketfd; |
|
149 |
+} |
|
150 |
+ |
|
151 |
+static int wwwconnect(const char *server, const char *proxy, int pport, char *ip, const char *localip, int ctimeout, struct mirdat *mdat) |
|
152 |
+{ |
|
153 |
+ int socketfd = -1, port, i, ret; |
|
154 |
+ struct sockaddr_in name; |
|
155 |
+ struct hostent *host; |
|
156 |
+ char ipaddr[16]; |
|
157 |
+ unsigned char *ia; |
|
158 |
+ const char *hostpt; |
|
159 |
+ |
|
160 |
+ if(ip) |
|
161 |
+ strcpy(ip, "???"); |
|
162 |
+ |
|
163 |
+ socketfd = getclientsock(localip); |
|
164 |
+ if(socketfd < 0) |
|
165 |
+ return -1; |
|
166 |
+ |
|
167 |
+ name.sin_family = AF_INET; |
|
168 |
+ |
|
147 | 169 |
if(proxy) { |
148 | 170 |
hostpt = proxy; |
149 | 171 |
|
... | ... |
@@ -225,6 +241,10 @@ static int wwwconnect(const char *server, const char *proxy, int pport, char *ip |
225 | 225 |
if(connect(socketfd, (struct sockaddr *) &name, sizeof(struct sockaddr_in)) == -1) { |
226 | 226 |
#endif |
227 | 227 |
logg("Can't connect to port %d of host %s (IP: %s)\n", port, hostpt, ipaddr); |
228 |
+ close(socketfd); |
|
229 |
+ if((socketfd = getclientsock(localip)) == -1) |
|
230 |
+ return -1; |
|
231 |
+ |
|
228 | 232 |
continue; |
229 | 233 |
} else { |
230 | 234 |
mdat->currip = ((struct in_addr *) ia)->s_addr; |