From 0ca6e36011df820a8848b77b0e126ace81df86b1 Mon Sep 17 00:00:00 2001 From: Ali MJ Al-Nasrawy Date: Sun, 18 Apr 2021 18:57:35 +0300 Subject: Fix -i 0.0.0.0 Don't use `interfaces`, use `miniserve_config.interfaces` instead! Otherwise, "0.0.0.0" is converted to "localhost"! --- src/main.rs | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 4ce2bd1..19bd16b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -196,30 +196,11 @@ async fn run(miniserve_config: MiniserveConfig) -> Result<(), ContextualError> { } } - let socket_addresses = interfaces + let socket_addresses = miniserve_config + .interfaces .iter() - .map(|interface| { - format!( - "{interface}:{port}", - interface = &interface, - port = miniserve_config.port, - ) - .parse::() - }) - .collect::, _>>(); - - let socket_addresses = match socket_addresses { - Ok(addresses) => addresses, - Err(e) => { - // Note that this should never fail, since CLI parsing succeeded - // This means the format of each IP address is valid, and so is the port - // Valid IpAddr + valid port == valid SocketAddr - return Err(ContextualError::ParseError( - "string as socket address".to_string(), - e.to_string(), - )); - } - }; + .map(|&interface| SocketAddr::new(interface, miniserve_config.port)) + .collect::>(); let srv = actix_web::HttpServer::new(move || { App::new() -- cgit v1.2.3