Skip to content

Commit

Permalink
fix(local): local-tun Device::name now returns Result
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed Oct 10, 2023
1 parent c0c0496 commit eafaa55
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 5 additions & 1 deletion crates/shadowsocks-service/src/local/tun/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand Down
13 changes: 9 additions & 4 deletions crates/shadowsocks-service/src/local/tun/sys/unix/apple/macos.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
//
Expand Down

0 comments on commit eafaa55

Please sign in to comment.