mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-04-20 13:59:10 +00:00
Refine code
This commit is contained in:
parent
46bf4434ef
commit
7a7293effd
1 changed files with 2 additions and 8 deletions
10
src/args.rs
10
src/args.rs
|
@ -395,17 +395,11 @@ impl TryFrom<&str> for ArgProxy {
|
||||||
let e = format!("`{s}` does not contain a host");
|
let e = format!("`{s}` does not contain a host");
|
||||||
let host = url.host_str().ok_or(Error::from(e))?;
|
let host = url.host_str().ok_or(Error::from(e))?;
|
||||||
|
|
||||||
let mut url_host = String::from(host);
|
|
||||||
let e = format!("`{s}` does not contain a port");
|
let e = format!("`{s}` does not contain a port");
|
||||||
let port = url.port_or_known_default().ok_or(Error::from(&e))?;
|
let port = url.port_or_known_default().ok_or(Error::from(&e))?;
|
||||||
url_host.push(':');
|
|
||||||
url_host.push_str(port.to_string().as_str());
|
|
||||||
|
|
||||||
let e = format!("`{host}` could not be resolved");
|
let e2 = format!("`{host}` does not resolve to a usable IP address");
|
||||||
let mut addr_iter = url_host.to_socket_addrs().map_err(|_| Error::from(&e))?;
|
let addr = (host, port).to_socket_addrs()?.next().ok_or(Error::from(&e2))?;
|
||||||
|
|
||||||
let e = format!("`{host}` does not resolve to a usable IP address");
|
|
||||||
let addr = addr_iter.next().ok_or(Error::from(&e))?;
|
|
||||||
|
|
||||||
let credentials = if url.username() == "" && url.password().is_none() {
|
let credentials = if url.username() == "" && url.password().is_none() {
|
||||||
None
|
None
|
||||||
|
|
Loading…
Add table
Reference in a new issue