A KVM switch emulator using UDP/IP
use std::io;
use std::net::IpAddr;
use std::path::PathBuf;

/// Obtain the host's name
pub fn get_host_name() -> io::Result<String> {
    hostname::get()?
        .into_string()
        .map_err(|_| io::Error::new(io::ErrorKind::InvalidData, "invalid utf-8"))
}

/// Obtain all of the host's IP addresses
pub fn get_host_ips() -> io::Result<impl Iterator<Item=IpAddr>> {
    Ok(get_if_addrs::get_if_addrs()?
        .into_iter()
        .map(|interface| interface.addr.ip()))
}

// Obtain the directory for storing application data
pub fn user_app_dir(name: &str) -> Option<PathBuf> {
    Some(dirs::config_dir()?.join(name))
}