sockopt_freebsd.go 632 B

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