diff --git a/aggligator-util/src/bin/agg-tunnel.rs b/aggligator-util/src/bin/agg-tunnel.rs index 5fdc93e..33647fa 100644 --- a/aggligator-util/src/bin/agg-tunnel.rs +++ b/aggligator-util/src/bin/agg-tunnel.rs @@ -16,7 +16,7 @@ use std::{ }; use tokio::{ io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}, - net::{TcpListener, TcpStream}, + net::{TcpListener, TcpSocket, TcpStream}, select, sync::{broadcast, mpsc, oneshot, watch}, task::block_in_place, @@ -259,11 +259,12 @@ impl ClientCli { let mut port_tasks = Vec::new(); for (server_port, client_port) in ports { let listeners = if self.global { - let listener = TcpListener::bind(SocketAddr::new(Ipv6Addr::UNSPECIFIED.into(), client_port)) - .await + let socket = TcpSocket::new_v6()?; + let _ = SockRef::from(&socket).set_only_v6(false); + socket + .bind(SocketAddr::new(Ipv6Addr::UNSPECIFIED.into(), client_port)) .context(format!("cannot bind to local port {client_port}"))?; - let _ = SockRef::from(&listener).set_only_v6(false); - vec![listener] + vec![socket.listen(16)?] } else { let listener_v4 = TcpListener::bind(SocketAddr::new(Ipv4Addr::LOCALHOST.into(), client_port)) .await diff --git a/aggligator-util/src/transport/tcp.rs b/aggligator-util/src/transport/tcp.rs index bd8b3f2..34d0d7c 100644 --- a/aggligator-util/src/transport/tcp.rs +++ b/aggligator-util/src/transport/tcp.rs @@ -349,11 +349,16 @@ impl TcpAcceptor { let mut listeners = Vec::new(); for addr in addrs { - let listener = TcpListener::bind(addr).await?; - if addr.is_ipv6() { - let _ = SockRef::from(&listener).set_only_v6(false); - } - listeners.push(listener); + let socket = match addr { + SocketAddr::V4(_) => TcpSocket::new_v4()?, + SocketAddr::V6(_) => { + let socket = TcpSocket::new_v6()?; + let _ = SockRef::from(&socket).set_only_v6(false); + socket + } + }; + socket.bind(addr)?; + listeners.push(socket.listen(16)?); } Self::from_listeners(listeners)