pub struct NetDevice { /* private fields */ }
Expand description
A reference to the network device
Implementations§
Source§impl NetDevice
impl NetDevice
Sourcepub fn open(adapter: u32, device: u32) -> Result<NetDevice>
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}
Sourcepub fn add_if(&self, pid: u16, feedtype: u8) -> Result<NetInterface<'_>>
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}
Sourcepub fn remove_if(&self, interface: NetInterface<'_>) -> Result<()>
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§
Auto Trait Implementations§
impl Freeze for NetDevice
impl RefUnwindSafe for NetDevice
impl Send for NetDevice
impl Sync for NetDevice
impl Unpin for NetDevice
impl UnwindSafe for NetDevice
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more