2022-08-22 03:01:29 +00:00
|
|
|
//go:build darwin
|
|
|
|
// +build darwin
|
|
|
|
|
|
|
|
package tcp
|
|
|
|
|
|
|
|
import (
|
2024-06-29 18:32:57 +00:00
|
|
|
"github.com/xtls/xray-core/common/errors"
|
2022-08-22 03:01:29 +00:00
|
|
|
"github.com/xtls/xray-core/common/net"
|
|
|
|
"github.com/xtls/xray-core/transport/internet"
|
|
|
|
"github.com/xtls/xray-core/transport/internet/stat"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetOriginalDestination from tcp conn
|
|
|
|
func GetOriginalDestination(conn stat.Connection) (net.Destination, error) {
|
|
|
|
la := conn.LocalAddr()
|
|
|
|
ra := conn.RemoteAddr()
|
|
|
|
ip, port, err := internet.OriginalDst(la, ra)
|
|
|
|
if err != nil {
|
2024-06-29 18:32:57 +00:00
|
|
|
return net.Destination{}, errors.New("failed to get destination").Base(err)
|
2022-08-22 03:01:29 +00:00
|
|
|
}
|
|
|
|
dest := net.TCPDestination(net.IPAddress(ip), net.Port(port))
|
|
|
|
if !dest.IsValid() {
|
2024-06-29 18:32:57 +00:00
|
|
|
return net.Destination{}, errors.New("failed to parse destination.")
|
2022-08-22 03:01:29 +00:00
|
|
|
}
|
|
|
|
return dest, nil
|
|
|
|
}
|