aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2018-02-09 11:31:25 +0200
committerArnold D. Robbins <arnold@skeeve.com>2018-02-09 11:31:25 +0200
commitc1e55fde1a4bb72a0627ab37fe5ba1493cbf91eb (patch)
treef173ef8e9f48bba33ff4580a58b50c2704ea33de
parentc326b7dfa00760f7127912053fad544b0b79da23 (diff)
downloadegawk-c1e55fde1a4bb72a0627ab37fe5ba1493cbf91eb.tar.gz
egawk-c1e55fde1a4bb72a0627ab37fe5ba1493cbf91eb.tar.bz2
egawk-c1e55fde1a4bb72a0627ab37fe5ba1493cbf91eb.zip
Small fix in sockets if only loopback interface is up.
-rw-r--r--ChangeLog7
-rw-r--r--io.c15
2 files changed, 21 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index a5fd076d..b467eb23 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2018-02-09 Arnold D. Robbins <arnold@skeeve.com>
+
+ * io.c (socketopen): Rearrange assigning the flags to use
+ AI_ADDRCONFIG only if family is AF_UNSPEC. Thanks to
+ Houder <houder@xs4all.nl> for the report and initial
+ code suggestion.
+
2018-02-07 Andrew J. Schorr <aschorr@telemetry-investments.com>
Print +"01" should print "1", not "01".
diff --git a/io.c b/io.c
index befc20a1..f09c4a02 100644
--- a/io.c
+++ b/io.c
@@ -1579,10 +1579,23 @@ socketopen(int family, int type, const char *localpname,
int any_remote_host = (strcmp(remotehostname, "0") == 0);
memset(& lhints, '\0', sizeof (lhints));
- lhints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
+
lhints.ai_socktype = type;
lhints.ai_family = family;
+ /*
+ * If only the loopback interface is up and hints.ai_flags has
+ * AI_ADDRCONFIG, getaddrinfo() will succeed and return all wildcard
+ * addresses, but only if hints.ai_family == AF_UNSPEC
+ *
+ * Do return the wildcard address in case the loopback interface
+ * is the only one that is up (and
+ * hints.ai_family == either AF_INET4 or AF_INET6)
+ */
+ lhints.ai_flags = AI_PASSIVE;
+ if (lhints.ai_family == AF_UNSPEC)
+ lhints.ai_flags |= AI_ADDRCONFIG;
+
lerror = getaddrinfo(NULL, localpname, & lhints, & lres);
if (lerror) {
if (strcmp(localpname, "0") != 0) {