mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-05-18 01:58:41 +00:00
fix udp original destination on windows
This commit is contained in:
parent
e9b3c53a0d
commit
d5c53b1ddd
5 changed files with 95 additions and 4 deletions
27
proxy/dokodemo/fakeudp_windows.go
Normal file
27
proxy/dokodemo/fakeudp_windows.go
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue