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