From 06d3b3bd2b8144411538ed722b1a9b679baa848f Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Wed, 28 Oct 2020 23:47:35 +0100 Subject: kike: ensure NULL binds to both IPv4 and IPv6 --- kike.c | 11 +++++++++-- 1 file 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 + * Copyright (c) 2014 - 2020, Přemysl Eric Janouch * * 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); } -- cgit v1.2.3-70-g09d2