diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 41b7cd2b1..a2eeb30ae 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -1198,6 +1198,7 @@ dependencies = [ "futures", "futures-util", "hickory-resolver", + "hostname", "ip_network", "libc", "log", @@ -2078,6 +2079,7 @@ dependencies = [ "connlib-client-shared", "connlib-shared", "firezone-cli-utils", + "hostname", "ipconfig", "keyring", "ring 0.17.7", diff --git a/rust/connlib/shared/Cargo.toml b/rust/connlib/shared/Cargo.toml index 050dd34d9..8c95a870b 100644 --- a/rust/connlib/shared/Cargo.toml +++ b/rust/connlib/shared/Cargo.toml @@ -15,6 +15,8 @@ boringtun = { workspace = true } chrono = { workspace = true } futures = { version = "0.3", default-features = false, features = ["std", "async-await", "executor"] } futures-util = { version = "0.3", default-features = false, features = ["std", "async-await", "async-await-macro"] } +# Hickory already depends on `hostname` so this isn't new +hostname = "0.3.1" ip_network = { version = "0.4", default-features = false, features = ["serde"] } os_info = { version = "3", default-features = false } parking_lot = "0.12" diff --git a/rust/connlib/shared/src/lib.rs b/rust/connlib/shared/src/lib.rs index 9b1f64239..9dc3678b4 100644 --- a/rust/connlib/shared/src/lib.rs +++ b/rust/connlib/shared/src/lib.rs @@ -153,10 +153,10 @@ fn get_host_name() -> Option { String::from_utf8(buf.split(|c| *c == 0).next()?.to_vec()).ok() } +/// Returns the hostname, or `None` if it's not valid UTF-8 #[cfg(target_os = "windows")] fn get_host_name() -> Option { - // FIXME: windows - None + hostname::get().ok().and_then(|x| x.into_string().ok()) } fn set_ws_scheme(url: &mut Url) -> Result<()> { diff --git a/rust/windows-client/src-tauri/Cargo.toml b/rust/windows-client/src-tauri/Cargo.toml index 1fa6d8ea7..6b04071f0 100755 --- a/rust/windows-client/src-tauri/Cargo.toml +++ b/rust/windows-client/src-tauri/Cargo.toml @@ -18,6 +18,8 @@ clap = { version = "4.4", features = ["derive", "env"] } connlib-client-shared = { workspace = true } connlib-shared = { workspace = true } firezone-cli-utils = { workspace = true } +# Same crate Hickory uses +hostname = "0.3.1" # This is the same crate hickory uses to get system resolvers ipconfig = "0.3.2" keyring = "2.0.5" diff --git a/rust/windows-client/src-tauri/src/client.rs b/rust/windows-client/src-tauri/src/client.rs index b8c38060d..2c0274041 100644 --- a/rust/windows-client/src-tauri/src/client.rs +++ b/rust/windows-client/src-tauri/src/client.rs @@ -66,6 +66,7 @@ pub(crate) fn run() -> Result<()> { println!("debug"); Ok(()) } + Some(Cmd::DebugHostname) => debug_commands::hostname(), Some(Cmd::DebugPipeServer) => debug_commands::pipe_server(), Some(Cmd::DebugWintun) => debug_commands::wintun(cli), // If we already tried to elevate ourselves, don't try again diff --git a/rust/windows-client/src-tauri/src/client/cli.rs b/rust/windows-client/src-tauri/src/client/cli.rs index adb4c9686..3591556fe 100755 --- a/rust/windows-client/src-tauri/src/client/cli.rs +++ b/rust/windows-client/src-tauri/src/client/cli.rs @@ -12,6 +12,7 @@ pub struct Cli { #[derive(clap::Subcommand)] pub enum CliCommands { Debug, + DebugHostname, DebugPipeServer, DebugWintun, Elevated, diff --git a/rust/windows-client/src-tauri/src/client/debug_commands.rs b/rust/windows-client/src-tauri/src/client/debug_commands.rs index fc4681865..178a59cdf 100644 --- a/rust/windows-client/src-tauri/src/client/debug_commands.rs +++ b/rust/windows-client/src-tauri/src/client/debug_commands.rs @@ -8,6 +8,14 @@ use tokio::runtime::Runtime; // TODO: In tauri-plugin-deep-link, this is the identifier in tauri.conf.json const PIPE_NAME: &str = "dev.firezone.client"; +pub fn hostname() -> Result<()> { + println!( + "{:?}", + hostname::get().ok().and_then(|x| x.into_string().ok()) + ); + Ok(()) +} + pub fn open_deep_link(path: &url::Url) -> Result<()> { tracing_subscriber::fmt::init();