diff --git a/transport/internet/sockopt_darwin.go b/transport/internet/sockopt_darwin.go index 86af492a..f684de98 100644 --- a/transport/internet/sockopt_darwin.go +++ b/transport/internet/sockopt_darwin.go @@ -200,6 +200,12 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig) } } + if config.V6Only { + if err := unix.SetsockoptInt(int(fd), unix.IPPROTO_IPV6, unix.IPV6_V6ONLY, 1); err != nil { + return errors.New("failed to set IPV6_V6ONLY").Base(err) + } + } + return nil } diff --git a/transport/internet/sockopt_windows.go b/transport/internet/sockopt_windows.go index e1c1d25e..cbd3b41e 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 { @@ -90,6 +91,12 @@ 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 }