From 602006f9c39b96aede97e895e006452435d7d077 Mon Sep 17 00:00:00 2001 From: xmh0511 <970252187@qq.com> Date: Mon, 29 Jan 2024 10:59:08 +0800 Subject: [PATCH 1/3] update tun2 version and do not need to process packet info anymore on all platforms --- Cargo.toml | 2 +- examples/tun2.rs | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 432e6a7..84739ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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.0", features = ["async"] } #tun_wintun.rs example [target.'cfg(any(target_os = "linux", target_os = "macos"))'.dev-dependencies] diff --git a/examples/tun2.rs b/examples/tun2.rs index 67b920e..7eed409 100644 --- a/examples/tun2.rs +++ b/examples/tun2.rs @@ -52,13 +52,12 @@ async fn main() -> Result<(), Box> { 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")] @@ -68,8 +67,6 @@ async fn main() -> Result<(), Box> { 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)?); From e089db33e8cc3bded18a00759a6b914c6f95e633 Mon Sep 17 00:00:00 2001 From: xmh0511 <970252187@qq.com> Date: Mon, 29 Jan 2024 11:04:28 +0800 Subject: [PATCH 2/3] update example --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 827cfb1..1504db9 100644 --- a/README.md +++ b/README.md @@ -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")] @@ -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 { From 8e9363c43e2dc97b39a432db8596cc6b820fbed0 Mon Sep 17 00:00:00 2001 From: xmh0511 <970252187@qq.com> Date: Tue, 30 Jan 2024 11:33:41 +0800 Subject: [PATCH 3/3] Update Cargo.toml --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 84739ee..3e8e61b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ tokio = { version = "1.35", features = [ ], default-features = false } #tun2.rs example -tun2 = { version = "1.0.0", features = ["async"] } +tun2 = { version = "1.0", features = ["async"] } #tun_wintun.rs example [target.'cfg(any(target_os = "linux", target_os = "macos"))'.dev-dependencies]