-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move platfrom-related code to the zenoh-util
- Loading branch information
Showing
5 changed files
with
46 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
// Contributors: | ||
// ZettaScale Zenoh Team, <[email protected]> | ||
// | ||
use async_std::net::TcpStream; | ||
use async_std::net::{TcpListener, TcpStream, UdpSocket}; | ||
use std::net::{IpAddr, Ipv6Addr}; | ||
use std::time::Duration; | ||
use zenoh_core::zconfigurable; | ||
|
@@ -491,3 +491,42 @@ pub fn get_ipv6_ipaddrs(interface: Option<String>) -> Vec<IpAddr> { | |
.chain(priv_ipv4_addrs) | ||
.collect() | ||
} | ||
|
||
#[cfg(target_os = "linux")] | ||
fn set_bind_to_device(socket: std::os::raw::c_int, iface: &Option<String>) { | ||
if let Some(iface) = iface { | ||
// @TODO: switch to bind_device after tokio porting | ||
log::debug!("Listen at the interface: {}", iface); | ||
unsafe { | ||
libc::setsockopt( | ||
socket, | ||
libc::SOL_SOCKET, | ||
libc::SO_BINDTODEVICE, | ||
iface.as_ptr() as *const std::os::raw::c_void, | ||
iface.len() as libc::socklen_t, | ||
); | ||
} | ||
} | ||
} | ||
|
||
#[cfg(target_os = "linux")] | ||
pub fn set_bind_to_device_tcp(socket: &TcpListener, iface: &Option<String>) { | ||
use std::os::fd::AsRawFd; | ||
set_bind_to_device(socket.as_raw_fd(), iface); | ||
} | ||
|
||
#[cfg(target_os = "linux")] | ||
pub fn set_bind_to_device_udp(socket: &UdpSocket, iface: &Option<String>) { | ||
use std::os::fd::AsRawFd; | ||
set_bind_to_device(socket.as_raw_fd(), iface); | ||
} | ||
|
||
#[cfg(any(target_os = "macos", target_os = "windows"))] | ||
pub fn set_bind_to_device_tcp(_socket: &TcpListener, _iface: &Option<String>) { | ||
log::warn!("Listen at the interface is not supported for this platform"); | ||
} | ||
|
||
#[cfg(any(target_os = "macos", target_os = "windows"))] | ||
pub fn set_bind_to_device_udp(_socket: &UdpSocket, _iface: &Option<String>) { | ||
log::warn!("Listen at the interface is not supported for this platform"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters