Struct NetDevice

Source
pub struct NetDevice { /* private fields */ }
Expand description

A reference to the network device

Implementations§

Source§

impl NetDevice

Source

pub fn open(adapter: u32, device: u32) -> Result<NetDevice>

Attempts to open a network device in read-write mode

Examples found in repository?
examples/netinfo.rs (line 19)
6fn main() -> Result<()> {
7    let mut args = std::env::args().skip(1);
8
9    let adapter = match args.next() {
10        Some(v) => v.parse::<u32>().context("adapter number")?,
11        None => bail!("adapter number not defined"),
12    };
13
14    let device = match args.next() {
15        Some(v) => v.parse::<u32>().context("device number")?,
16        None => 0,
17    };
18
19    let dev = NetDevice::open(adapter, device)?;
20
21    let interface = dev.add_if(0, libdvb_rs::net::sys::DVB_NET_FEEDTYPE_MPE)?;
22    println!("Interface: {}", &interface);
23    let mac = interface.get_mac();
24    println!("MAC: {}", &mac);
25    dev.remove_if(interface)?;
26
27    Ok(())
28}
Source

pub fn add_if(&self, pid: u16, feedtype: u8) -> Result<NetInterface<'_>>

Creates a new network interface and returns interface number

Examples found in repository?
examples/netinfo.rs (line 21)
6fn main() -> Result<()> {
7    let mut args = std::env::args().skip(1);
8
9    let adapter = match args.next() {
10        Some(v) => v.parse::<u32>().context("adapter number")?,
11        None => bail!("adapter number not defined"),
12    };
13
14    let device = match args.next() {
15        Some(v) => v.parse::<u32>().context("device number")?,
16        None => 0,
17    };
18
19    let dev = NetDevice::open(adapter, device)?;
20
21    let interface = dev.add_if(0, libdvb_rs::net::sys::DVB_NET_FEEDTYPE_MPE)?;
22    println!("Interface: {}", &interface);
23    let mac = interface.get_mac();
24    println!("MAC: {}", &mac);
25    dev.remove_if(interface)?;
26
27    Ok(())
28}
Source

pub fn remove_if(&self, interface: NetInterface<'_>) -> Result<()>

Removes a network interface

Examples found in repository?
examples/netinfo.rs (line 25)
6fn main() -> Result<()> {
7    let mut args = std::env::args().skip(1);
8
9    let adapter = match args.next() {
10        Some(v) => v.parse::<u32>().context("adapter number")?,
11        None => bail!("adapter number not defined"),
12    };
13
14    let device = match args.next() {
15        Some(v) => v.parse::<u32>().context("device number")?,
16        None => 0,
17    };
18
19    let dev = NetDevice::open(adapter, device)?;
20
21    let interface = dev.add_if(0, libdvb_rs::net::sys::DVB_NET_FEEDTYPE_MPE)?;
22    println!("Interface: {}", &interface);
23    let mac = interface.get_mac();
24    println!("MAC: {}", &mac);
25    dev.remove_if(interface)?;
26
27    Ok(())
28}

Trait Implementations§

Source§

impl AsRawFd for NetDevice

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl Debug for NetDevice

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.