Introduce new mDNS API, add mDNS client example

This commit is contained in:
Sergio R. Caprile committed 2026-03-06 11:27:22 -03:00
1 parent abe19d2367
commit 2a7fa4cb68
11 files changed
+303 -92

No files matched your search

+18 -2
View File
@@ -3,6 +3,13 @@
#include "net.h"
#include "str.h"
#define MG_DNS_RTYPE_A 1
#define MG_DNS_RTYPE_PTR 12
#define MG_DNS_RTYPE_TXT 16
#define MG_DNS_RTYPE_AAAA 28
#define MG_DNS_RTYPE_SRV 33
// Mongoose sends DNS queries that contain only one question:
// either A (IPv4) or AAAA (IPv6) address lookup.
// Therefore, we expect zero or one answer.
@@ -38,18 +45,26 @@ struct mg_dnssd_record {
uint16_t port; // SRV record port
};
// mDNS request
// mDNS request and response data structs passed to event handlers
struct mg_mdns_req {
struct mg_dns_rr *rr;
struct mg_dnssd_record *r;
struct mg_str reqname; // requested name in RR
struct mg_str respname; // actual name in response
struct mg_str respname; // actual name to use in response
struct mg_addr addr;
bool is_listing;
bool is_resp;
bool is_unicast;
};
struct mg_mdns_resp {
struct mg_dns_rr *rr;
// TODO(scaprile )struct mg_str srvcproto; struct mg_str txt; uint16_t port; ?
struct mg_str name;
struct mg_addr addr;
// TODO(scaprile); bool has_A; bool has_PTR; bool has_SRV; bool has_TXT; ?
};
void mg_resolve(struct mg_connection *, const char *url);
void mg_resolve_cancel(struct mg_connection *);
bool mg_dns_parse(const uint8_t *buf, size_t len, struct mg_dns_message *);
@@ -58,3 +73,4 @@ size_t mg_dns_parse_rr(const uint8_t *buf, size_t len, size_t ofs,
struct mg_connection *mg_mdns_listen(struct mg_mgr *mgr, mg_event_handler_t fn,
void *fn_data);
bool mg_mdns_query(struct mg_connection *, const char *, unsigned int);