github.com/EagleQL/Xray-core@v1.4.3/transport/internet/udp/hub_linux.go (about) 1 // +build linux 2 3 package udp 4 5 import ( 6 "syscall" 7 8 "github.com/xtls/xray-core/common/net" 9 "golang.org/x/sys/unix" 10 ) 11 12 func RetrieveOriginalDest(oob []byte) net.Destination { 13 msgs, err := syscall.ParseSocketControlMessage(oob) 14 if err != nil { 15 return net.Destination{} 16 } 17 for _, msg := range msgs { 18 if msg.Header.Level == syscall.SOL_IP && msg.Header.Type == syscall.IP_RECVORIGDSTADDR { 19 ip := net.IPAddress(msg.Data[4:8]) 20 port := net.PortFromBytes(msg.Data[2:4]) 21 return net.UDPDestination(ip, port) 22 } else if msg.Header.Level == syscall.SOL_IPV6 && msg.Header.Type == unix.IPV6_RECVORIGDSTADDR { 23 ip := net.IPAddress(msg.Data[8:24]) 24 port := net.PortFromBytes(msg.Data[2:4]) 25 return net.UDPDestination(ip, port) 26 } 27 } 28 return net.Destination{} 29 } 30 31 func ReadUDPMsg(conn *net.UDPConn, payload []byte, oob []byte) (int, int, int, *net.UDPAddr, error) { 32 return conn.ReadMsgUDP(payload, oob) 33 }