Skip to content

Commit 71abd20

Browse files
committed
Allow the user to specify their own socket
This is useful when dealing with multiple network/user namespaces. Requires rust-netlink/netlink-proto#25
1 parent 5fca904 commit 71abd20

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/connection.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,19 @@ where
3333
netlink_proto::new_connection_with_socket(NETLINK_ROUTE)?;
3434
Ok((conn, Handle::new(handle), messages))
3535
}
36+
37+
#[allow(clippy::type_complexity)]
38+
pub fn from_socket<S>(
39+
socket: S,
40+
) -> (
41+
Connection<RouteNetlinkMessage, S>,
42+
Handle,
43+
UnboundedReceiver<(NetlinkMessage<RouteNetlinkMessage>, SocketAddr)>,
44+
)
45+
where
46+
S: AsyncSocket,
47+
{
48+
let (conn, handle, messages) =
49+
netlink_proto::from_socket_with_codec(socket);
50+
(conn, Handle::new(handle), messages)
51+
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ mod traffic_control;
2929
pub use crate::addr::{
3030
AddressAddRequest, AddressDelRequest, AddressGetRequest, AddressHandle,
3131
};
32+
pub use crate::connection::from_socket;
3233
#[cfg(feature = "tokio_socket")]
3334
pub use crate::connection::new_connection;
3435
pub use crate::connection::new_connection_with_socket;

0 commit comments

Comments
 (0)