fix udp original destination on windows

This commit is contained in:
Deghy 2025-05-09 18:29:30 +03:30
parent e9b3c53a0d
commit d5c53b1ddd
5 changed files with 95 additions and 4 deletions

View file

@ -11,6 +11,7 @@ import (
"unsafe"
"github.com/xtls/xray-core/common/errors"
"golang.org/x/sys/windows"
)
const (
@ -142,6 +143,15 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
}
}
if config.ReceiveOriginalDestAddress && isUDPSocket(network) {
if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_IP, windows.IP_PKTINFO, 1); err != nil {
return errors.New("failed to set IP_PKTINFO").Base(err)
}
if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_IPV6, windows.IPV6_PKTINFO, 1); err != nil {
return errors.New("failed to set IPV6_PKTINFO").Base(err)
}
}
if len(config.CustomSockopt) > 0 {
for _, custom := range config.CustomSockopt {
if custom.System != "" && custom.System != runtime.GOOS {