fix: 调整获取远程目的的位置

This commit is contained in:
Skyxim 2022-05-28 20:00:02 +08:00
parent d0268bb9a2
commit 067c02aba1
2 changed files with 8 additions and 11 deletions

View file

@ -148,16 +148,7 @@ func (c *conn) AppendToChains(a C.ProxyAdapter) {
} }
func NewConn(c net.Conn, a C.ProxyAdapter) C.Conn { func NewConn(c net.Conn, a C.ProxyAdapter) C.Conn {
var remoteDestination string return &conn{c, []string{a.Name()}, parseRemoteDestination(a.Addr())}
if c != nil {
if tcpAddr, ok := c.RemoteAddr().(*net.TCPAddr); ok {
remoteDestination = tcpAddr.IP.String()
} else {
remoteDestination = parseRemoteDestination(a.Addr())
}
}
return &conn{c, []string{a.Name()}, remoteDestination}
} }
type packetConn struct { type packetConn struct {

View file

@ -59,7 +59,13 @@ func (tt *tcpTracker) Close() error {
func NewTCPTracker(conn C.Conn, manager *Manager, metadata *C.Metadata, rule C.Rule) *tcpTracker { func NewTCPTracker(conn C.Conn, manager *Manager, metadata *C.Metadata, rule C.Rule) *tcpTracker {
uuid, _ := uuid.NewV4() uuid, _ := uuid.NewV4()
if conn != nil {
if tcpAddr, ok := conn.RemoteAddr().(*net.TCPAddr); ok {
metadata.RemoteDst = tcpAddr.IP.String()
} else {
metadata.RemoteDst = conn.RemoteDestination() metadata.RemoteDst = conn.RemoteDestination()
}
}
t := &tcpTracker{ t := &tcpTracker{
Conn: conn, Conn: conn,