From f089673e1f21f1cfe557dfa05c4b36b92c08448f Mon Sep 17 00:00:00 2001 From: Yuyuan Yuan Date: Thu, 14 Mar 2024 16:50:35 +0800 Subject: [PATCH] Fix the permission denied while binding to None interface on some platforms (#826) --- commons/zenoh-util/src/std_only/net/mod.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/commons/zenoh-util/src/std_only/net/mod.rs b/commons/zenoh-util/src/std_only/net/mod.rs index 3e6caa2d8f..8ec0ed03a1 100644 --- a/commons/zenoh-util/src/std_only/net/mod.rs +++ b/commons/zenoh-util/src/std_only/net/mod.rs @@ -425,13 +425,17 @@ pub fn get_ipv6_ipaddrs(interface: Option<&str>) -> Vec { #[cfg(target_os = "linux")] pub fn set_bind_to_device_tcp_socket(socket: &TcpSocket, iface: Option<&str>) -> ZResult<()> { - socket.bind_device(iface.map(|x| x.as_bytes()))?; + if let Some(iface) = iface { + socket.bind_device(Some(iface.as_bytes()))?; + } Ok(()) } #[cfg(target_os = "linux")] pub fn set_bind_to_device_udp_socket(socket: &UdpSocket, iface: Option<&str>) -> ZResult<()> { - socket.bind_device(iface.map(|x| x.as_bytes()))?; + if let Some(iface) = iface { + socket.bind_device(Some(iface.as_bytes()))?; + } Ok(()) }