github.com/xraypb/xray-core@v1.6.6/transport/internet/tcp/sockopt_freebsd.go (about)

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