From 1a12b70f95867f2a9db2c61aadbb967f42fbd8a8 Mon Sep 17 00:00:00 2001 From: FelixSelter Date: Sun, 8 Feb 2026 12:13:46 +0100 Subject: [PATCH 1/5] comments on service name length<=15 limit Added two comments to explain the limitation and that the lib will silently fail without a monitor connection - Added a comment to the ty_domain property of ServiceInfo - Added a bold portion in the docstring of new --- src/service_info.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/service_info.rs b/src/service_info.rs index 00f86db..1006e08 100644 --- a/src/service_info.rs +++ b/src/service_info.rs @@ -87,6 +87,8 @@ fn escape_instance_name(name: &str) -> String { /// as well as A (IPv4 Address) and AAAA (IPv6 Address) records. #[derive(Debug, Clone)] pub struct ServiceInfo { + // With default settings service name length must be <= 15 bytes + // so "_abcdefghijklmno._udp.local." would be valid but "_abcdefghijklmnop._udp.local." is not ty_domain: String, // . /// See RFC6763 section 7.1 about "Subtypes": @@ -128,6 +130,9 @@ impl ServiceInfo { /// /// `ty_domain` is the service type and the domain label, for example /// "_my-service._udp.local.". + /// With default settings service name length must be <= 15 bytes + /// so "_abcdefghijklmno._udp.local." would be valid but "_abcdefghijklmnop._udp.local." is not + /// ❗ **This will silently fail and no error will be shown** unless you setup a monitor connection via `ServiceDaemon::monitor()` /// /// `my_name` is the instance name, without the service type suffix. /// It allows dots (`.`) and backslashes (`\`). From d0430d10af2a69e686f6bb9cb9dd721a27cc2140 Mon Sep 17 00:00:00 2001 From: FelixSelter Date: Sun, 8 Feb 2026 12:28:46 +0100 Subject: [PATCH 2/5] warning about service name length <=15 added to module docstring --- src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index f9e575c..d110abd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,6 +41,9 @@ //! let mdns = ServiceDaemon::new().expect("Failed to create daemon"); //! //! // Browse for a service type. +//! // ❗ Make sure that the service name: "mdns-sd-my-test" is <= 15 characters or this will silently fail +//! // You may also want to setup a monitor connection via `mdns.monitor` and log any `DaemonEvent::Error` +//! // You can see how to setup this inside the register example //! let service_type = "_mdns-sd-my-test._udp.local."; //! let receiver = mdns.browse(service_type).expect("Failed to browse"); //! @@ -75,6 +78,9 @@ //! let mdns = ServiceDaemon::new().expect("Failed to create daemon"); //! //! // Create a service info. +//! // ❗ Make sure that the service name: "mdns-sd-my-test" is <= 15 characters or this will silently fail +//! // You may also want to setup a monitor connection via `mdns.monitor` and log any `DaemonEvent::Error` +//! // You can see how to setup this inside the register example //! let service_type = "_mdns-sd-my-test._udp.local."; //! let instance_name = "my_instance"; //! let ip = "192.168.1.12"; From 5075dfc14e684a38eb9d8f5007b3a7e7e484e257 Mon Sep 17 00:00:00 2001 From: FelixSelter Date: Sun, 8 Feb 2026 12:37:07 +0100 Subject: [PATCH 3/5] check_service_name_length was changed from debug to error If this fails no service will be published and the library is not working as intended by the user therefore this should be a hard error. There are a ton of logs and with debug it seemed unimportant and was near impossible to find for users without experience of this crate --- src/service_daemon.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/service_daemon.rs b/src/service_daemon.rs index 0e10c1a..ff7362d 100644 --- a/src/service_daemon.rs +++ b/src/service_daemon.rs @@ -29,7 +29,7 @@ // in Service Discovery, the basic data structure is "Service Info". One Service Info // corresponds to a set of DNS Resource Records. #[cfg(feature = "logging")] -use crate::log::{debug, trace}; +use crate::log::{debug, error, trace}; use crate::{ dns_cache::{current_time_millis, DnsCache}, dns_parser::{ @@ -1863,7 +1863,7 @@ impl Zeroconf { fn register_service(&mut self, mut info: ServiceInfo) { // Check the service name length. if let Err(e) = check_service_name_length(info.get_type(), self.service_name_len_max) { - debug!("check_service_name_length: {}", &e); + error!("check_service_name_length: {}", &e); self.notify_monitors(DaemonEvent::Error(e)); return; } From 92e164969166c16e43ba9dda08c2a23d02dcc1a8 Mon Sep 17 00:00:00 2001 From: FelixSelter Date: Wed, 11 Feb 2026 18:29:04 +0100 Subject: [PATCH 4/5] updated comments --- src/lib.rs | 5 +---- src/service_info.rs | 3 ++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d110abd..acc39dc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,9 +41,6 @@ //! let mdns = ServiceDaemon::new().expect("Failed to create daemon"); //! //! // Browse for a service type. -//! // ❗ Make sure that the service name: "mdns-sd-my-test" is <= 15 characters or this will silently fail -//! // You may also want to setup a monitor connection via `mdns.monitor` and log any `DaemonEvent::Error` -//! // You can see how to setup this inside the register example //! let service_type = "_mdns-sd-my-test._udp.local."; //! let receiver = mdns.browse(service_type).expect("Failed to browse"); //! @@ -78,7 +75,7 @@ //! let mdns = ServiceDaemon::new().expect("Failed to create daemon"); //! //! // Create a service info. -//! // ❗ Make sure that the service name: "mdns-sd-my-test" is <= 15 characters or this will silently fail +//! // ❗ Make sure that the service name: "mdns-sd-my-test" is not longer than the max length limit. (15 characters by default) //! // You may also want to setup a monitor connection via `mdns.monitor` and log any `DaemonEvent::Error` //! // You can see how to setup this inside the register example //! let service_type = "_mdns-sd-my-test._udp.local."; diff --git a/src/service_info.rs b/src/service_info.rs index 1006e08..638d21f 100644 --- a/src/service_info.rs +++ b/src/service_info.rs @@ -132,7 +132,8 @@ impl ServiceInfo { /// "_my-service._udp.local.". /// With default settings service name length must be <= 15 bytes /// so "_abcdefghijklmno._udp.local." would be valid but "_abcdefghijklmnop._udp.local." is not - /// ❗ **This will silently fail and no error will be shown** unless you setup a monitor connection via `ServiceDaemon::monitor()` + /// ❗ **This will fail with an error log which may not be noticed unless you properly setup logging**. + /// It is recommended to setup a monitor connection via `ServiceDaemon::monitor()` /// /// `my_name` is the instance name, without the service type suffix. /// It allows dots (`.`) and backslashes (`\`). From 865cebf2c15382b1b00583334528b5752bdd794f Mon Sep 17 00:00:00 2001 From: FelixSelter Date: Wed, 11 Feb 2026 18:39:33 +0100 Subject: [PATCH 5/5] added monitor connection to module doc example --- src/lib.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index acc39dc..1f2717c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -74,10 +74,21 @@ //! // Create a daemon //! let mdns = ServiceDaemon::new().expect("Failed to create daemon"); //! +//! // Recommended: Setup a monitor connection to receive events, especially errors from the daemon thread. +//! let receiver = mdns.monitor().expect("Failed to monitor daemon"); +//! std::thread::spawn(move || { +//! while let Ok(event) = receiver.recv() { +//! match event { +//! mdns_sd::DaemonEvent::Error(error) => { +//! eprintln!("Daemon error: {error}"); +//! } +//! _ => {} +//! } +//! } +//! }); +//! //! // Create a service info. //! // ❗ Make sure that the service name: "mdns-sd-my-test" is not longer than the max length limit. (15 characters by default) -//! // You may also want to setup a monitor connection via `mdns.monitor` and log any `DaemonEvent::Error` -//! // You can see how to setup this inside the register example //! let service_type = "_mdns-sd-my-test._udp.local."; //! let instance_name = "my_instance"; //! let ip = "192.168.1.12";