mirror of
https://git.alemi.dev/mumble-stats-api.git
synced 2024-12-22 12:44:53 +01:00
fix: try all addresses, in case resolves ipv6 too
This commit is contained in:
parent
734de0bde5
commit
7937330185
1 changed files with 6 additions and 5 deletions
11
src/main.rs
11
src/main.rs
|
@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue