aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2020-10-28 23:47:35 +0100
committerPřemysl Eric Janouch <p@janouch.name>2020-10-29 00:39:57 +0100
commit06d3b3bd2b8144411538ed722b1a9b679baa848f (patch)
tree6674ac3295f2c7e0630a0f226e7f0a7b4931cf36
parent132e4a38b8cb234f4992fe3078ad056c5f523d3e (diff)
downloadxK-06d3b3bd2b8144411538ed722b1a9b679baa848f.tar.gz
xK-06d3b3bd2b8144411538ed722b1a9b679baa848f.tar.xz
xK-06d3b3bd2b8144411538ed722b1a9b679baa848f.zip
kike: ensure NULL binds to both IPv4 and IPv6
-rw-r--r--kike.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/kike.c b/kike.c
index 9ec2e63..68e71c0 100644
--- a/kike.c
+++ b/kike.c
@@ -1,7 +1,7 @@
/*
* kike.c: the experimental IRC daemon
*
- * Copyright (c) 2014 - 2018, Přemysl Eric Janouch <p@janouch.name>
+ * Copyright (c) 2014 - 2020, Přemysl Eric Janouch <p@janouch.name>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
@@ -3801,6 +3801,14 @@ irc_listen (struct addrinfo *gai_iter)
soft_assert (setsockopt (fd, SOL_SOCKET, SO_REUSEADDR,
&yes, sizeof yes) != -1);
+#if defined SOL_IPV6 && defined IPV6_V6ONLY
+ // Make NULL always bind to both IPv4 and IPv6, irrespectively of the order
+ // of results; only INADDR6_ANY seems to be affected by this
+ if (gai_iter->ai_family == AF_INET6)
+ soft_assert (setsockopt (fd, SOL_IPV6, IPV6_V6ONLY,
+ &yes, sizeof yes) != -1);
+#endif
+
char host[NI_MAXHOST], port[NI_MAXSERV];
host[0] = port[0] = '\0';
int err = getnameinfo (gai_iter->ai_addr, gai_iter->ai_addrlen,
@@ -3855,7 +3863,6 @@ irc_listen_resolve (struct server_context *ctx,
ctx->listen_fds[ctx->n_listen_fds++] = fd;
poller_fd_set (event, POLLIN);
- break;
}
freeaddrinfo (gai_result);
}