From ce9cfce8fca83255704d8c4c382667b24d3e0afe Mon Sep 17 00:00:00 2001 From: Tilo Spannagel Date: Mon, 20 Dec 2021 17:37:57 +0000 Subject: [PATCH] Fix ipv6 endpoints --- src/wg.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/wg.rs b/src/wg.rs index 2dc20d3..305232f 100644 --- a/src/wg.rs +++ b/src/wg.rs @@ -37,10 +37,13 @@ impl WireGuardTunnel { pub async fn new(config: &Config) -> anyhow::Result { let source_peer_ip = config.source_peer_ip; let peer = Self::create_tunnel(config)?; - let udp = UdpSocket::bind("0.0.0.0:0") - .await - .with_context(|| "Failed to create UDP socket for WireGuard connection")?; let endpoint = config.endpoint_addr; + let udp = UdpSocket::bind(match endpoint { + SocketAddr::V4(_) => "0.0.0.0:0", + SocketAddr::V6(_) => "[::]:0", + }) + .await + .with_context(|| "Failed to create UDP socket for WireGuard connection")?; let virtual_port_ip_tx = Default::default(); Ok(Self {