pub fn gethostname() -> Result<OsString>
Expand description
Get the host name and store it in an internally allocated buffer, returning an
OsString
on success (see
gethostname(2)).
This function call attempts to get the host name for the running system and
store it in an internal buffer, returning it as an OsString
if successful.
use nix::unistd;
let hostname = unistd::gethostname().expect("Failed getting hostname");
let hostname = hostname.into_string().expect("Hostname wasn't valid UTF-8");
println!("Hostname: {}", hostname);