diff options
-rw-r--r-- | src/s_client.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/s_client.c b/src/s_client.c index 863dd12..ba1238f 100644 --- a/src/s_client.c +++ b/src/s_client.c @@ -83,15 +83,15 @@ connect_socket(const char *host, const char *port) if (sfd == -1) { continue; } - if (connect(sfd, rp->ai_addr, rp->ai_addrlen) != -1) { - break; + if (connect(sfd, rp->ai_addr, rp->ai_addrlen) == -1) { + close(sfd); + continue; } - close(sfd); + break; } if (rp == NULL) { fputs("Failed to connect\n", stderr); - freeaddrinfo(result); - return -1; + sfd = -1; } freeaddrinfo(result); |