github.com/EagleQL/Xray-core@v1.4.3/transport/internet/tcp/sockopt_freebsd.go (about) 1 // +build freebsd 2 3 package tcp 4 5 import ( 6 "github.com/xtls/xray-core/common/net" 7 "github.com/xtls/xray-core/transport/internet" 8 ) 9 10 // GetOriginalDestination from tcp conn 11 func GetOriginalDestination(conn internet.Connection) (net.Destination, error) { 12 la := conn.LocalAddr() 13 ra := conn.RemoteAddr() 14 ip, port, err := internet.OriginalDst(la, ra) 15 if err != nil { 16 return net.Destination{}, newError("failed to get destination").Base(err) 17 } 18 dest := net.TCPDestination(net.IPAddress(ip), net.Port(port)) 19 if !dest.IsValid() { 20 return net.Destination{}, newError("failed to parse destination.") 21 } 22 return dest, nil 23 }