Expand description
§Example:
use tun_rs::DeviceBuilder;
let dev = DeviceBuilder::new()
.name("utun7")
.ipv4("10.0.0.12", 24, None)
.ipv6("CDCD:910A:2222:5498:8475:1111:3900:2021", 64)
.mtu(1400)
.build_sync()
.unwrap();
let mut buf = [0;65535];
loop {
let len = dev.recv(&mut buf).unwrap();
println!("buf= {:?}",&buf[..len]);
}§Example IOS/Android/… :
#[cfg(unix)]
{
use tun_rs::SyncDevice;
// use PacketTunnelProvider/VpnService create tun fd
let fd = 7799;
let dev = unsafe{SyncDevice::from_fd(fd).unwrap()};
let mut buf = [0;65535];
loop {
let len = dev.recv(&mut buf).unwrap();
println!("buf= {:?}",&buf[..len]);
}
}Modules§
- async_
framed ( async_ioorasync_tokio) andasync_framed
Structs§
- Async
Device Unix and non-macOS - An async Tun/Tap device wrapper around a Tun/Tap device.
- Borrowed
Async Device async_ioorasync_tokio - Borrowed
Sync Device Unix - Device
Impl Unix and neither Windows, nor macOS, nor Linux and non- target_env=ohos, nor FreeBSD, nor OpenBSD, nor NetBSD - A TUN device for Android/iOS/…
- Interrupt
Event Unix and interruptible - Sync
Device - A transparent wrapper around DeviceImpl, providing synchronous I/O operations.
Constants§
- PACKET_
INFORMATION_ LENGTH - Length of the protocol info header