summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@dtucker.net>2018-02-23 15:20:42 +1100
committerDarren Tucker <dtucker@dtucker.net>2018-02-23 15:20:42 +1100
commitb59162da99399d89bd57f71c170c0003c55b1583 (patch)
treebf440d2fb9931ef3e9589125f1c1214a55b38f02
parenta8dd6fe0aa10b6866830b4688a73ef966f0aed88 (diff)
Check for ifaddrs.h for BindInterface.
BindInterface required getifaddr and friends so disable if not available (eg Solaris 10). We should be able to add support for some systems with a bit more work but this gets the building again.
-rw-r--r--configure.ac1
-rw-r--r--sshconnect.c14
2 files changed, 14 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index cbcf9d077..e81e3eccd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -365,6 +365,7 @@ AC_CHECK_HEADERS([ \
365 glob.h \ 365 glob.h \
366 ia.h \ 366 ia.h \
367 iaf.h \ 367 iaf.h \
368 ifaddrs.h \
368 inttypes.h \ 369 inttypes.h \
369 langinfo.h \ 370 langinfo.h \
370 limits.h \ 371 limits.h \
diff --git a/sshconnect.c b/sshconnect.c
index d9618bcf7..442424b40 100644
--- a/sshconnect.c
+++ b/sshconnect.c
@@ -44,7 +44,9 @@
44#include <stdlib.h> 44#include <stdlib.h>
45#include <string.h> 45#include <string.h>
46#include <unistd.h> 46#include <unistd.h>
47#include <ifaddrs.h> 47#ifdef HAVE_IFADDRS_H
48# include <ifaddrs.h>
49#endif
48 50
49#include "xmalloc.h" 51#include "xmalloc.h"
50#include "key.h" 52#include "key.h"
@@ -272,6 +274,7 @@ ssh_kill_proxy_command(void)
272 kill(proxy_command_pid, SIGHUP); 274 kill(proxy_command_pid, SIGHUP);
273} 275}
274 276
277#ifdef HAVE_IFADDRS_H
275/* 278/*
276 * Search a interface address list (returned from getifaddrs(3)) for an 279 * Search a interface address list (returned from getifaddrs(3)) for an
277 * address that matches the desired address family on the specifed interface. 280 * address that matches the desired address family on the specifed interface.
@@ -332,6 +335,7 @@ check_ifaddrs(const char *ifname, int af, const struct ifaddrs *ifaddrs,
332 } 335 }
333 return -1; 336 return -1;
334} 337}
338#endif
335 339
336/* 340/*
337 * Creates a (possibly privileged) socket for use as the ssh connection. 341 * Creates a (possibly privileged) socket for use as the ssh connection.
@@ -343,7 +347,9 @@ ssh_create_socket(int privileged, struct addrinfo *ai)
343 struct sockaddr_storage bindaddr; 347 struct sockaddr_storage bindaddr;
344 socklen_t bindaddrlen = 0; 348 socklen_t bindaddrlen = 0;
345 struct addrinfo hints, *res = NULL; 349 struct addrinfo hints, *res = NULL;
350#ifdef HAVE_IFADDRS_H
346 struct ifaddrs *ifaddrs = NULL; 351 struct ifaddrs *ifaddrs = NULL;
352#endif
347 char ntop[NI_MAXHOST]; 353 char ntop[NI_MAXHOST];
348 354
349 sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); 355 sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
@@ -380,6 +386,7 @@ ssh_create_socket(int privileged, struct addrinfo *ai)
380 memcpy(&bindaddr, res->ai_addr, res->ai_addrlen); 386 memcpy(&bindaddr, res->ai_addr, res->ai_addrlen);
381 bindaddrlen = res->ai_addrlen; 387 bindaddrlen = res->ai_addrlen;
382 } else if (options.bind_interface != NULL) { 388 } else if (options.bind_interface != NULL) {
389#ifdef HAVE_IFADDRS_H
383 if ((r = getifaddrs(&ifaddrs)) != 0) { 390 if ((r = getifaddrs(&ifaddrs)) != 0) {
384 error("getifaddrs: %s: %s", options.bind_interface, 391 error("getifaddrs: %s: %s", options.bind_interface,
385 strerror(errno)); 392 strerror(errno));
@@ -392,6 +399,9 @@ ssh_create_socket(int privileged, struct addrinfo *ai)
392 options.bind_interface); 399 options.bind_interface);
393 goto fail; 400 goto fail;
394 } 401 }
402#else
403 error("BindInterface not supported on this platform.");
404#endif
395 } 405 }
396 if ((r = getnameinfo((struct sockaddr *)&bindaddr, bindaddrlen, 406 if ((r = getnameinfo((struct sockaddr *)&bindaddr, bindaddrlen,
397 ntop, sizeof(ntop), NULL, 0, NI_NUMERICHOST)) != 0) { 407 ntop, sizeof(ntop), NULL, 0, NI_NUMERICHOST)) != 0) {
@@ -427,8 +437,10 @@ fail:
427 out: 437 out:
428 if (res != NULL) 438 if (res != NULL)
429 freeaddrinfo(res); 439 freeaddrinfo(res);
440#ifdef HAVE_IFADDRS_H
430 if (ifaddrs != NULL) 441 if (ifaddrs != NULL)
431 freeifaddrs(ifaddrs); 442 freeifaddrs(ifaddrs);
443#endif
432 return sock; 444 return sock;
433} 445}
434 446