github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/transport/internet/tcp/sockopt_freebsd.go (about)

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