|
Lines 342-347
ssh_create_socket(struct addrinfo *ai)
Link Here
|
| 342 |
struct addrinfo hints, *res = NULL; |
342 |
struct addrinfo hints, *res = NULL; |
| 343 |
struct ifaddrs *ifaddrs = NULL; |
343 |
struct ifaddrs *ifaddrs = NULL; |
| 344 |
char ntop[NI_MAXHOST]; |
344 |
char ntop[NI_MAXHOST]; |
|
|
345 |
char *cp = NULL, *addrport = NULL, *addr = NULL, *port = NULL; |
| 345 |
|
346 |
|
| 346 |
sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); |
347 |
sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); |
| 347 |
if (sock == -1) { |
348 |
if (sock == -1) { |
|
Lines 359-372
ssh_create_socket(struct addrinfo *ai)
Link Here
|
| 359 |
return sock; |
360 |
return sock; |
| 360 |
|
361 |
|
| 361 |
if (options.bind_address != NULL) { |
362 |
if (options.bind_address != NULL) { |
|
|
363 |
cp = addrport = xstrdup(options.bind_address); |
| 364 |
addr = hpdelim(&addrport); |
| 365 |
if (*addr == '\0') /* no address, port only */ |
| 366 |
addr = NULL; |
| 367 |
if (addrport != NULL) /* optional port */ |
| 368 |
port = hpdelim(&addrport); |
| 369 |
if (addrport != NULL) { |
| 370 |
error("Invalid BindAddress specification '%s'", |
| 371 |
options.bind_address); |
| 372 |
goto fail; |
| 373 |
} |
| 362 |
memset(&hints, 0, sizeof(hints)); |
374 |
memset(&hints, 0, sizeof(hints)); |
| 363 |
hints.ai_family = ai->ai_family; |
375 |
hints.ai_family = ai->ai_family; |
| 364 |
hints.ai_socktype = ai->ai_socktype; |
376 |
hints.ai_socktype = ai->ai_socktype; |
| 365 |
hints.ai_protocol = ai->ai_protocol; |
377 |
hints.ai_protocol = ai->ai_protocol; |
| 366 |
hints.ai_flags = AI_PASSIVE; |
378 |
hints.ai_flags = AI_PASSIVE; |
| 367 |
if ((r = getaddrinfo(options.bind_address, NULL, |
379 |
if ((r = getaddrinfo(addr, port, &hints, &res)) != 0) { |
| 368 |
&hints, &res)) != 0) { |
380 |
error("getaddrinfo: %s port %s: %s", addr, port, |
| 369 |
error("getaddrinfo: %s: %s", options.bind_address, |
|
|
| 370 |
ssh_gai_strerror(r)); |
381 |
ssh_gai_strerror(r)); |
| 371 |
goto fail; |
382 |
goto fail; |
| 372 |
} |
383 |
} |
|
Lines 410-415
fail:
Link Here
|
| 410 |
freeaddrinfo(res); |
421 |
freeaddrinfo(res); |
| 411 |
if (ifaddrs != NULL) |
422 |
if (ifaddrs != NULL) |
| 412 |
freeifaddrs(ifaddrs); |
423 |
freeifaddrs(ifaddrs); |
|
|
424 |
free(cp); |
| 413 |
return sock; |
425 |
return sock; |
| 414 |
} |
426 |
} |
| 415 |
|
427 |
|