github.com/v2fly/v2ray-core/v4@v4.45.2/transport/internet/tcp/sockopt_freebsd.go (about) 1 //go:build freebsd && !confonly 2 // +build freebsd,!confonly 3 4 package tcp 5 6 import ( 7 "github.com/v2fly/v2ray-core/v4/common/net" 8 "github.com/v2fly/v2ray-core/v4/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 }