Skip to content

Commit

Permalink
Merge pull request #20 from xmh0511/main
Browse files Browse the repository at this point in the history
update tun2 version and do not need to process packet info anymore on…
  • Loading branch information
SajjadPourali committed Jan 31, 2024
2 parents dd932b6 + 8e9363c commit 4274ca4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ tokio = { version = "1.35", features = [
], default-features = false }

#tun2.rs example
tun2 = { version = "0.7", features = ["async"] }
tun2 = { version = "1.0", features = ["async"] }

#tun_wintun.rs example
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dev-dependencies]
Expand Down
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ async fn main(){
let ipv4 = Ipv4Addr::new(10, 0, 0, 1);
let netmask = Ipv4Addr::new(255, 255, 255, 0);
let mut config = tun2::Configuration::default();
config.address(ipv4).netmask(netmask).mtu(MTU as i32).up();
config.address(ipv4).netmask(netmask).mtu(MTU as usize).up();

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

#[cfg(target_os = "windows")]
Expand All @@ -30,8 +29,6 @@ async fn main(){

let mut ipstack_config = ipstack::IpStackConfig::default();
ipstack_config.mtu(MTU);
let packet_information = cfg!(all(target_family = "unix", not(target_os = "android")));
ipstack_config.packet_information(packet_information);
let mut ip_stack = ipstack::IpStack::new(ipstack_config, tun2::create_as_async(&config).unwrap());

while let Ok(stream) = ip_stack.accept().await {
Expand Down
7 changes: 2 additions & 5 deletions examples/tun2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let gateway = Ipv4Addr::new(10, 0, 0, 1);

let mut config = tun2::Configuration::default();
config.address(ipv4).netmask(netmask).mtu(MTU as i32).up();
config.address(ipv4).netmask(netmask).mtu(MTU as usize).up();
config.destination(gateway);

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

#[cfg(target_os = "windows")]
Expand All @@ -68,8 +67,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let mut ipstack_config = ipstack::IpStackConfig::default();
ipstack_config.mtu(MTU);
let packet_information = cfg!(all(target_family = "unix", not(target_os = "android")));
ipstack_config.packet_information(packet_information);

let mut ip_stack = ipstack::IpStack::new(ipstack_config, tun2::create_as_async(&config)?);

Expand Down

0 comments on commit 4274ca4

Please sign in to comment.