From 8be40a1fbd2ab48337144a7d51df83c6a9f68d47 Mon Sep 17 00:00:00 2001 From: "B. Blechschmidt" Date: Thu, 23 Mar 2023 18:01:25 +0100 Subject: [PATCH] Squashed code beautifications commit d5fdf845bfe7d5170eb6dfa0c66d46c2021d0aa4 Author: ssrlive <30760636+ssrlive@users.noreply.github.com> Date: Thu Mar 23 23:21:22 2023 +0800 Update tun2proxy.rs commit 2540daa423e9695bbabc8716c7e9058a23f941b6 Author: ssrlive <30760636+ssrlive@users.noreply.github.com> Date: Thu Mar 23 22:40:26 2023 +0800 Update main.rs commit 9ef5efb864084389d75f059e8d240e3012b9fcb1 Author: ssrlive <30760636+ssrlive@users.noreply.github.com> Date: Thu Mar 23 22:19:06 2023 +0800 Update main.rs commit 017ea1a17a509baa5909c8620817486422736d72 Author: ssrlive <30760636+ssrlive@users.noreply.github.com> Date: Thu Mar 23 22:15:00 2023 +0800 Update main.rs --- src/main.rs | 5 +++-- src/tun2proxy.rs | 16 +++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 02677a7..36ebf41 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,10 +13,11 @@ struct Args { tun: String, /// The proxy URL in the form proto://[username[:password]@]host:port - #[arg(short, long = "proxy", value_parser = Proxy::from_url, value_name = "URL")] + #[arg(short, long, value_parser = Proxy::from_url, value_name = "URL")] proxy: Proxy, - #[arg(short, long = "dns")] + /// Enable virtual DNS feature + #[arg(short = 'd', long = "dns")] virtual_dns: bool, } diff --git a/src/tun2proxy.rs b/src/tun2proxy.rs index de27c2c..e61170b 100644 --- a/src/tun2proxy.rs +++ b/src/tun2proxy.rs @@ -48,15 +48,13 @@ pub(crate) struct Destination { impl TryFrom for SocketAddr { type Error = Error; fn try_from(value: Destination) -> Result { - Ok(SocketAddr::new( - match value.host { - DestinationHost::Address(addr) => addr, - Hostname(e) => { - return Err(e.into()); - } - }, - value.port, - )) + let ip = match value.host { + DestinationHost::Address(addr) => addr, + Hostname(e) => { + return Err(e.into()); + } + }; + Ok(SocketAddr::new(ip, value.port)) } }