tun 0.3.0

TUN device creation and handling.
Documentation

TUN interfaces Crates.io tun WTFPL

This crate allows the creation and usage of TUN interfaces, the aim is to make this cross-platform but right now it only supports Linux.

Usage

First, add the following to your Cargo.toml:

[dependencies]
tun = "0.3"

Next, add this to your crate root:

extern crate tun;

If you want to use the TUN interface with mio/tokio, you need to enable the mio feature:

[dependencies]
tun = { version = "0.3", features = ["mio"] }

Example

The following example creates and configures a TUN interface and starts reading packets from it.

use std::io::Read;

extern crate tun;

fn main() {
	let mut config = tun::Configuration::default();
	config.address((10, 0, 0, 1))
	       .netmask((255, 255, 255, 0))
	       .up();

	#[cfg(target_os = "linux")]
	config.platform(|config| {
		config.packet_information(true);
	});

	let mut dev = tun::create(&config).unwrap();
	let mut buf = [0; 4096];

	loop {
		let amount = dev.read(&mut buf).unwrap();
		println!("{:?}", &buf[0 .. amount]);
	}
}