Skip to content

Commit e126e1f

Browse files
fix(cli): ip address parsing to support both ipv4 and ipv6 (#547)
1 parent c56fc63 commit e126e1f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

cli/src/main.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::fs::File;
22
use std::io::Write;
3+
use std::net::IpAddr;
34
use std::net::SocketAddr;
45
use std::path::PathBuf;
56
use std::process::ExitCode;
@@ -79,9 +80,12 @@ fn main() -> Result<ExitCode, anyhow::Error> {
7980
let exit_code = match matches.subcommand() {
8081
Some(("start", sub_matches)) => {
8182
let ip = sub_matches.get_one::<String>("ip").cloned().unwrap();
83+
let ip = IpAddr::from_str(&ip)
84+
.context("failed to parse the IP address to bind the server")?;
85+
8286
let port = sub_matches.get_one::<u16>("port").copied().unwrap();
83-
let addr = SocketAddr::from_str(&format!("{ip}:{port}"))
84-
.context("failed to parse the address to bind the server")?;
87+
88+
let addr = SocketAddr::new(ip, port);
8589

8690
let maybe_tls =
8791
if let Some(port) = sub_matches.get_one::<u16>("tls").copied() {

0 commit comments

Comments
 (0)