From 5842bbc9f7f5f60f78d14a22ed4e99f405b0e2b4 Mon Sep 17 00:00:00 2001 From: xqzr <34030394+xqzr@users.noreply.github.com> Date: Mon, 31 Mar 2025 05:43:22 +0800 Subject: [PATCH] Sockopt: Add Windows `V6Only` #1677 --- transport/internet/sockopt_windows.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/transport/internet/sockopt_windows.go b/transport/internet/sockopt_windows.go index e1c1d25e..aa9f933b 100644 --- a/transport/internet/sockopt_windows.go +++ b/transport/internet/sockopt_windows.go @@ -15,6 +15,7 @@ const ( IPV6_UNICAST_IF = 31 IP_MULTICAST_IF = 9 IPV6_MULTICAST_IF = 9 + IPV6_V6ONLY = 27 ) func setTFO(fd syscall.Handle, tfo int) error { @@ -89,6 +90,11 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig) } } } + if config.V6Only { + if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_IPV6, IPV6_V6ONLY, 1); err != nil { + return errors.New("failed to set IPV6_V6ONLY").Base(err) + } + } return nil }