diff --git a/client/http_resolve_host.c b/client/http_resolve_host.c index 69f054ea..b3f2ddc8 100644 --- a/client/http_resolve_host.c +++ b/client/http_resolve_host.c @@ -54,7 +54,7 @@ struct url static int try_url(struct url *url, fko_cli_options_t *options) { - int sock=-1, res, error, http_buf_len, i; + int sock=-1, sock_success=0, res, error, http_buf_len, i; int bytes_read = 0, position = 0; int o1, o2, o3, o4; struct addrinfo *result, *rp, hints; @@ -108,19 +108,20 @@ try_url(struct url *url, fko_cli_options_t *options) continue; if ((error = (connect(sock, rp->ai_addr, rp->ai_addrlen) != -1))) + { + sock_success = 1; break; /* made it */ + } + } + if (! sock_success) + { + log_msg(LOG_VERBOSITY_ERROR, "resolve_ip_http: Could not create socket: ", strerror(errno)); #ifdef WIN32 closesocket(sock); #else close(sock); #endif - } - - if (rp == NULL) - { - log_msg(LOG_VERBOSITY_ERROR, "resolve_ip_http: Could not create socket: ", strerror(errno)); - close(sock); return(-1); } diff --git a/client/spa_comm.c b/client/spa_comm.c index e5f05677..51b57880 100644 --- a/client/spa_comm.c +++ b/client/spa_comm.c @@ -86,7 +86,7 @@ static int send_spa_packet_tcp_or_udp(const char *spa_data, const int sd_len, const fko_cli_options_t *options) { - int sock, res=0, error; + int sock=-1, sock_success=0, res=0, error; struct addrinfo *result, *rp, hints; char port_str[MAX_PORT_STR_LEN+1] = {0}; @@ -134,16 +134,13 @@ send_spa_packet_tcp_or_udp(const char *spa_data, const int sd_len, continue; if ((error = (connect(sock, rp->ai_addr, rp->ai_addrlen) != -1))) + { + sock_success = 1; break; /* made it */ - -#ifdef WIN32 - closesocket(sock); -#else - close(sock); -#endif + } } - if (rp == NULL) { + if (! sock_success) { log_msg(LOG_VERBOSITY_ERROR, "send_spa_packet_tcp_or_udp: Could not create socket: ", strerror(errno));