fix: try all addresses, in case resolves ipv6 too

This commit is contained in:
əlemi 2024-02-17 04:11:56 +01:00
parent 734de0bde5
commit 7937330185
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -35,12 +35,13 @@ async fn ping_server(Query(options): Query<PingOptions>) -> Result<Json<ServerIn
let tuple = (options.host, options.port.unwrap_or(64738)); let tuple = (options.host, options.port.unwrap_or(64738));
match tuple.to_socket_addrs() { match tuple.to_socket_addrs() {
Err(e) => Err(format!("invalid address: {e}")), Err(e) => Err(format!("invalid address: {e}")),
Ok(mut addrs) => match addrs.next() { Ok(addrs) => {
None => Err("could not resolve host".to_string()), for addr in addrs {
Some(addr) => match ping_mumble_server(addr).await { if let Ok(info) = ping_mumble_server(addr).await {
Err(e) => Err(format!("could not ping server: {e}")), return Ok(Json(info));
Ok(info) => Ok(Json(info)), }
} }
Err("could not resolve host".to_string())
} }
} }
} }