From 5e642702fccf4c8be2cbbff30d828fd2ddb3df1f Mon Sep 17 00:00:00 2001 From: Soham Kute Date: Mon, 23 Feb 2026 01:49:41 +0530 Subject: [PATCH] =?UTF-8?q?mdns:=20detect=20goodbye=20packets=20per=20RFC?= =?UTF-8?q?=206762=20=C2=A711.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Identify mDNS goodbye packets by checking for TTL=0 in answer records. Previously treated as normal announcements; now trigger listen callback with MDNS_GOODBYE so callers can detect service departure. --- compat/compat.h | 1 + src/mdns.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/compat/compat.h b/compat/compat.h index 071e7b8..67164c2 100644 --- a/compat/compat.h +++ b/compat/compat.h @@ -28,6 +28,7 @@ enum { MDNS_NETERR = -2, // network error MDNS_LKPERR = -3, // lookup error MDNS_ERROR = -4, // any runtime error that's not originating from the standard library + MDNS_GOODBYE = 1, // goodbye packet received (RFC 6762 §11.3, TTL=0) }; /* diff --git a/src/mdns.c b/src/mdns.c index 198654c..dfd798e 100644 --- a/src/mdns.c +++ b/src/mdns.c @@ -767,7 +767,12 @@ mdns_listen_probe_network(const struct mdns_ctx *ctx, const char *const names[], for (struct rr_entry *entry = entries; entry; entry = entry->next) { for (unsigned int i = 0; i < nb_names; ++i) { if (!strrcmp(entry->name, names[i])) { - callback(p_cookie, r, entries); + /* RFC 6762 §11.3: TTL=0 is a goodbye packet */ + if (entry->ttl == 0) { + callback(p_cookie, MDNS_GOODBYE, entries); + } else { + callback(p_cookie, r, entries); + } break; } }