mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-02 14:07:46 +00:00
uucore/utmpx: remove unwrap in cannon_host
Default to hostname if getaddrinfo fails
This commit is contained in:
parent
2e12316ae1
commit
235152a6b7
1 changed files with 13 additions and 10 deletions
|
@ -236,17 +236,20 @@ impl Utmpx {
|
||||||
flags: AI_CANONNAME,
|
flags: AI_CANONNAME,
|
||||||
..AddrInfoHints::default()
|
..AddrInfoHints::default()
|
||||||
};
|
};
|
||||||
let sockets = getaddrinfo(Some(hostname), None, Some(hints))
|
if let Ok(sockets) = getaddrinfo(Some(hostname), None, Some(hints)) {
|
||||||
.unwrap()
|
let sockets = sockets.collect::<IOResult<Vec<_>>>()?;
|
||||||
.collect::<IOResult<Vec<_>>>()?;
|
for socket in sockets {
|
||||||
for socket in sockets {
|
if let Some(ai_canonname) = socket.canonname {
|
||||||
if let Some(ai_canonname) = socket.canonname {
|
return Ok(if display.is_empty() {
|
||||||
return Ok(if display.is_empty() {
|
ai_canonname
|
||||||
ai_canonname
|
} else {
|
||||||
} else {
|
format!("{}:{}", ai_canonname, display)
|
||||||
format!("{}:{}", ai_canonname, display)
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// GNU coreutils has this behavior
|
||||||
|
return Ok(hostname.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue