diff --git a/src/connect.c b/src/connect.c index 5ddd149f..807b1faf 100644 --- a/src/connect.c +++ b/src/connect.c @@ -382,7 +382,15 @@ socket_t ssh_connect_host_nonblocking(ssh_session session, const char *host, continue; } - connect(s, itr->ai_addr, itr->ai_addrlen); + rc = connect(s, itr->ai_addr, itr->ai_addrlen); + if (rc == -1) { + ssh_set_error(session, SSH_FATAL, + "Failed to connect: %s", strerror(errno)); + ssh_connect_socket_close(s); + s = -1; + continue; + } + break; }