github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/transport/internet/udp/hub_linux.go (about) 1 // +build linux 2 3 package udp 4 5 import ( 6 "syscall" 7 8 "golang.org/x/sys/unix" 9 "v2ray.com/core/common/net" 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 }