|
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); |