From 765c9e52c544ec4c9e9abbce7d9d0a3f6a320be9 Mon Sep 17 00:00:00 2001 From: zonyitoo Date: Sun, 16 Jun 2024 19:59:25 +0800 Subject: [PATCH] fix(shadowsocks): IpStackCapability check IPv4-mapped-IPv6 properly - ref #1543 --- crates/shadowsocks/src/net/sys/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/shadowsocks/src/net/sys/mod.rs b/crates/shadowsocks/src/net/sys/mod.rs index 8c7cf401a8fc..3bab53c8566c 100644 --- a/crates/shadowsocks/src/net/sys/mod.rs +++ b/crates/shadowsocks/src/net/sys/mod.rs @@ -152,6 +152,7 @@ static IP_STACK_CAPABILITIES: Lazy = Lazy::new(|| { // Check IPv4 if let Ok(_) = Socket::new(Domain::IPV4, Type::STREAM, Some(Protocol::TCP)) { caps.support_ipv4 = true; + debug!("IpStackCapability support_ipv4=true"); } // Check IPv6 (::1) @@ -160,6 +161,7 @@ static IP_STACK_CAPABILITIES: Lazy = Lazy::new(|| { let local_host = SockAddr::from(SocketAddr::new(Ipv6Addr::LOCALHOST.into(), 0)); if let Ok(..) = ipv6_socket.bind(&local_host) { caps.support_ipv6 = true; + debug!("IpStackCapability support_ipv6=true"); } } } @@ -167,9 +169,10 @@ static IP_STACK_CAPABILITIES: Lazy = Lazy::new(|| { // Check IPv4-mapped-IPv6 (127.0.0.1) if let Ok(ipv6_socket) = Socket::new(Domain::IPV6, Type::STREAM, Some(Protocol::TCP)) { if let Ok(..) = ipv6_socket.set_only_v6(false) { - let local_host = SockAddr::from(SocketAddr::new(Ipv4Addr::LOCALHOST.into(), 0)); + let local_host = SockAddr::from(SocketAddr::new(Ipv4Addr::LOCALHOST.to_ipv6_mapped().into(), 0)); if let Ok(..) = ipv6_socket.bind(&local_host) { caps.support_ipv4_mapped_ipv6 = true; + debug!("IpStackCapability support_ipv4_mapped_ipv6=true"); } } }