mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-04-22 23:09:09 +00:00
minor changes
This commit is contained in:
parent
18cdfa6b06
commit
03b6e01d4a
1 changed files with 14 additions and 9 deletions
|
@ -194,16 +194,16 @@ impl WinTunInterface {
|
|||
.iter()
|
||||
.find(|addr| addr.is_ipv4())
|
||||
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "No ipv4 gateway found"))?;
|
||||
let old_gateway = old_gateway.ip();
|
||||
self.old_gateway = Some(old_gateway);
|
||||
|
||||
// 3. route the bypass ip to the old gateway
|
||||
// command: `route add bypass_ip old_gateway metric 1`
|
||||
let bypass_ip = bypass_ip.unwrap().to_string();
|
||||
let old_gateway = old_gateway.ip();
|
||||
let args = &["add", &bypass_ip, &old_gateway.to_string(), "metric", "1"];
|
||||
if let Some(bypass_ip) = bypass_ip {
|
||||
let args = &["add", &bypass_ip.to_string(), &old_gateway.to_string(), "metric", "1"];
|
||||
run_command("route", args)?;
|
||||
log::info!("route {:?}", args);
|
||||
|
||||
self.old_gateway = Some(old_gateway);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -345,8 +345,13 @@ impl event::Source for NamedPipeSource {
|
|||
pub(crate) fn run_command(command: &str, args: &[&str]) -> io::Result<()> {
|
||||
let out = std::process::Command::new(command).args(args).output()?;
|
||||
if !out.status.success() {
|
||||
let info = format!("{} failed: {}", command, String::from_utf8_lossy(&out.stderr));
|
||||
return Err(io::Error::new(io::ErrorKind::Other, info));
|
||||
let err = String::from_utf8_lossy(if out.stderr.is_empty() {
|
||||
&out.stdout
|
||||
} else {
|
||||
&out.stderr
|
||||
});
|
||||
let info = format!("{} failed with: \"{}\"", command, err);
|
||||
return Err(std::io::Error::new(std::io::ErrorKind::Other, info));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue