[−][src]Struct nl80211::Socket
A generic netlink socket to send commands and receive messages
Fields
sock: NlSocket
family_id: u16
Methods
impl Socket
[src]
pub fn connect() -> Result<Self, NlError>
[src]
Create a new nl80211 socket with netlink
Example
// Create a new nl80211 socket and use this socket to send nl80211 commands let mut nl80211sock = Socket::connect()?; let attrs: Vec<Nlattr<Nl80211Attr, Vec<u8>>> = vec![]; // Create a netlink message header with the command CMD_GET_INTERFACE and some payloads let genlhdr = Genlmsghdr::new(Nl80211Cmd::CmdGetInterface, NL_80211_GENL_VERSION, attrs)?; // Crate a netlink header let nlhdr = { let len = None; let nl_type = nl80211sock.family_id; let flags = vec![NlmF::Request, NlmF::Dump]; // Dump info let seq = None; let pid = None; let payload = genlhdr; Nlmsghdr::new(len, nl_type, flags, seq, pid, payload) }; // Send netlink message nl80211sock.sock.send_nl(nlhdr)?; let mut iter = nl80211sock.sock.iter::<Nlmsg, Genlmsghdr<Nl80211Cmd, Nl80211Attr>>(); while let Some(Ok(response)) = iter.next() { match response.nl_type { Nlmsg::Error => panic!("Error"), Nlmsg::Done => break, _ => { // Parsing netlink messages here } } }
pub fn get_interfaces_info(&mut self) -> Result<Vec<Interface>, NlError>
[src]
Get information for all your wifi interfaces
Example
let wifi_interfaces = Socket::connect()?.get_interfaces_info(); for wifi_interface in wifi_interfaces? { println!("{}", wifi_interface.pretty_format()); }
pub fn get_station_info(
&mut self,
interface_attr_if_index: &Vec<u8>
) -> Result<Station, NlError>
[src]
&mut self,
interface_attr_if_index: &Vec<u8>
) -> Result<Station, NlError>
Get access point information for a specific interface
Example
// First of all we need to get wifi interface information to get more data let wifi_interfaces = Socket::connect()?.get_interfaces_info(); for wifi_interface in wifi_interfaces? { if let Some(netlink_index) = wifi_interface.index { // Then for each wifi interface we can fetch station information let station_info = Socket::connect()?.get_station_info(&netlink_index.clone())?; println!("{}", station_info.pretty_format()); } }
pub fn get_bss_info(
&mut self,
interface_attr_if_index: &Vec<u8>
) -> Result<Bss, NlError>
[src]
&mut self,
interface_attr_if_index: &Vec<u8>
) -> Result<Bss, NlError>
Auto Trait Implementations
impl Send for Socket
impl Unpin for Socket
impl Sync for Socket
impl UnwindSafe for Socket
impl RefUnwindSafe for Socket
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,