|
@@ -3,33 +3,30 @@
|
|
|
package tcp
|
|
package tcp
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
|
+ "net"
|
|
|
"syscall"
|
|
"syscall"
|
|
|
|
|
|
|
|
"v2ray.com/core/app/log"
|
|
"v2ray.com/core/app/log"
|
|
|
- "v2ray.com/core/common/net"
|
|
|
|
|
|
|
+ v2net "v2ray.com/core/common/net"
|
|
|
"v2ray.com/core/transport/internet"
|
|
"v2ray.com/core/transport/internet"
|
|
|
|
|
+ "v2ray.com/core/transport/internet/internal"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
const SO_ORIGINAL_DST = 80
|
|
const SO_ORIGINAL_DST = 80
|
|
|
|
|
|
|
|
-func GetOriginalDestination(conn internet.Connection) net.Destination {
|
|
|
|
|
- tcpConn, ok := conn.(internet.SysFd)
|
|
|
|
|
- if !ok {
|
|
|
|
|
- log.Trace(newError("failed to get sys fd"))
|
|
|
|
|
- return net.Destination{}
|
|
|
|
|
- }
|
|
|
|
|
- fd, err := tcpConn.SysFd()
|
|
|
|
|
|
|
+func GetOriginalDestination(conn internet.Connection) v2net.Destination {
|
|
|
|
|
+ fd, err := internal.GetSysFd(conn.(net.Conn))
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
log.Trace(newError("failed to get original destination").Base(err))
|
|
log.Trace(newError("failed to get original destination").Base(err))
|
|
|
- return net.Destination{}
|
|
|
|
|
|
|
+ return v2net.Destination{}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
addr, err := syscall.GetsockoptIPv6Mreq(fd, syscall.IPPROTO_IP, SO_ORIGINAL_DST)
|
|
addr, err := syscall.GetsockoptIPv6Mreq(fd, syscall.IPPROTO_IP, SO_ORIGINAL_DST)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
log.Trace(newError("failed to call getsockopt").Base(err))
|
|
log.Trace(newError("failed to call getsockopt").Base(err))
|
|
|
- return net.Destination{}
|
|
|
|
|
|
|
+ return v2net.Destination{}
|
|
|
}
|
|
}
|
|
|
- ip := net.IPAddress(addr.Multiaddr[4:8])
|
|
|
|
|
|
|
+ ip := v2net.IPAddress(addr.Multiaddr[4:8])
|
|
|
port := uint16(addr.Multiaddr[2])<<8 + uint16(addr.Multiaddr[3])
|
|
port := uint16(addr.Multiaddr[2])<<8 + uint16(addr.Multiaddr[3])
|
|
|
- return net.TCPDestination(ip, net.Port(port))
|
|
|
|
|
|
|
+ return v2net.TCPDestination(ip, v2net.Port(port))
|
|
|
}
|
|
}
|