Function nix::unistd::gethostname

source ·
pub fn gethostname() -> Result<OsString>
Expand description

Get the host name and store it in an internally allocated buffer, returning an OsString on success.

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.

§Examples

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);

See also gethostname(2).