sockopt_freebsd.go 671 B

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