summaryrefslogtreecommitdiff
path: root/sshconnect.c
diff options
context:
space:
mode:
Diffstat (limited to 'sshconnect.c')
-rw-r--r--sshconnect.c29
1 files changed, 9 insertions, 20 deletions
diff --git a/sshconnect.c b/sshconnect.c
index 5cf107794..5f2ad1cfa 100644
--- a/sshconnect.c
+++ b/sshconnect.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshconnect.c,v 1.180 2006/03/25 13:17:02 djm Exp $ */ 1/* $OpenBSD: sshconnect.c,v 1.181 2006/04/20 09:47:59 markus Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -306,17 +306,14 @@ ssh_connect(const char *host, struct sockaddr_storage * hostaddr,
306 fatal("%s: %.100s: %s", __progname, host, 306 fatal("%s: %.100s: %s", __progname, host,
307 gai_strerror(gaierr)); 307 gai_strerror(gaierr));
308 308
309 /* 309 for (attempt = 0; attempt < connection_attempts; attempt++) {
310 * Try to connect several times. On some machines, the first time
311 * will sometimes fail. In general socket code appears to behave
312 * quite magically on many machines.
313 */
314 for (attempt = 0; ;) {
315 if (attempt > 0) 310 if (attempt > 0)
316 debug("Trying again..."); 311 debug("Trying again...");
317 312
318 /* Loop through addresses for this host, and try each one in 313 /*
319 sequence until the connection succeeds. */ 314 * Loop through addresses for this host, and try each one in
315 * sequence until the connection succeeds.
316 */
320 for (ai = aitop; ai; ai = ai->ai_next) { 317 for (ai = aitop; ai; ai = ai->ai_next) {
321 if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6) 318 if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6)
322 continue; 319 continue;
@@ -343,21 +340,13 @@ ssh_connect(const char *host, struct sockaddr_storage * hostaddr,
343 } else { 340 } else {
344 debug("connect to address %s port %s: %s", 341 debug("connect to address %s port %s: %s",
345 ntop, strport, strerror(errno)); 342 ntop, strport, strerror(errno));
346 /*
347 * Close the failed socket; there appear to
348 * be some problems when reusing a socket for
349 * which connect() has already returned an
350 * error.
351 */
352 close(sock); 343 close(sock);
344 sock = -1;
353 } 345 }
354 } 346 }
355 if (ai) 347 if (sock != -1)
356 break; /* Successful connection. */ 348 break; /* Successful connection. */
357 349
358 attempt++;
359 if (attempt >= connection_attempts)
360 break;
361 /* Sleep a moment before retrying. */ 350 /* Sleep a moment before retrying. */
362 sleep(1); 351 sleep(1);
363 } 352 }
@@ -365,7 +354,7 @@ ssh_connect(const char *host, struct sockaddr_storage * hostaddr,
365 freeaddrinfo(aitop); 354 freeaddrinfo(aitop);
366 355
367 /* Return failure if we didn't get a successful connection. */ 356 /* Return failure if we didn't get a successful connection. */
368 if (attempt >= connection_attempts) { 357 if (sock == -1) {
369 error("ssh: connect to host %s port %s: %s", 358 error("ssh: connect to host %s port %s: %s",
370 host, strport, strerror(errno)); 359 host, strport, strerror(errno));
371 return (-1); 360 return (-1);