Skip to main content

ip_nlroute/handle/
mod.rs

1pub struct NetlinkRouteHandle {
2    #[cfg(all(target_os = "linux", feature = "netlink"))]
3    pub(crate) rtnl: neli::router::synchronous::NlRouter,
4}
5
6impl NetlinkRouteHandle {
7    #[cfg(all(target_os = "linux", feature = "netlink"))]
8    pub fn open() -> Result<Self, crate::error::Error> {
9        let (rtnl, _) = neli::router::synchronous::NlRouter::connect(
10            neli::consts::socket::NlFamily::Route,
11            None,
12            neli::utils::Groups::empty(),
13        )?;
14        rtnl.enable_strict_checking(true)?;
15
16        Ok(Self { rtnl })
17    }
18    #[cfg(not(all(target_os = "linux", feature = "netlink")))]
19    pub fn open() -> Result<Self, crate::error::Error> {
20        Ok(Self {})
21    }
22}