pull/215/head
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 const SO_ORIGINAL_DST = 80
func GetOriginalDestination(conn internet.Connection) v2net.Destination { 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() fd, err := tcpConn.SysFd()
if err != nil { if err != nil {
log.Info("Dokodemo: Failed to get original destination: ", err) log.Info("Dokodemo: Failed to get original destination: ", err)

View File

@ -31,3 +31,7 @@ type Connection interface {
net.Conn net.Conn
Reusable 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) SetReusable(b bool) {}
func (this *RawConnection) SysFd() (int, error) {
return getSysFd(&this.TCPConn)
}
type Connection struct { type Connection struct {
dest string dest string
conn net.Conn conn net.Conn
@ -102,7 +106,11 @@ func (this *Connection) Reusable() bool {
} }
func (this *Connection) SysFd() (int, error) { 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() { switch ce := cv.Elem(); ce.Kind() {
case reflect.Struct: case reflect.Struct:
netfd := ce.FieldByName("conn").FieldByName("fd") netfd := ce.FieldByName("conn").FieldByName("fd")