Skip to content

Commit 5e64270

Browse files
author
Soham Kute
committed
mdns: detect goodbye packets per RFC 6762 §11.3
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.
1 parent 8cb6b90 commit 5e64270

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

compat/compat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ enum {
2828
MDNS_NETERR = -2, // network error
2929
MDNS_LKPERR = -3, // lookup error
3030
MDNS_ERROR = -4, // any runtime error that's not originating from the standard library
31+
MDNS_GOODBYE = 1, // goodbye packet received (RFC 6762 §11.3, TTL=0)
3132
};
3233

3334
/*

src/mdns.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,12 @@ mdns_listen_probe_network(const struct mdns_ctx *ctx, const char *const names[],
767767
for (struct rr_entry *entry = entries; entry; entry = entry->next) {
768768
for (unsigned int i = 0; i < nb_names; ++i) {
769769
if (!strrcmp(entry->name, names[i])) {
770-
callback(p_cookie, r, entries);
770+
/* RFC 6762 §11.3: TTL=0 is a goodbye packet */
771+
if (entry->ttl == 0) {
772+
callback(p_cookie, MDNS_GOODBYE, entries);
773+
} else {
774+
callback(p_cookie, r, entries);
775+
}
771776
break;
772777
}
773778
}

0 commit comments

Comments
 (0)