Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d0350f8

Browse files
xqzrRPRX
andauthoredMar 31, 2025··
Sockopt: Allow v6only work for Windows & Drawin (#4571)
Completes #1677 --------- Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com>
1 parent 63eb053 commit d0350f8

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed
 

‎transport/internet/sockopt_darwin.go

+6
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
200200
}
201201
}
202202

203+
if config.V6Only {
204+
if err := unix.SetsockoptInt(int(fd), unix.IPPROTO_IPV6, unix.IPV6_V6ONLY, 1); err != nil {
205+
return errors.New("failed to set IPV6_V6ONLY").Base(err)
206+
}
207+
}
208+
203209
return nil
204210
}
205211

‎transport/internet/sockopt_windows.go

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const (
1515
IPV6_UNICAST_IF = 31
1616
IP_MULTICAST_IF = 9
1717
IPV6_MULTICAST_IF = 9
18+
IPV6_V6ONLY = 27
1819
)
1920

2021
func setTFO(fd syscall.Handle, tfo int) error {
@@ -90,6 +91,12 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
9091
}
9192
}
9293

94+
if config.V6Only {
95+
if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_IPV6, IPV6_V6ONLY, 1); err != nil {
96+
return errors.New("failed to set IPV6_V6ONLY").Base(err)
97+
}
98+
}
99+
93100
return nil
94101
}
95102

0 commit comments

Comments
 (0)
Please sign in to comment.