sockopt_freebsd.go 737 B

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