From f0e931d7bd8eb38da428188d43594c91b2ba234b Mon Sep 17 00:00:00 2001 From: EAimTY Date: Thu, 25 May 2023 21:51:10 +0900 Subject: [PATCH] returns error on dual-stack IPv4 socket --- tuic-client/src/socks5.rs | 8 ++++++++ tuic-server/src/server.rs | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/tuic-client/src/socks5.rs b/tuic-client/src/socks5.rs index 1d8af58..128ab78 100644 --- a/tuic-client/src/socks5.rs +++ b/tuic-client/src/socks5.rs @@ -43,6 +43,13 @@ impl Server { let socket = Socket::from(TcpListener::bind(&cfg.server).await?.into_std()?); if let Some(dual_stack) = cfg.dual_stack { + if cfg.server.is_ipv4() && dual_stack { + return Err(Error::from(IoError::new( + ErrorKind::Unsupported, + "IPv4 socket cannot be dual stack", + ))); + } + socket.set_only_v6(!dual_stack)?; } @@ -119,6 +126,7 @@ impl Server { ); if let Some(dual_stack) = SERVER.get().unwrap().dual_stack { + // We already checked that the server address is IPv6 socket.set_only_v6(!dual_stack)?; } diff --git a/tuic-server/src/server.rs b/tuic-server/src/server.rs index 8dfa5bf..5138830 100644 --- a/tuic-server/src/server.rs +++ b/tuic-server/src/server.rs @@ -98,6 +98,13 @@ impl Server { let socket = Socket::from(StdUdpSocket::bind(cfg.server)?); if let Some(dual_stack) = cfg.dual_stack { + if cfg.server.is_ipv4() && dual_stack { + return Err(Error::from(IoError::new( + ErrorKind::Unsupported, + "IPv4 socket cannot be dual stack", + ))); + } + socket.set_only_v6(!dual_stack)?; }