Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #290 from WGH-/fix-ip-monitor-example
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTitor authored Sep 27, 2022
2 parents 3dabd3e + 546e944 commit b2c64f9
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions rtnetlink/examples/ip_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ use rtnetlink::{
sys::{AsyncSocket, SocketAddr},
};

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> {
// conn - `Connection` that has a netlink socket which is a `Future` that polls the socket
Expand All @@ -19,21 +29,21 @@ async fn main() -> Result<(), String> {
let (mut conn, mut _handle, mut messages) = new_connection().map_err(|e| format!("{}", e))?;

// These flags specify what kinds of broadcast messages we want to listen for.
let groups = RTNLGRP_LINK
| RTNLGRP_IPV4_IFADDR
| RTNLGRP_IPV6_IFADDR
| RTNLGRP_IPV4_ROUTE
| RTNLGRP_IPV6_ROUTE
| RTNLGRP_MPLS_ROUTE
| RTNLGRP_IPV4_MROUTE
| RTNLGRP_IPV6_MROUTE
| RTNLGRP_NEIGH
| RTNLGRP_IPV4_NETCONF
| RTNLGRP_IPV6_NETCONF
| RTNLGRP_IPV4_RULE
| RTNLGRP_IPV6_RULE
| RTNLGRP_NSID
| RTNLGRP_MPLS_NETCONF;
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()
Expand Down

0 comments on commit b2c64f9

Please sign in to comment.