mirror of
https://github.com/aramperes/onetun.git
synced 2025-09-09 17:38:32 -04:00
Add host address binding option
This commit is contained in:
parent
73671a4d07
commit
5e94a0f31e
2 changed files with 22 additions and 5 deletions
14
src/wg.rs
14
src/wg.rs
|
@ -36,11 +36,15 @@ impl WireGuardTunnel {
|
|||
let source_peer_ip = config.source_peer_ip;
|
||||
let peer = Self::create_tunnel(config)?;
|
||||
let endpoint = config.endpoint_addr;
|
||||
let udp = UdpSocket::bind(match endpoint {
|
||||
SocketAddr::V4(_) => "0.0.0.0:0",
|
||||
SocketAddr::V6(_) => "[::]:0",
|
||||
})
|
||||
.await
|
||||
let udp = if let Some(host) = config.host_addr {
|
||||
UdpSocket::bind(host).await
|
||||
} else {
|
||||
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")?;
|
||||
|
||||
Ok(Self {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue