// Copyright (C) 2019 - Will Glozer. All rights reserved. use anyhow::Result; use nell::{Family, Message, Netlink, Socket}; use nell::api::{addr, link, peer, route}; use nell::ffi::*; use Netlink::Msg; fn main() -> Result<()> { let mut sock = Socket::new(Family::ROUTE)?; let mut msg = Message::::new(RTM_GETLINK); msg.set_flags(NLM_F_REQUEST | NLM_F_DUMP); msg.rtgen_family = AF_UNSPEC; sock.send(&msg)?; while let Msg(msg) = sock.recv::()? { let link = link(&msg)?; println!("{:?}", link); } let mut msg = Message::::new(RTM_GETADDR); msg.set_flags(NLM_F_REQUEST | NLM_F_DUMP); msg.rtgen_family = AF_UNSPEC; sock.send(&msg)?; while let Msg(msg) = sock.recv::()? { let addr = addr(&msg)?; println!("{:?}", addr); } let mut msg = Message::::new(RTM_GETROUTE); msg.set_flags(NLM_F_REQUEST | NLM_F_DUMP); msg.rtgen_family = AF_UNSPEC; sock.send(&msg)?; while let Msg(msg) = sock.recv::()? { let route = route(&msg)?; println!("{:?}", route); } let mut msg = Message::::new(RTM_GETNEIGH); msg.set_flags(NLM_F_REQUEST | NLM_F_DUMP); msg.rtgen_family = AF_UNSPEC; sock.send(&msg)?; while let Msg(msg) = sock.recv::()? { let peer = peer(&msg)?; println!("{:?}", peer); } Ok(()) }