From 7cce3124bfd4f165bc00e872ff97a3719d1659a9 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 11 Feb 2009 21:09:18 +0100 Subject: [PATCH] Use IPv4 and v6 only when suitable interfaces are configured Only on systems supporting AI_ADDRCONFIG. --- src/client/host.c | 6 ++++++ src/lib/gen/tcp_listen.c | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/client/host.c b/src/client/host.c index 68df7e21..6687f71a 100644 --- a/src/client/host.c +++ b/src/client/host.c @@ -52,6 +52,11 @@ #endif #include "misc.h" +/* Portability cruft, should become unnecessary eventually */ +#ifndef AI_ADDRCONFIG +#define AI_ADDRCONFIG 0 +#endif + #ifdef HAVE_GETADDRINFO /* * Inspired by example code from W. Richard Stevens: UNIX Network @@ -65,6 +70,7 @@ tcp_connect(char *host, char *serv) struct addrinfo hints, *res, *ressave; memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_flags = AI_ADDRCONFIG; hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; diff --git a/src/lib/gen/tcp_listen.c b/src/lib/gen/tcp_listen.c index 29c227d3..fa494c40 100644 --- a/src/lib/gen/tcp_listen.c +++ b/src/lib/gen/tcp_listen.c @@ -46,6 +46,11 @@ #include #include "prototypes.h" +/* Portability cruft, should become unnecessary eventually */ +#ifndef AI_ADDRCONFIG +#define AI_ADDRCONFIG 0 +#endif + static void cant_listen(char *, char *, const char *); int @@ -62,7 +67,7 @@ tcp_listen(char *host, char *serv, size_t *addrlenp) struct addrinfo hints, *res, *ressave; memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_flags = AI_PASSIVE; + hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG; hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM;