From 255f84c969dee4409cdfdf67a691ad399d968bf2 Mon Sep 17 00:00:00 2001 From: lbl8603 <49143209+lbl8603@users.noreply.github.com> Date: Wed, 5 Jun 2024 22:58:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E7=A4=BA=E5=88=9B=E5=BB=BAtun?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=9A=84=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnt-cli/src/main.rs | 10 ++++++++-- vnt/src/core/conn.rs | 8 ++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/vnt-cli/src/main.rs b/vnt-cli/src/main.rs index fbdd09c..f82b44f 100644 --- a/vnt-cli/src/main.rs +++ b/vnt-cli/src/main.rs @@ -326,7 +326,7 @@ fn main() { Ok(config) => config, Err(e) => { println!("config.toml error: {}", e); - return; + std::process::exit(1); } }; (config, cmd) @@ -353,7 +353,13 @@ fn main0(config: Config, _show_cmd: bool) { println!("UDP port mapping {}->{}", addr, dest) } } - let vnt_util = Vnt::new(config, callback::VntHandler {}).unwrap(); + let vnt_util = match Vnt::new(config, callback::VntHandler {}) { + Ok(vnt) => vnt, + Err(e) => { + println!("error: {:?}", e); + std::process::exit(1); + } + }; #[cfg(any(target_os = "linux", target_os = "macos"))] { let vnt_c = vnt_util.clone(); diff --git a/vnt/src/core/conn.rs b/vnt/src/core/conn.rs index bd80078..2570bc3 100644 --- a/vnt/src/core/conn.rs +++ b/vnt/src/core/conn.rs @@ -1,3 +1,4 @@ +use anyhow::Context; use std::collections::HashMap; use std::net::Ipv4Addr; use std::sync::Arc; @@ -133,9 +134,12 @@ impl Vnt { #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] let device = { log::info!("开始创建tun"); - let device = tun_tap_device::create_device(&config)?; + let device = tun_tap_device::create_device(&config).context("create tun failed")?; log::info!("创建tun成功"); - let tun_info = DeviceInfo::new(device.name()?, device.version()?); + let tun_info = DeviceInfo::new( + device.name().unwrap_or("unknown".into()), + device.version().unwrap_or("unknown".into()), + ); log::info!("tun信息{:?}", tun_info); callback.create_tun(tun_info); device