summaryrefslogtreecommitdiff
path: root/evutil.c
diff options
context:
space:
mode:
authorEdoardo Lolletti <edoardo762@gmail.com>2023-02-04 15:00:48 +0100
committerGitHub <noreply@github.com>2023-02-04 15:00:48 +0100
commitf9134df7d07a9214d00cb0d18d7fd820fa7eb781 (patch)
tree0839eb6cdb1d408a95a3f4bd6275afd0b8155f18 /evutil.c
parenta5b0ded3c93ca5e21fc0644e3222d9f4a177dfd3 (diff)
downloadlibevent-f9134df7d07a9214d00cb0d18d7fd820fa7eb781.tar.gz
Add LEV_OPT_BIND_IPV4_AND_IPV6 flag (#1400)
Libevent introduced the LEV_OPT_BIND_IPV6ONLY to pass to evconnlistener_new_bind to make it automatically set the underlying socket as accepting ipv6 requests. This works fine on posix compliant platforms as by the standard every new AF_INET6 socket is created as both supporting ipv6 and ipv4 connections. But on windows the default is the opposite, with the flag IPV6_V6ONLY being always enabled by default. This makes creating a listener to supports both protocols a bit more tricky as winsock doesn't allow changing this flag after evconnlistener_new_bind does all the initial setup because as stated in the docs, you can't change it after the sonnect connected, so one would have to manually create the socket beforehand and set the flag and then call evconnlistener_new with the socket itself. It would be nice to have libevent keep a consistent behaviour across the platforms in this scenario, maybe or by making it always set IPV6_V6ONLY to false unless LEV_OPT_BIND_IPV6ONLY is passed, in which case it's set to true, or add another flag to forcefully set it to false and keep the system dependent behaviour as default. So this patch add new option for libevent listeners to bind to both - LEV_OPT_BIND_IPV4_AND_IPV6
Diffstat (limited to 'evutil.c')
-rw-r--r--evutil.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/evutil.c b/evutil.c
index d46c997b..bbf908c0 100644
--- a/evutil.c
+++ b/evutil.c
@@ -604,6 +604,17 @@ evutil_make_listen_socket_ipv6only(evutil_socket_t sock)
}
int
+evutil_make_listen_socket_not_ipv6only(evutil_socket_t sock)
+{
+#if defined(IPV6_V6ONLY)
+ int zero = 0;
+ return setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&zero,
+ (ev_socklen_t)sizeof(zero));
+#endif
+ return 0;
+}
+
+int
evutil_make_tcp_listen_socket_deferred(evutil_socket_t sock)
{
#if defined(EVENT__HAVE_NETINET_TCP_H) && defined(TCP_DEFER_ACCEPT)