1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -05:00
This commit is contained in:
v2ray 2016-06-30 00:08:20 +02:00
parent 98cc28a4c4
commit f050113925
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
3 changed files with 18 additions and 2 deletions

View File

@ -14,7 +14,11 @@ import (
const SO_ORIGINAL_DST = 80
func GetOriginalDestination(conn internet.Connection) v2net.Destination {
tcpConn := conn.(*tcp.Connection)
tcpConn, ok := conn.(internet.SysFd)
if !ok {
log.Info("Dokodemo: Failed to get sys fd.")
return nil
}
fd, err := tcpConn.SysFd()
if err != nil {
log.Info("Dokodemo: Failed to get original destination: ", err)

View File

@ -31,3 +31,7 @@ type Connection interface {
net.Conn
Reusable
}
type SysFd interface {
SysFd() (int, error)
}

View File

@ -26,6 +26,10 @@ func (this *RawConnection) Reusable() bool {
func (this *RawConnection) SetReusable(b bool) {}
func (this *RawConnection) SysFd() (int, error) {
return getSysFd(&this.TCPConn)
}
type Connection struct {
dest string
conn net.Conn
@ -102,7 +106,11 @@ func (this *Connection) Reusable() bool {
}
func (this *Connection) SysFd() (int, error) {
cv := reflect.ValueOf(this.conn)
return getSysFd(this.conn)
}
func getSysFd(conn net.Conn) (int, error) {
cv := reflect.ValueOf(conn)
switch ce := cv.Elem(); ce.Kind() {
case reflect.Struct:
netfd := ce.FieldByName("conn").FieldByName("fd")