v2ray 9 роки тому
батько
коміт
f050113925

+ 5 - 1
proxy/dokodemo/sockopt_linux.go

@@ -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)

+ 4 - 0
transport/internet/connection.go

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

+ 9 - 1
transport/internet/tcp/connection.go

@@ -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")