Skip to content

Commit

Permalink
update tun2 example (#42)
Browse files Browse the repository at this point in the history
* update tun2 example

* cargo fmt
  • Loading branch information
xmh0511 committed Apr 24, 2024
1 parent 1eb6941 commit 7621a08
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions examples/tun2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let ipv4 = Ipv4Addr::new(10, 0, 0, 33);
let netmask = Ipv4Addr::new(255, 255, 255, 0);
let _gateway = Ipv4Addr::new(10, 0, 0, 1);
#[cfg(not(target_os = "windows"))]
let gateway = Ipv4Addr::new(10, 0, 0, 1);

let mut tun_config = tun2::Configuration::default();
tun_config.address(ipv4).netmask(netmask).mtu(MTU).up();
#[cfg(not(target_os = "windows"))]
tun_config.destination(_gateway); // avoid routing all traffic to tun on Windows platform
tun_config.destination(gateway); // avoid routing all traffic to tun on Windows platform

#[cfg(target_os = "linux")]
tun_config.platform_config(|p_cfg| {
Expand Down

0 comments on commit 7621a08

Please sign in to comment.