Created
July 9, 2024 06:21
-
-
Save a-gavin/15c4f64d7f0ea2c8e0956f271bbefdbe to your computer and use it in GitHub Desktop.
Revisions
-
a-gavin created this gist
Jul 9, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,70 @@ use neli::{ consts::{nl::NlmF, socket::NlFamily}, genl::{AttrTypeBuilder, Genlmsghdr, GenlmsghdrBuilder, NlattrBuilder, NoUserHeader}, neli_enum, nl::NlPayload, router::synchronous::NlRouter, types::GenlBuffer, utils::Groups, }; #[neli_enum(serialized_type = "u8")] pub enum Nl80211Cmd { GetWiphy = 1, } impl neli::consts::genl::Cmd for Nl80211Cmd {} #[neli_enum(serialized_type = "u16")] pub enum Nl80211Attr { Wiphy = 1, SplitWiphyDump = 174, } impl neli::consts::genl::NlAttrType for Nl80211Attr {} fn main() { // Open control socket let (nl80211_sd, _) = NlRouter::connect(NlFamily::Generic, Some(0), Groups::empty()).unwrap(); let nl80211_family_id = nl80211_sd.resolve_genl_family("nl80211").unwrap(); // Build NL80211_CMD_GET_WIPHY command with the NL80211_ATTR_WIPHY and // NL80211_ATTR_SPLIT_WIPHY_DUMP attributes set let attrs = vec![ NlattrBuilder::default() .nla_type( AttrTypeBuilder::default() .nla_type(Nl80211Attr::Wiphy) .build() .unwrap(), ) .nla_payload(0) .build() .unwrap(), NlattrBuilder::default() .nla_type( AttrTypeBuilder::default() .nla_type(Nl80211Attr::SplitWiphyDump) .build() .unwrap(), ) .nla_payload(0) .build() .unwrap(), ]; let attrs = attrs.into_iter().collect::<GenlBuffer<_, _>>(); let genl_msg = GenlmsghdrBuilder::<Nl80211Cmd, Nl80211Attr, NoUserHeader>::default() .attrs(attrs) .version(0) .cmd(Nl80211Cmd::GetWiphy) .build() .unwrap(); // Send command _ = nl80211_sd .send::<_, _, u16, Genlmsghdr<Nl80211Cmd, Nl80211Attr>>( nl80211_family_id, NlmF::REQUEST | NlmF::DUMP | NlmF::ACK, NlPayload::Payload(genl_msg), ) .unwrap(); }