From 8fa6bd1743604d16c0bedb87adeda621acf8c1d8 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Sun, 11 Dec 2022 23:53:39 +0800 Subject: [PATCH] fix: fix wireguard outbound not work with the sniffer --- adapter/outbound/wireguard.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/adapter/outbound/wireguard.go b/adapter/outbound/wireguard.go index eb35ba03..002b65aa 100644 --- a/adapter/outbound/wireguard.go +++ b/adapter/outbound/wireguard.go @@ -212,7 +212,8 @@ func (w *WireGuard) DialContext(ctx context.Context, metadata *C.Metadata, opts } conn, err = N.DialSerial(ctx, w.tunDevice, "tcp", M.ParseSocksaddr(metadata.RemoteAddress()), addrs) } else { - conn, err = w.tunDevice.DialContext(ctx, "tcp", M.ParseSocksaddr(metadata.Pure().RemoteAddress())) + port, _ := strconv.Atoi(metadata.DstPort) + conn, err = w.tunDevice.DialContext(ctx, "tcp", M.SocksaddrFrom(metadata.DstIP, uint16(port))) } if err != nil { return nil, err @@ -242,7 +243,8 @@ func (w *WireGuard) ListenPacketContext(ctx context.Context, metadata *C.Metadat } metadata.DstIP = ip } - pc, err = w.tunDevice.ListenPacket(ctx, M.ParseSocksaddr(metadata.Pure().RemoteAddress())) + port, _ := strconv.Atoi(metadata.DstPort) + pc, err = w.tunDevice.ListenPacket(ctx, M.SocksaddrFrom(metadata.DstIP, uint16(port))) if err != nil { return nil, err }