Try Fix sockopt Interface miss multicast on Windows

This commit is contained in:
xqzr 2025-03-29 20:29:39 +08:00 committed by GitHub
parent 29e37e8a82
commit 390a48357c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,6 +13,8 @@ const (
TCP_FASTOPEN = 15
IP_UNICAST_IF = 31
IPV6_UNICAST_IF = 31
IPV6_MULTICAST_IF = 9
IP_MULTICAST_IF = 9
)
func setTFO(fd syscall.Handle, tfo int) error {
@ -41,10 +43,16 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf
if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_IP, IP_UNICAST_IF, int(idx)); err != nil {
return errors.New("failed to set IP_UNICAST_IF").Base(err)
}
if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_IP, IP_MULTICAST_IF, int(idx)); err != nil {
return errors.New("failed to set IP_MULTICAST_IF").Base(err)
}
} else {
if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_IPV6, IPV6_UNICAST_IF, inf.Index); err != nil {
return errors.New("failed to set IPV6_UNICAST_IF").Base(err)
}
if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_IPV6, IPV6_MULTICAST_IF, inf.Index); err != nil {
return errors.New("failed to set IPV6_MULTICAST_IF").Base(err)
}
}
}