Crate tun_rs

Crate tun_rs 

Source
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_io or async_tokio) and async_framed

Structs§

AsyncDeviceUnix and non-macOS
An async Tun/Tap device wrapper around a Tun/Tap device.
BorrowedAsyncDeviceasync_io or async_tokio
BorrowedSyncDeviceUnix
DeviceBuilderWindows, or Linux and non-target_env=ohos, or macOS, or FreeBSD, or OpenBSD, or NetBSD
This is a unified constructor of a device for various platforms. The specification of every API can be found by looking at the documentation of the concrete platform.
DeviceImpl
A TUN device using the TUN/TAP Linux driver.
GROTable
send_multiple Using GROTable to assist in writing data
InterruptEventUnix and interruptible
SyncDevice
A transparent wrapper around DeviceImpl, providing synchronous I/O operations.

Enums§

LayerWindows, or Linux and non-target_env=ohos, or macOS, or FreeBSD, or OpenBSD, or NetBSD
Represents the OSI layer at which the TUN interface operates.

Constants§

IDEAL_BATCH_SIZE
https://github.com/WireGuard/wireguard-go/blob/master/conn/conn.go#L19
PACKET_INFORMATION_LENGTH
Length of the protocol info header
VIRTIO_NET_HDR_LEN

Traits§

ExpandBuffer
ToIpv4AddressWindows, or Linux and non-target_env=ohos, or macOS, or FreeBSD, or OpenBSD, or NetBSD
Trait for converting various types into an IPv4 address.
ToIpv4NetmaskWindows, or Linux and non-target_env=ohos, or macOS, or FreeBSD, or OpenBSD, or NetBSD
Trait for converting various types into an IPv4 netmask (prefix length).
ToIpv6AddressWindows, or Linux and non-target_env=ohos, or macOS, or FreeBSD, or OpenBSD, or NetBSD
Trait for converting various types into an IPv6 address.
ToIpv6NetmaskWindows, or Linux and non-target_env=ohos, or macOS, or FreeBSD, or OpenBSD, or NetBSD
Trait for converting various types into an IPv6 netmask (prefix length).