sockopt_freebsd.go 690 B

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