// Copyright (C) 2019 - Will Glozer. All rights reserved. use anyhow::Result; use nell::{Family, Message, Netlink, Socket}; use nell::api::diag; use nell::ffi::*; fn main() -> Result<()> { let mut sock = Socket::new(Family::INET_DIAG)?; let mut msg = Message::::new(SOCK_DIAG_BY_FAMILY); msg.set_flags(NLM_F_REQUEST | NLM_F_DUMP); msg.sdiag_family = AF_INET; msg.sdiag_protocol = IPPROTO_TCP; msg.idiag_states = !0; msg.idiag_ext = 1 << (INET_DIAG_INFO as u8 - 1); sock.send(&msg)?; while let Netlink::Msg(msg) = sock.recv::()? { let diag = diag(&msg)?; println!("{:?}", diag); } Ok(()) }