use futures::stream::StreamExt;
use netlink_packet_route::constants::*;
use netlink_sys::{AsyncSocket, SocketAddr};
use rtnetlink::new_connection;
const fn nl_mgrp(group: u32) -> u32 {
if group > 31 {
panic!("use netlink_sys::Socket::add_membership() for this group");
}
if group == 0 {
0
} else {
1 << (group - 1)
}
}
#[tokio::main]
async fn main() -> Result<(), String> {
let (mut conn, mut _handle, mut messages) =
new_connection().map_err(|e| format!("{e}"))?;
let groups = nl_mgrp(RTNLGRP_LINK)
| nl_mgrp(RTNLGRP_IPV4_IFADDR)
| nl_mgrp(RTNLGRP_IPV6_IFADDR)
| nl_mgrp(RTNLGRP_IPV4_ROUTE)
| nl_mgrp(RTNLGRP_IPV6_ROUTE)
| nl_mgrp(RTNLGRP_MPLS_ROUTE)
| nl_mgrp(RTNLGRP_IPV4_MROUTE)
| nl_mgrp(RTNLGRP_IPV6_MROUTE)
| nl_mgrp(RTNLGRP_NEIGH)
| nl_mgrp(RTNLGRP_IPV4_NETCONF)
| nl_mgrp(RTNLGRP_IPV6_NETCONF)
| nl_mgrp(RTNLGRP_IPV4_RULE)
| nl_mgrp(RTNLGRP_IPV6_RULE)
| nl_mgrp(RTNLGRP_NSID)
| nl_mgrp(RTNLGRP_MPLS_NETCONF);
let addr = SocketAddr::new(0, groups);
conn.socket_mut()
.socket_mut()
.bind(&addr)
.expect("Failed to bind");
tokio::spawn(conn);
tokio::spawn(async move {
});
while let Some((message, _)) = messages.next().await {
let payload = message.payload;
println!("{payload:?}");
}
Ok(())
}