mirror of https://github.com/v2ray/v2ray-core
fix #185
parent
98cc28a4c4
commit
f050113925
|
@ -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)
|
||||||
|
|
|
@ -31,3 +31,7 @@ type Connection interface {
|
||||||
net.Conn
|
net.Conn
|
||||||
Reusable
|
Reusable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SysFd interface {
|
||||||
|
SysFd() (int, error)
|
||||||
|
}
|
||||||
|
|
|
@ -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")
|
||||||
|
|
Loading…
Reference in New Issue