From 0acf4844c46e63b83eab3e58069fe8c060509974 Mon Sep 17 00:00:00 2001 From: levi Date: Fri, 14 Jul 2023 10:52:26 +0800 Subject: [PATCH] Fix issue 189 --- tuic-client/src/socks5/udp_session.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tuic-client/src/socks5/udp_session.rs b/tuic-client/src/socks5/udp_session.rs index 7033352..da4530d 100644 --- a/tuic-client/src/socks5/udp_session.rs +++ b/tuic-client/src/socks5/udp_session.rs @@ -100,6 +100,26 @@ impl UdpSession { let (pkt, frag, dst_addr, src_addr) = self.socket.recv_from().await?; if let Ok(connected_addr) = self.socket.peer_addr() { + let connected_addr = match connected_addr { + SocketAddr::V4(addr) => { + if let SocketAddr::V6(_) = src_addr { + SocketAddr::new(addr.ip().to_ipv6_mapped().into(), addr.port()) + } else { + connected_addr + } + } + SocketAddr::V6(addr) => { + if let SocketAddr::V4(_) = src_addr { + if let Some(ip) = addr.ip().to_ipv4_mapped() { + SocketAddr::new(IpAddr::V4(ip), addr.port()) + } else { + connected_addr + } + } else { + connected_addr + } + } + }; if src_addr != connected_addr { Err(IoError::new( ErrorKind::Other,