|
Lines 331-345
timeout_connect(int sockfd, const struct
Link Here
|
| 331 |
* the daemon. |
331 |
* the daemon. |
| 332 |
*/ |
332 |
*/ |
| 333 |
int |
333 |
int |
| 334 |
ssh_connect(const char *host, struct sockaddr_storage * hostaddr, |
334 |
ssh_connect(char **hostp, struct sockaddr_storage *hostaddr, |
| 335 |
u_short port, int family, int connection_attempts, int *timeout_ms, |
335 |
u_short port, int family, int connection_attempts, int *timeout_ms, |
| 336 |
int want_keepalive, int needpriv, const char *proxy_command) |
336 |
int want_keepalive, int needpriv, const char *proxy_command) |
| 337 |
{ |
337 |
{ |
| 338 |
int gaierr; |
338 |
int gaierr; |
| 339 |
int on = 1; |
339 |
int on = 1; |
| 340 |
int sock = -1, attempt; |
340 |
int sock = -1, attempt, replace_host = 0; |
| 341 |
char ntop[NI_MAXHOST], strport[NI_MAXSERV]; |
341 |
char ntop[NI_MAXHOST], strport[NI_MAXSERV]; |
| 342 |
struct addrinfo hints, *ai, *aitop; |
342 |
struct addrinfo hints, *ai, *aitop; |
|
|
343 |
const char *host = *hostp; |
| 343 |
|
344 |
|
| 344 |
debug2("ssh_connect: needpriv %d", needpriv); |
345 |
debug2("ssh_connect: needpriv %d", needpriv); |
| 345 |
|
346 |
|
|
Lines 349-361
ssh_connect(const char *host, struct soc
Link Here
|
| 349 |
|
350 |
|
| 350 |
/* No proxy command. */ |
351 |
/* No proxy command. */ |
| 351 |
|
352 |
|
|
|
353 |
/* Try numeric address first */ |
| 352 |
memset(&hints, 0, sizeof(hints)); |
354 |
memset(&hints, 0, sizeof(hints)); |
| 353 |
hints.ai_family = family; |
355 |
hints.ai_family = family; |
| 354 |
hints.ai_socktype = SOCK_STREAM; |
356 |
hints.ai_socktype = SOCK_STREAM; |
|
|
357 |
hints.ai_flags = AI_NUMERICHOST|AI_NUMERICSERV; |
| 355 |
snprintf(strport, sizeof strport, "%u", port); |
358 |
snprintf(strport, sizeof strport, "%u", port); |
| 356 |
if ((gaierr = getaddrinfo(host, strport, &hints, &aitop)) != 0) |
359 |
if ((gaierr = getaddrinfo(host, strport, &hints, &aitop)) == 0) { |
| 357 |
fatal("%s: Could not resolve hostname %.100s: %s", __progname, |
360 |
/* Hostname was numeric. arrange to use it later */ |
| 358 |
host, ssh_gai_strerror(gaierr)); |
361 |
replace_host = 1; |
|
|
362 |
} else { |
| 363 |
debug3("%s: could not parse hostname %.100s as numeric: %s", |
| 364 |
__func__, host, ssh_gai_strerror(gaierr)); |
| 365 |
memset(&hints, 0, sizeof(hints)); |
| 366 |
hints.ai_family = family; |
| 367 |
hints.ai_socktype = SOCK_STREAM; |
| 368 |
snprintf(strport, sizeof strport, "%u", port); |
| 369 |
if ((gaierr = getaddrinfo(host, strport, &hints, &aitop)) != 0) |
| 370 |
fatal("%s: Could not resolve hostname %.100s: %s", |
| 371 |
__progname, host, ssh_gai_strerror(gaierr)); |
| 372 |
} |
| 359 |
|
373 |
|
| 360 |
for (attempt = 0; attempt < connection_attempts; attempt++) { |
374 |
for (attempt = 0; attempt < connection_attempts; attempt++) { |
| 361 |
if (attempt > 0) { |
375 |
if (attempt > 0) { |
|
Lines 400-406
ssh_connect(const char *host, struct soc
Link Here
|
| 400 |
if (sock != -1) |
414 |
if (sock != -1) |
| 401 |
break; /* Successful connection. */ |
415 |
break; /* Successful connection. */ |
| 402 |
} |
416 |
} |
| 403 |
|
|
|
| 404 |
freeaddrinfo(aitop); |
417 |
freeaddrinfo(aitop); |
| 405 |
|
418 |
|
| 406 |
/* Return failure if we didn't get a successful connection. */ |
419 |
/* Return failure if we didn't get a successful connection. */ |
|
Lines 410-415
ssh_connect(const char *host, struct soc
Link Here
|
| 410 |
return (-1); |
423 |
return (-1); |
| 411 |
} |
424 |
} |
| 412 |
|
425 |
|
|
|
426 |
if (replace_host) |
| 427 |
*hostp = xstrdup(ntop); |
| 428 |
|
| 413 |
debug("Connection established."); |
429 |
debug("Connection established."); |
| 414 |
|
430 |
|
| 415 |
/* Set SO_KEEPALIVE if requested. */ |
431 |
/* Set SO_KEEPALIVE if requested. */ |
|
Lines 744-750
check_host_key(char *hostname, struct so
Link Here
|
| 744 |
load_hostkeys(host_hostkeys, host, system_hostfiles[i]); |
760 |
load_hostkeys(host_hostkeys, host, system_hostfiles[i]); |
| 745 |
|
761 |
|
| 746 |
ip_hostkeys = NULL; |
762 |
ip_hostkeys = NULL; |
| 747 |
if (!want_cert && options.check_host_ip) { |
763 |
if (options.check_host_ip) { |
| 748 |
ip_hostkeys = init_hostkeys(); |
764 |
ip_hostkeys = init_hostkeys(); |
| 749 |
for (i = 0; i < num_user_hostfiles; i++) |
765 |
for (i = 0; i < num_user_hostfiles; i++) |
| 750 |
load_hostkeys(ip_hostkeys, ip, user_hostfiles[i]); |
766 |
load_hostkeys(ip_hostkeys, ip, user_hostfiles[i]); |