Skip to content

Commit

Permalink
Allow the user to specify their own socket
Browse files Browse the repository at this point in the history
This is useful when dealing with multiple network/user namespaces.

Requires rust-netlink/netlink-proto#25
  • Loading branch information
MaxHearnden committed Nov 17, 2024
1 parent 5fca904 commit e0a7748
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,17 @@ where
netlink_proto::new_connection_with_socket(NETLINK_ROUTE)?;
Ok((conn, Handle::new(handle), messages))
}

#[allow(clippy::type_complexity)]
pub fn from_socket<S>(socket: S) -> (
Connection<RouteNetlinkMessage, S>,
Handle,
UnboundedReceiver<(NetlinkMessage<RouteNetlinkMessage>, SocketAddr)>,
)
where
S: AsyncSocket,
{
let (conn, handle, messages) =
netlink_proto::from_socket_with_codec(socket);
(conn, Handle::new(handle), messages)
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub use crate::addr::{
#[cfg(feature = "tokio_socket")]
pub use crate::connection::new_connection;
pub use crate::connection::new_connection_with_socket;
pub use crate::connection::from_socket;
pub use crate::errors::Error;
pub use crate::handle::Handle;
pub use crate::link::{
Expand Down

0 comments on commit e0a7748

Please sign in to comment.