Skip to content

Commit

Permalink
Fix command line parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
erebe committed Oct 21, 2023
1 parent 8c9ee8c commit 28d4436
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
};
Expand Down

0 comments on commit 28d4436

Please sign in to comment.