sockopt_freebsd.go 580 B

1234567891011121314151617181920212223
  1. // +build freebsd
  2. // +build !confonly
  3. package tcp
  4. import (
  5. "v2ray.com/core/common/net"
  6. "v2ray.com/core/transport/internet"
  7. )
  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. }