mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 09:36:34 -05:00
fix #185
This commit is contained in:
parent
98cc28a4c4
commit
f050113925
@ -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)
|
||||
|
@ -31,3 +31,7 @@ type Connection interface {
|
||||
net.Conn
|
||||
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) 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")
|
||||
|
Loading…
Reference in New Issue
Block a user