From f3fd0069786282e429bbab3efc3de0c5759bb155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=A3rebe=20-=20Romain=20GERARD?= Date: Sat, 21 Oct 2023 15:23:25 +0200 Subject: [PATCH] Fix command line parsing Former-commit-id: b36693f619525c3c6196bcefbb77d566f7618364 [formerly 10726be9d050b3891b797ecebba9dcc8a45dfb7e] [formerly b8295a04bd8f5d591c677e1bded1e4a5bb1e5af6 [formerly 28d443681b6d9b94a719203e746f9a3d542fac46]] Former-commit-id: 8f77fc39adff92421852e6ed5e296e46e446f605 [formerly 9a8ef64aa90ff4880d4a90c9bfd57509ee705e6c] Former-commit-id: 743d161581e3752f138426cd854b2dcfde055dfe Former-commit-id: b8d50c1746aa5295980a02fb5b1be0a55d682cbc Former-commit-id: 981c8d7404e0bbf3b2884c4c72df27c0a49b4df1 Former-commit-id: ae68f651b57fcad5316c9d38f76a1a911bf2797e [formerly 1d4b878c54c39c4baece82f3811c6cdb8f2022ce] Former-commit-id: 2859f6d56f92d30a8becdb052ef72399a8824c54 --- src/main.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1b4e4c6..2521056 100644 --- a/src/main.rs +++ b/src/main.rs @@ -203,16 +203,11 @@ fn parse_local_bind(arg: &str) -> Result<(SocketAddr, &str), io::Error> { (IpAddr::V6(ipv6_addr), remaining) } else { // Maybe ipv4 addr - let Some((ipv4_str, remaining)) = arg.split_once(':') else { - return Err(Error::new( - ErrorKind::InvalidInput, - format!("cannot parse IPv4 bind from {}", arg), - )); - }; + let (ipv4_str, remaining) = arg.split_once(':').unwrap_or((arg, "")); match Ipv4Addr::from_str(ipv4_str) { Ok(ip4_addr) => (IpAddr::V4(ip4_addr), remaining), - // Must be the port, so we default to ipv6 bind + // Must be the port, so we default to ipv4 bind Err(_) => (IpAddr::V4(Ipv4Addr::from_str("127.0.0.1").unwrap()), arg), } };