View | Details | Raw Unified | Return to bug 1742
Collapse All | Expand All

(-)openssh-5.4p1/ssh.c (+4 lines)
Lines 671-680 Link Here
671
		options.user = xstrdup(pw->pw_name);
671
		options.user = xstrdup(pw->pw_name);
672
672
673
	/* Get default port if port has not been set. */
673
	/* Get default port if port has not been set. */
674
	/* 
675
	 * This is probably the wrong place to set the default port anyway.
676
	 * It should be done inside ssh_connect.
674
	if (options.port == 0) {
677
	if (options.port == 0) {
675
		sp = getservbyname(SSH_SERVICE_NAME, "tcp");
678
		sp = getservbyname(SSH_SERVICE_NAME, "tcp");
676
		options.port = sp ? ntohs(sp->s_port) : SSH_DEFAULT_PORT;
679
		options.port = sp ? ntohs(sp->s_port) : SSH_DEFAULT_PORT;
677
	}
680
	}
681
	*/
678
682
679
	if (options.local_command != NULL) {
683
	if (options.local_command != NULL) {
680
		char thishost[NI_MAXHOST];
684
		char thishost[NI_MAXHOST];
(-)openssh-5.4p1/sshconnect.c (-3 / +17 lines)
Lines 328-333 Link Here
328
	int on = 1;
328
	int on = 1;
329
	int sock = -1, attempt;
329
	int sock = -1, attempt;
330
	char ntop[NI_MAXHOST], strport[NI_MAXSERV];
330
	char ntop[NI_MAXHOST], strport[NI_MAXSERV];
331
	char *service = "ssh";
331
	struct addrinfo hints, *ai, *aitop;
332
	struct addrinfo hints, *ai, *aitop;
332
333
333
	debug2("ssh_connect: needpriv %d", needpriv);
334
	debug2("ssh_connect: needpriv %d", needpriv);
Lines 342-348 Link Here
342
	hints.ai_family = family;
343
	hints.ai_family = family;
343
	hints.ai_socktype = SOCK_STREAM;
344
	hints.ai_socktype = SOCK_STREAM;
344
	snprintf(strport, sizeof strport, "%u", port);
345
	snprintf(strport, sizeof strport, "%u", port);
345
	if ((gaierr = getaddrinfo(host, strport, &hints, &aitop)) != 0)
346
	if (port != 0)
347
		service = strport;
348
349
	if ((gaierr = getaddrinfo(host, service, &hints, &aitop)) != 0)
346
		fatal("%s: Could not resolve hostname %.100s: %s", __progname,
350
		fatal("%s: Could not resolve hostname %.100s: %s", __progname,
347
		    host, ssh_gai_strerror(gaierr));
351
		    host, ssh_gai_strerror(gaierr));
348
352
Lines 357-362 Link Here
357
		 * sequence until the connection succeeds.
361
		 * sequence until the connection succeeds.
358
		 */
362
		 */
359
		for (ai = aitop; ai; ai = ai->ai_next) {
363
		for (ai = aitop; ai; ai = ai->ai_next) {
364
			struct sockaddr_in *sa = (struct sockaddr_in *) ai->ai_addr;
365
			port = ntohs(sa->sin_port);
366
			snprintf(strport, sizeof strport, "%u", port);
367
360
			if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6)
368
			if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6)
361
				continue;
369
				continue;
362
			if (getnameinfo(ai->ai_addr, ai->ai_addrlen,
370
			if (getnameinfo(ai->ai_addr, ai->ai_addrlen,
Lines 386-393 Link Here
386
				sock = -1;
394
				sock = -1;
387
			}
395
			}
388
		}
396
		}
389
		if (sock != -1)
397
		/*
390
			break;	/* Successful connection. */
398
		 * Successful connection.  Save the port that we connected
399
		 * on because it may be different from this function's input.
400
		 */
401
		if (sock != -1) {
402
			options.port = port;
403
			break;
404
		}
391
	}
405
	}
392
406
393
	freeaddrinfo(aitop);
407
	freeaddrinfo(aitop);

Return to bug 1742