diff --git a/Cargo.lock b/Cargo.lock index 0d5acb3..66532ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -314,6 +314,7 @@ dependencies = [ "http-body-util", "hyper", "hyper-util", + "rand", "ratatui", "reqwest", "serde", diff --git a/Cargo.toml b/Cargo.toml index 6f32425..3fd1d10 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ zbus = { version = "5.11", default-features = false, features = ["tokio"] } http-body-util = { version = "0.1", default-features = false } serde_json = { version = "1.0", default-features = false } anyhow = { version = "1.0", default-features = false } +rand = { version = "0.9", default-features = false, features = ["thread_rng"] } [build-dependencies] uefi-reset = { version = "1.0", artifact = "bin", target = "x86_64-unknown-uefi" } diff --git a/src/avahi.rs b/src/avahi.rs index 5974948..299f4a4 100644 --- a/src/avahi.rs +++ b/src/avahi.rs @@ -71,6 +71,9 @@ impl AvahiService { pub async fn register(&self, name: &str, port: u16, txt: &[(&str, &str)]) -> Result<()> { let service_type = format!("_{name}._tcp"); + // Generate a random suffix to avoid service name collisions on the network. + let service_name = format!("{name}-{:04x}", rand::random::()); + // Convert TXT records to the format expected by Avahi let txt: Vec> = txt .iter() @@ -84,7 +87,7 @@ impl AvahiService { // domain: "" (use default) // host: "" (use local hostname) self.entry_group - .add_service(-1, 0, 0, name, &service_type, "", "", port, txt) + .add_service(-1, 0, 0, &service_name, &service_type, "", "", port, txt) .await .context("Failed to add service")?;