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