sockopt_freebsd.go 651 B

123456789101112131415161718192021222324
  1. //go:build freebsd
  2. // +build freebsd
  3. package tcp
  4. import (
  5. "github.com/v2fly/v2ray-core/v5/common/net"
  6. "github.com/v2fly/v2ray-core/v5/transport/internet"
  7. )
  8. // GetOriginalDestination from tcp conn
  9. func GetOriginalDestination(conn internet.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. }