From ac42487c0657537c9da42bc318901cb3e80ea701 Mon Sep 17 00:00:00 2001 From: Sebastian Urban Date: Mon, 5 Feb 2024 19:20:59 +0100 Subject: [PATCH] Fix build on non-Linux. --- aggligator-util/src/transport/tcp.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/aggligator-util/src/transport/tcp.rs b/aggligator-util/src/transport/tcp.rs index fd84906..bee6713 100644 --- a/aggligator-util/src/transport/tcp.rs +++ b/aggligator-util/src/transport/tcp.rs @@ -482,20 +482,21 @@ pub(crate) fn bind_socket_to_interface(socket: &TcpSocket, interface: &[u8], rem { for ifn in local_interfaces()? { if ifn.name.as_bytes() == interface { - let Some(addr) = ifn.addr else { continue }; - match (addr.ip(), remote) { - (IpAddr::V4(_), IpAddr::V4(_)) => (), - (IpAddr::V6(_), IpAddr::V6(_)) => (), - _ => continue, + for addr in ifn.addr { + match (addr.ip(), remote) { + (IpAddr::V4(_), IpAddr::V4(_)) => (), + (IpAddr::V6(_), IpAddr::V6(_)) => (), + _ => continue, + } + + if addr.ip().is_loopback() != remote.is_loopback() { + continue; + } + + tracing::debug!("binding to {addr:?} on interface {}", &ifn.name); + socket.bind(SocketAddr::new(addr.ip(), 0))?; + return Ok(()); } - - if addr.ip().is_loopback() != remote.is_loopback() { - continue; - } - - tracing::debug!("binding to {addr:?} on interface {}", &ifn.name); - socket.bind(SocketAddr::new(addr.ip(), 0))?; - return Ok(()); } }