[−][src]Struct tap_windows::Device
A tap-windows device handle, it offers facilities to:
- create, open and delete interfaces
- write and read the current configuration
- write and read packets from the device Example
use tap_windows::Device; use std::io::Read; const MY_INTERFACE: &str = "My Interface"; // Try to open the device let mut dev = Device::open(MY_INTERFACE) .or_else(|_| -> std::io::Result<_> { // The device does not exists... // try creating a new one let dev = Device::create()?; dev.set_name(MY_INTERFACE)?; Ok(dev) }) // Everything failed, just panic .expect("Failed to open device"); // Set the device ip dev.set_ip([192, 168, 60, 1], [255, 255, 255, 0]) .expect("Failed to set device ip"); // Setup read buffer let mtu = dev.get_mtu().unwrap_or(1500); let mut buf = vec![0; mtu as usize]; // Read a single packet from the device let amt = dev.read(&mut buf) .expect("Failed to read packet"); // Print it println!("{:#?}", &buf[..amt]);
Implementations
impl Device
[src]
pub fn create() -> Result<Self>
[src]
Creates a new tap-windows device Example
use tap_windows::Device; let dev = Device::create() .expect("Failed to create device"); println!("{:?}", dev.get_name());
pub fn open(name: &str) -> Result<Self>
[src]
Opens an existing tap-windows device by name Example
use tap_windows::Device; let dev = Device::open("My Own Device") .expect("Failed to open device"); println!("{:?}", dev.get_name());
pub fn delete(self) -> Result<()>
[src]
Deletes the interface before closing it. By default interfaces are never deleted on Drop, with this you can choose if you want deletion or not Example
use tap_windows::Device; let dev = Device::create() .expect("Failed to create device"); println!("{:?}", dev.get_name()); // Perform a quick cleanup before exiting dev.delete().expect("Failed to delete device");
pub fn up(&self) -> Result<()>
[src]
Sets the status of the interface to connected.
Equivalent to .set_status(true)
pub fn down(&self) -> Result<()>
[src]
Sets the status of the interface to disconnected.
Equivalent to .set_status(false)
pub fn get_mac(&self) -> Result<[u8; 6]>
[src]
Retieve the mac of the interface
pub fn get_version(&self) -> Result<[u32; 3]>
[src]
Retrieve the version of the driver
pub fn get_mtu(&self) -> Result<u32>
[src]
Retieve the mtu of the interface
pub fn get_name(&self) -> Result<String>
[src]
Retrieve the name of the interface
pub fn set_name(&self, newname: &str) -> Result<()>
[src]
Set the name of the interface
pub fn set_ip<A, B>(&self, address: A, mask: B) -> Result<()> where
A: Into<Ipv4Addr>,
B: Into<Ipv4Addr>,
[src]
A: Into<Ipv4Addr>,
B: Into<Ipv4Addr>,
Set the ip of the interface
use tap_windows::Device; let dev = Device::create() .expect("Failed to create device"); dev.set_ip([192, 168, 60, 1], [255, 255, 255, 0]) .expect("Failed to set interface ip"); println!("{:?}", dev.get_name());
pub fn set_status(&self, status: bool) -> Result<()>
[src]
Set the status of the interface, true for connected, false for disconnected.
Trait Implementations
impl Drop for Device
[src]
impl Read for Device
[src]
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
[src]
fn read_vectored(&mut self, bufs: &mut [IoSliceMut]) -> Result<usize, Error>
1.36.0[src]
fn is_read_vectored(&self) -> bool
[src]
unsafe fn initializer(&self) -> Initializer
[src]
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
1.0.0[src]
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0[src]
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
1.6.0[src]
fn by_ref(&mut self) -> &mut Self
1.0.0[src]
fn bytes(self) -> Bytes<Self>
1.0.0[src]
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: Read,
1.0.0[src]
R: Read,
fn take(self, limit: u64) -> Take<Self>
1.0.0[src]
impl Write for Device
[src]
fn write(&mut self, buf: &[u8]) -> Result<usize>
[src]
fn flush(&mut self) -> Result<()>
[src]
fn write_vectored(&mut self, bufs: &[IoSlice]) -> Result<usize, Error>
1.36.0[src]
fn is_write_vectored(&self) -> bool
[src]
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
1.0.0[src]
fn write_all_vectored(&mut self, bufs: &mut [IoSlice]) -> Result<(), Error>
[src]
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
1.0.0[src]
fn by_ref(&mut self) -> &mut Self
1.0.0[src]
Auto Trait Implementations
impl RefUnwindSafe for Device
impl !Send for Device
impl !Sync for Device
impl Unpin for Device
impl UnwindSafe for Device
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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>,