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));
match tuple.to_socket_addrs() {
Err(e) => Err(format!("invalid address: {e}")),
Ok(mut addrs) => match addrs.next() {
None => Err("could not resolve host".to_string()),
Some(addr) => match ping_mumble_server(addr).await {
Err(e) => Err(format!("could not ping server: {e}")),
Ok(info) => Ok(Json(info)),
Ok(addrs) => {
for addr in addrs {
if let Ok(info) = ping_mumble_server(addr).await {
return Ok(Json(info));
}
}
Err("could not resolve host".to_string())
}
}
}