From 557431252787cd72f47a44e628dc4ef75148bdd1 Mon Sep 17 00:00:00 2001 From: wayne warren Date: Tue, 23 May 2023 16:35:05 -0600 Subject: [PATCH 1/4] lib/virtual-net: tokio::net::lookup_host requires host:port format --- lib/virtual-net/src/host.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/virtual-net/src/host.rs b/lib/virtual-net/src/host.rs index 0866f1a20f3..fe25768c604 100644 --- a/lib/virtual-net/src/host.rs +++ b/lib/virtual-net/src/host.rs @@ -92,7 +92,11 @@ impl VirtualNetworking for LocalNetworking { port: Option, dns_server: Option, ) -> Result> { - tokio::net::lookup_host(host) + let port = match port { + Some(p) => p, + None => 0, + }; + tokio::net::lookup_host(format!("{}:{}", host, port)) .await .map(|a| a.map(|a| a.ip()).collect::>()) .map_err(io_err_into_net_error) From 4e8a2c12d37da33a4ce0a002efcb14fe26eb4a20 Mon Sep 17 00:00:00 2001 From: wayne warren Date: Tue, 23 May 2023 17:21:55 -0600 Subject: [PATCH 2/4] fixup! lib/virtual-net: tokio::net::lookup_host requires host:port format --- lib/virtual-net/src/host.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/virtual-net/src/host.rs b/lib/virtual-net/src/host.rs index fe25768c604..5201d339a52 100644 --- a/lib/virtual-net/src/host.rs +++ b/lib/virtual-net/src/host.rs @@ -92,11 +92,7 @@ impl VirtualNetworking for LocalNetworking { port: Option, dns_server: Option, ) -> Result> { - let port = match port { - Some(p) => p, - None => 0, - }; - tokio::net::lookup_host(format!("{}:{}", host, port)) + tokio::net::lookup_host(format!("{}:{}", host, port.unwrap_or(0))) .await .map(|a| a.map(|a| a.ip()).collect::>()) .map_err(io_err_into_net_error) From 2cfb359fff331d3c3fbee8e790870762298dcd74 Mon Sep 17 00:00:00 2001 From: wayne warren Date: Wed, 24 May 2023 11:50:30 -0600 Subject: [PATCH 3/4] lib/virtual-net: allow given host string to contain port already --- lib/virtual-net/src/host.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/virtual-net/src/host.rs b/lib/virtual-net/src/host.rs index 5201d339a52..ac3c3f6e2e8 100644 --- a/lib/virtual-net/src/host.rs +++ b/lib/virtual-net/src/host.rs @@ -92,10 +92,20 @@ impl VirtualNetworking for LocalNetworking { port: Option, dns_server: Option, ) -> Result> { - tokio::net::lookup_host(format!("{}:{}", host, port.unwrap_or(0))) - .await - .map(|a| a.map(|a| a.ip()).collect::>()) - .map_err(io_err_into_net_error) + tokio::net::lookup_host( + host.chars() + .find_map(|c| { + if c == ':' { + Some(host.to_string()) + } else { + None + } + }) + .unwrap_or(format!("{}:{}", host, port.unwrap_or(0))), + ) + .await + .map(|a| a.map(|a| a.ip()).collect::>()) + .map_err(io_err_into_net_error) } } From 20f6189116655e8ff7088a9f9da00f391815036d Mon Sep 17 00:00:00 2001 From: wayne warren Date: Wed, 24 May 2023 12:15:01 -0600 Subject: [PATCH 4/4] fixup! lib/virtual-net: allow given host string to contain port already --- lib/virtual-net/src/host.rs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/lib/virtual-net/src/host.rs b/lib/virtual-net/src/host.rs index ac3c3f6e2e8..4885d81728f 100644 --- a/lib/virtual-net/src/host.rs +++ b/lib/virtual-net/src/host.rs @@ -92,20 +92,15 @@ impl VirtualNetworking for LocalNetworking { port: Option, dns_server: Option, ) -> Result> { - tokio::net::lookup_host( - host.chars() - .find_map(|c| { - if c == ':' { - Some(host.to_string()) - } else { - None - } - }) - .unwrap_or(format!("{}:{}", host, port.unwrap_or(0))), - ) - .await - .map(|a| a.map(|a| a.ip()).collect::>()) - .map_err(io_err_into_net_error) + let host_to_lookup = if host.contains(':') { + host.to_string() + } else { + format!("{}:{}", host, port.unwrap_or(0)) + }; + tokio::net::lookup_host(host_to_lookup) + .await + .map(|a| a.map(|a| a.ip()).collect::>()) + .map_err(io_err_into_net_error) } }