提示创建tun失败的信息

This commit is contained in:
lbl8603
2024-06-05 22:58:56 +08:00
parent 7617d6c409
commit 255f84c969
2 changed files with 14 additions and 4 deletions
+8 -2
View File
@@ -326,7 +326,7 @@ fn main() {
Ok(config) => config, Ok(config) => config,
Err(e) => { Err(e) => {
println!("config.toml error: {}", e); println!("config.toml error: {}", e);
return; std::process::exit(1);
} }
}; };
(config, cmd) (config, cmd)
@@ -353,7 +353,13 @@ fn main0(config: Config, _show_cmd: bool) {
println!("UDP port mapping {}->{}", addr, dest) 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"))] #[cfg(any(target_os = "linux", target_os = "macos"))]
{ {
let vnt_c = vnt_util.clone(); let vnt_c = vnt_util.clone();
+6 -2
View File
@@ -1,3 +1,4 @@
use anyhow::Context;
use std::collections::HashMap; use std::collections::HashMap;
use std::net::Ipv4Addr; use std::net::Ipv4Addr;
use std::sync::Arc; use std::sync::Arc;
@@ -133,9 +134,12 @@ impl Vnt {
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
let device = { let device = {
log::info!("开始创建tun"); 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成功"); 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); log::info!("tun信息{:?}", tun_info);
callback.create_tun(tun_info); callback.create_tun(tun_info);
device device