View | Details | Raw Unified | Return to bug 2814 | Differences between
and this patch

Collapse All | Expand All

(-)a/sshconnect.c (-4 / +11 lines)
Lines 404-410 ssh_connect_direct(struct ssh *ssh, const char *host, struct addrinfo *aitop, Link Here
404
    int connection_attempts, int *timeout_ms, int want_keepalive, int needpriv)
404
    int connection_attempts, int *timeout_ms, int want_keepalive, int needpriv)
405
{
405
{
406
	int on = 1;
406
	int on = 1;
407
	int sock = -1, attempt;
407
	int oerrno, sock = -1, attempt;
408
	char ntop[NI_MAXHOST], strport[NI_MAXSERV];
408
	char ntop[NI_MAXHOST], strport[NI_MAXSERV];
409
	struct addrinfo *ai;
409
	struct addrinfo *ai;
410
410
Lines 424-435 ssh_connect_direct(struct ssh *ssh, const char *host, struct addrinfo *aitop, Link Here
424
		 */
424
		 */
425
		for (ai = aitop; ai; ai = ai->ai_next) {
425
		for (ai = aitop; ai; ai = ai->ai_next) {
426
			if (ai->ai_family != AF_INET &&
426
			if (ai->ai_family != AF_INET &&
427
			    ai->ai_family != AF_INET6)
427
			    ai->ai_family != AF_INET6) {
428
				errno = EAFNOSUPPORT;
428
				continue;
429
				continue;
430
			}
429
			if (getnameinfo(ai->ai_addr, ai->ai_addrlen,
431
			if (getnameinfo(ai->ai_addr, ai->ai_addrlen,
430
			    ntop, sizeof(ntop), strport, sizeof(strport),
432
			    ntop, sizeof(ntop), strport, sizeof(strport),
431
			    NI_NUMERICHOST|NI_NUMERICSERV) != 0) {
433
			    NI_NUMERICHOST|NI_NUMERICSERV) != 0) {
434
				oerrno = errno;
432
				error("%s: getnameinfo failed", __func__);
435
				error("%s: getnameinfo failed", __func__);
436
				errno = oerrno;
433
				continue;
437
				continue;
434
			}
438
			}
435
			debug("Connecting to %.200s [%.100s] port %s.",
439
			debug("Connecting to %.200s [%.100s] port %s.",
Lines 439-444 ssh_connect_direct(struct ssh *ssh, const char *host, struct addrinfo *aitop, Link Here
439
			sock = ssh_create_socket(needpriv, ai);
443
			sock = ssh_create_socket(needpriv, ai);
440
			if (sock < 0)
444
			if (sock < 0)
441
				/* Any error is already output */
445
				/* Any error is already output */
446
				errno = 0;
442
				continue;
447
				continue;
443
448
444
			if (timeout_connect(sock, ai->ai_addr, ai->ai_addrlen,
449
			if (timeout_connect(sock, ai->ai_addr, ai->ai_addrlen,
Lines 447-456 ssh_connect_direct(struct ssh *ssh, const char *host, struct addrinfo *aitop, Link Here
447
				memcpy(hostaddr, ai->ai_addr, ai->ai_addrlen);
452
				memcpy(hostaddr, ai->ai_addr, ai->ai_addrlen);
448
				break;
453
				break;
449
			} else {
454
			} else {
455
				oerrno = errno;
450
				debug("connect to address %s port %s: %s",
456
				debug("connect to address %s port %s: %s",
451
				    ntop, strport, strerror(errno));
457
				    ntop, strport, strerror(errno));
452
				close(sock);
458
				close(sock);
453
				sock = -1;
459
				sock = -1;
460
				errno = oerrno;
454
			}
461
			}
455
		}
462
		}
456
		if (sock != -1)
463
		if (sock != -1)
Lines 460-467 ssh_connect_direct(struct ssh *ssh, const char *host, struct addrinfo *aitop, Link Here
460
	/* Return failure if we didn't get a successful connection. */
467
	/* Return failure if we didn't get a successful connection. */
461
	if (sock == -1) {
468
	if (sock == -1) {
462
		error("ssh: connect to host %s port %s: %s",
469
		error("ssh: connect to host %s port %s: %s",
463
		    host, strport, strerror(errno));
470
		    host, strport, errno == 0 ? "failure" : strerror(errno));
464
		return (-1);
471
		return -1;
465
	}
472
	}
466
473
467
	debug("Connection established.");
474
	debug("Connection established.");

Return to bug 2814