1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-23 02:26:49 -05:00
v2fly/proxy/dokodemo/sockopt_linux.go

36 lines
883 B
Go
Raw Normal View History

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