2016-06-11 23:35:40 +00:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package dokodemo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"github.com/v2ray/v2ray-core/common/log"
|
|
|
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
2016-06-14 20:54:08 +00:00
|
|
|
"github.com/v2ray/v2ray-core/transport/internet"
|
2016-06-11 23:35:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const SO_ORIGINAL_DST = 80
|
|
|
|
|
2016-06-14 20:54:08 +00:00
|
|
|
func GetOriginalDestination(conn internet.Connection) v2net.Destination {
|
2016-06-29 22:08:20 +00:00
|
|
|
tcpConn, ok := conn.(internet.SysFd)
|
|
|
|
if !ok {
|
|
|
|
log.Info("Dokodemo: Failed to get sys fd.")
|
|
|
|
return nil
|
|
|
|
}
|
2016-06-14 20:54:08 +00:00
|
|
|
fd, err := tcpConn.SysFd()
|
2016-06-11 23:35:40 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Info("Dokodemo: Failed to get original destination: ", err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
addr, err := syscall.GetsockoptIPv6Mreq(fd, syscall.IPPROTO_IP, SO_ORIGINAL_DST)
|
|
|
|
if err != nil {
|
|
|
|
log.Info("Dokodemo: Failed to call getsockopt: ", err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
ip := v2net.IPAddress(addr.Multiaddr[4:8])
|
|
|
|
port := uint16(addr.Multiaddr[2])<<8 + uint16(addr.Multiaddr[3])
|
|
|
|
return v2net.TCPDestination(ip, v2net.Port(port))
|
|
|
|
}
|