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

@ -1,5 +1,5 @@
//go:build !linux
// +build !linux
//go:build !linux && !windows
// +build !linux,!windows
package dokodemo

View file

@ -0,0 +1,27 @@
//go:build windows
// +build windows
package dokodemo
import (
"net"
"syscall"
)
func FakeUDP(addr *net.UDPAddr, mark int) (net.PacketConn, error) {
udpConn, err := net.ListenUDP("udp", addr)
if err != nil {
return udpConn, err
}
rawConn, err := udpConn.SyscallConn()
if err != nil {
return nil, err
}
err = rawConn.Control(func(fd uintptr) {
syscall.SetsockoptInt(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
})
if err != nil {
return nil, err
}
return udpConn, nil
}