github.com/xmplusdev/xmcore@v1.8.11-0.20240412132628-5518b55526af/transport/internet/tcp/sockopt_darwin.go (about) 1 //go:build darwin 2 // +build darwin 3 4 package tcp 5 6 import ( 7 "github.com/xmplusdev/xmcore/common/net" 8 "github.com/xmplusdev/xmcore/transport/internet" 9 "github.com/xmplusdev/xmcore/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 }