fix(local): local-tun Device::name now returns Result

This commit is contained in:
zonyitoo
2023-10-10 19:52:27 +08:00
parent c0c0496656
commit eafaa55e63
2 changed files with 14 additions and 5 deletions
@@ -143,7 +143,11 @@ impl Tun {
info!(
"shadowsocks tun device {}, mode {}",
self.device.get_ref().name(),
self.device
.get_ref()
.name()
.or_else(|r| Ok::<_, ()>(r.to_string()))
.unwrap(),
self.mode,
);
@@ -1,12 +1,11 @@
use std::{
ffi::CStr,
io::{self, ErrorKind},
mem,
ptr,
mem, ptr,
};
use log::{error, trace};
use tun::{platform::Device as TunDevice, Device};
use tun::{platform::Device as TunDevice, Device, Error as TunError};
/// These numbers are used by reliable protocols for determining
/// retransmission behavior and are included in the routing structure.
@@ -75,7 +74,13 @@ pub async fn set_route_configuration(device: &TunDevice) -> io::Result<()> {
}
};
let tun_name = device.name();
let tun_name = match device.name() {
Ok(n) => n,
Err(err) => match err {
TunError::Io(err) => return Err(err),
e => return Err(io::Error::new(ErrorKind::Other, e)),
},
};
// routing packets that saddr & daddr are in the subnet of the Tun interface
//