socket-connect.c: check last_errno after all connections fail
example--
Looking up ftp.gnome.org
Trying openshift.gnome.org:21 (8.43.85.29)
Cannot connect to openshift.gnome.org: No route to host
Trying 8.43.85.13:21
Cannot connect to 8.43.85.13: No route to host
Trying 8.43.85.14:21
Cannot connect to 8.43.85.14: No route to host
@@ -92,6 +92,7 @@ gftp_connect_server_with_getaddrinfo (gftp_request * request, char *service,
struct addrinfo *res, *hostp, *current_hostp;
struct sockaddr_in * addrin;
char ipstr[128], * hostname;
+ int last_errno = 0;
unsigned int port;
int sock = -1;
struct timeval timeout;
@@ -144,14 +145,7 @@ gftp_connect_server_with_getaddrinfo (gftp_request * request, char *service,
_("Cannot connect to %s: %s\n"),
hostname, g_strerror (errno));
close (sock);
- switch (errno)
- {
- case EINVAL: /* Invalid argument */
- case EHOSTUNREACH: /* No route to host */
- freeaddrinfo (hostp);
- return GFTP_EFATAL;
- ;;
- }
+ last_errno = errno;
continue;
}
@@ -165,8 +159,16 @@ gftp_connect_server_with_getaddrinfo (gftp_request * request, char *service,
if (hostp != NULL)
freeaddrinfo (hostp);
+ switch (last_errno)
+ {
+ case EINVAL: /* Invalid argument */
+ case EHOSTUNREACH: /* No route to host */
+ return GFTP_EFATAL;
+ break;
+ default:
return (GFTP_ERETRYABLE);
}
+ }
request->remote_addr_len = current_hostp->ai_addrlen;
request->remote_addr = g_malloc0 (request->remote_addr_len);
