Use IPv4 and v6 only when suitable interfaces are configured

Only on systems supporting AI_ADDRCONFIG.
This commit is contained in:
Markus Armbruster 2009-02-11 21:09:18 +01:00
parent 00b5cb2b8a
commit 7cce3124bf
2 changed files with 12 additions and 1 deletions

View file

@ -52,6 +52,11 @@
#endif #endif
#include "misc.h" #include "misc.h"
/* Portability cruft, should become unnecessary eventually */
#ifndef AI_ADDRCONFIG
#define AI_ADDRCONFIG 0
#endif
#ifdef HAVE_GETADDRINFO #ifdef HAVE_GETADDRINFO
/* /*
* Inspired by example code from W. Richard Stevens: UNIX Network * 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; struct addrinfo hints, *res, *ressave;
memset(&hints, 0, sizeof(struct addrinfo)); memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_flags = AI_ADDRCONFIG;
hints.ai_family = AF_UNSPEC; hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;

View file

@ -46,6 +46,11 @@
#include <unistd.h> #include <unistd.h>
#include "prototypes.h" #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 *); static void cant_listen(char *, char *, const char *);
int int
@ -62,7 +67,7 @@ tcp_listen(char *host, char *serv, size_t *addrlenp)
struct addrinfo hints, *res, *ressave; struct addrinfo hints, *res, *ressave;
memset(&hints, 0, sizeof(struct addrinfo)); 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_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;