Go to the documentation of this file.
32 #define TRACE_LEVEL DNS_SD_TRACE_LEVEL
42 #if (DNS_SD_RESPONDER_SUPPORT == ENABLED)
58 context = service->context;
63 service->timeout = delay;
65 service->retransmitCount = 0;
67 service->state = newState;
70 if(context->stateChangeEvent != NULL)
75 context->stateChangeEvent(service, context->interface, newState);
99 for(i =
n; i > 0; i--)
105 if(service->instanceName[i - 1] !=
')')
111 if(!
osIsdigit(service->instanceName[i - 1]))
117 if(service->instanceName[i] !=
'\0')
120 index =
osAtoi(service->instanceName + i);
128 if(service->instanceName[i - 2] ==
' ' &&
129 service->instanceName[i - 1] ==
'(')
136 service->instanceName[i] =
'\0';
171 context = service->context;
173 interface = context->interface;
188 service->serviceName,
".local",
223 message.dnsHeader->ancount = 0;
253 context = service->context;
255 interface = context->interface;
323 context = service->context;
325 interface = context->interface;
401 context = interface->dnsSdResponderContext;
412 qtype =
ntohs(question->qtype);
435 for(i = 0; i < context->numServices; i++)
438 service = &context->services[i];
441 if(service->instanceName[0] !=
'\0' &&
442 service->serviceName[0] !=
'\0' &&
452 offset,
"",
"_services._dns-sd._udp",
".local", 0))
459 response, service,
ttl);
469 offset,
"", service->serviceName,
".local", 0))
486 service->instanceName, service->serviceName,
".local", 0))
493 service, cacheFlush,
ttl);
504 service, cacheFlush,
ttl);
515 service, cacheFlush,
ttl);
548 context = interface->dnsSdResponderContext;
554 for(i = 0; i < context->numServices; i++)
557 service = &context->services[i];
560 if(service->instanceName[0] !=
'\0' &&
561 service->serviceName[0] !=
'\0')
574 if(record == NULL && j >= 3)
582 else if(record != NULL && j >= 3)
587 service->tieBreakLost =
TRUE;
590 else if(record == NULL && j < 3)
614 service->tieBreakLost =
TRUE;
656 context = interface->dnsSdResponderContext;
662 for(i = 0; i < context->numServices; i++)
665 service = &context->services[i];
668 if(service->instanceName[0] !=
'\0' &&
669 service->serviceName[0] !=
'\0')
673 service->instanceName, service->serviceName,
".local", 0))
691 response, record) != 0)
695 service->conflict =
TRUE;
706 service->conflict =
TRUE;
730 #if (DNS_SD_ADDITIONAL_RECORDS_SUPPORT == ENABLED)
744 context = interface->dnsSdResponderContext;
805 for(j = 0; j < context->numServices; j++)
808 service = &context->services[j];
811 if(service->instanceName[0] !=
'\0' &&
812 service->serviceName[0] !=
'\0')
822 offset,
"", service->serviceName,
".local", 0))
838 offset, service->instanceName, service->serviceName,
851 offset =
n +
ntohs(record->rdlength);
900 (uint8_t *)
message->dnsHeader + offset);
928 record->rdlength =
htons(
n);
964 n =
mdnsEncodeName(service->instanceName, service->serviceName,
".local",
972 n =
mdnsEncodeName(service->instanceName, service->serviceName,
".local",
p);
1009 n =
mdnsEncodeName(service->instanceName, service->serviceName,
".local",
1017 n =
mdnsEncodeName(service->instanceName, service->serviceName,
".local",
1021 record->rdlength =
htons(
n);
1024 message->dnsHeader->ancount++;
1055 mdnsResponderContext = interface->mdnsResponderContext;
1078 offset +=
mdnsEncodeName(service->instanceName, service->serviceName,
1079 ".local", (uint8_t *)
message->dnsHeader + offset);
1093 record->priority =
htons(service->priority);
1094 record->weight =
htons(service->weight);
1095 record->port =
htons(service->port);
1107 n =
mdnsEncodeName(
"", mdnsResponderContext->hostname,
".local", NULL);
1122 message->dnsHeader->ancount++;
1164 n =
mdnsEncodeName(service->instanceName, service->serviceName,
".local",
1172 offset +=
mdnsEncodeName(service->instanceName, service->serviceName,
1173 ".local", (uint8_t *)
message->dnsHeader + offset);
1186 record->rdlength =
htons(service->metadataLen);
1202 osMemcpy(record->rdata, service->metadata, service->metadataLen);
1205 message->length = offset + service->metadataLen;
1207 message->dnsHeader->ancount++;
1246 osMemset(bitmap, 0,
sizeof(bitmap));
1254 for(bitmapLen =
sizeof(bitmap); bitmapLen > 0; bitmapLen--)
1257 if(bitmap[bitmapLen - 1] != 0)
1267 n =
mdnsEncodeName(service->instanceName, service->serviceName,
".local",
1275 offset +=
mdnsEncodeName(service->instanceName, service->serviceName,
1276 ".local", (uint8_t *)
message->dnsHeader + offset);
1305 ".local", record->rdata);
1308 record->rdata[
n++] = 0;
1310 record->rdata[
n++] = bitmapLen;
1313 osMemcpy(record->rdata +
n, bitmap, bitmapLen);
1316 record->rdlength =
htons(
n + bitmapLen);
1319 message->dnsHeader->ancount++;
1321 message->length = offset +
n + bitmapLen;
1373 service->instanceName, service->serviceName,
".local", 0))
1388 if(nextRecord == NULL)
1390 nextRecord = curRecord;
1394 nextRecord = curRecord;
1400 offset =
n +
ntohs(curRecord->rdlength);
1430 mdnsResponderContext = interface->mdnsResponderContext;
1477 else if(
value > service->priority)
1489 if(value < service->
weight)
1493 else if(
value > service->weight)
1505 if(value < service->
port)
1509 else if(
value > service->port)
1518 offset = srvRecord->target - (uint8_t *)
message->dnsHeader;
1522 "", mdnsResponderContext->hostname,
".local", 0);
1582 n =
htons(record->rdlength);
1590 if(n < service->metadataLen)
1602 else if(
n > service->metadataLen)
1605 res =
osMemcmp(record->rdata, service->metadata, service->metadataLen);
#define MdnsResponderContext
error_t dnsSdResponderSendGoodbye(DnsSdResponderService *service)
Send goodbye packet.
@ DNS_RR_CLASS_ANY
Any class.
int_t mdnsCompareName(const DnsHeader *message, size_t length, size_t pos, const char_t *instance, const char_t *service, const char_t *domain, uint_t level)
Compare instance, service and domain names.
#define DNS_SET_NSEC_BITMAP(bitmap, type)
void dnsSdResponderParseAnRecord(NetInterface *interface, const MdnsMessage *response, size_t offset, const DnsResourceRecord *record)
Parse a resource record from the Answer Section.
error_t dnsSdResponderFormatServiceEnumPtrRecord(NetInterface *interface, MdnsMessage *message, const DnsSdResponderService *service, uint32_t ttl)
Format PTR resource record (in response to a meta-query)
error_t dnsSdResponderFormatNsecRecord(NetInterface *interface, MdnsMessage *message, const DnsSdResponderService *service, bool_t cacheFlush, uint32_t ttl)
Format NSEC resource record.
#define DNS_SD_DEFAULT_RR_TTL
bool_t mdnsCheckDuplicateRecord(const MdnsMessage *message, const char_t *instance, const char_t *service, const char_t *domain, uint16_t rtype, const uint8_t *rdata, size_t rdlength)
Check for duplicate resource records.
error_t dnsSdResponderParseQuestion(NetInterface *interface, const MdnsMessage *query, size_t offset, const DnsQuestion *question, MdnsMessage *response)
Parse a question.
size_t dnsParseName(const DnsHeader *message, size_t length, size_t pos, char_t *dest, uint_t level)
Decode a domain name that uses the DNS name encoding.
@ DNS_RR_TYPE_NSEC
NSEC record.
error_t dnsSdResponderSendAnnouncement(DnsSdResponderService *service)
Send announcement packet.
#define osMemcmp(p1, p2, length)
@ DNS_RR_CLASS_IN
Internet.
MdnsState
mDNS responder states
#define MDNS_LEGACY_UNICAST_RR_TTL
@ DNS_RR_TYPE_ANY
A request for all records.
#define osMemcpy(dest, src, length)
#define DNS_GET_QUESTION(message, offset)
#define osSprintf(dest,...)
error_t dnsSdResponderFormatSrvRecord(NetInterface *interface, MdnsMessage *message, const DnsSdResponderService *service, bool_t cacheFlush, uint32_t ttl)
Format SRV resource record.
#define DNS_GET_RESOURCE_RECORD(message, offset)
void dnsSdResponderChangeInstanceName(DnsSdResponderService *service)
Programmatically change the service instance name.
DNS-SD responder (DNS-Based Service Discovery)
error_t dnsSdResponderFormatPtrRecord(NetInterface *interface, MdnsMessage *message, const DnsSdResponderService *service, uint32_t ttl)
Format PTR resource record.
#define DnsSdResponderContext
int_t dnsSdResponderCompareTxtRecord(DnsSdResponderService *service, const MdnsMessage *message, const DnsResourceRecord *record)
Compare TXT resource records.
@ DNS_RR_TYPE_PTR
Domain name pointer.
error_t mdnsCreateMessage(MdnsMessage *message, bool_t queryResponse)
Create an empty mDNS message.
#define DnsSdResponderService
#define DNS_SD_MAX_INSTANCE_NAME_LEN
error_t dnsSdResponderSendProbe(DnsSdResponderService *service)
Send probe packet.
uint32_t systime_t
System time.
int_t mdnsCompareRecord(const MdnsMessage *message1, const DnsResourceRecord *record1, const MdnsMessage *message2, const DnsResourceRecord *record2)
Compare resource records.
void dnsSdResponderParseNsRecords(NetInterface *interface, const MdnsMessage *query, size_t offset)
Parse the Authority Section.
void dnsSdResponderChangeState(DnsSdResponderService *service, MdnsState newState, systime_t delay)
Update FSM state.
void dnsSdResponderGenerateAdditionalRecords(NetInterface *interface, MdnsMessage *response, bool_t legacyUnicast)
Additional record generation.
int_t dnsSdResponderCompareSrvRecord(NetInterface *interface, DnsSdResponderService *service, const MdnsMessage *message, const DnsResourceRecord *record)
Compare SRV resource records.
Helper functions for DNS-SD responder.
void mdnsDeleteMessage(MdnsMessage *message)
release a mDNS message
const UdpHeader * udpHeader
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
@ DNS_RR_TYPE_TXT
Text strings.
#define MDNS_MESSAGE_MAX_SIZE
DnsResourceRecord * dnsSdResponderGetNextTiebreakerRecord(DnsSdResponderService *service, const MdnsMessage *query, size_t offset, DnsResourceRecord *record)
Sort the tiebreaker records in lexicographical order.
@ DNS_RR_TYPE_SRV
Server selection.
error_t dnsSdResponderFormatTxtRecord(NetInterface *interface, MdnsMessage *message, const DnsSdResponderService *service, bool_t cacheFlush, uint32_t ttl)
Format TXT resource record.
#define osMemset(p, value, length)
size_t mdnsEncodeName(const char_t *instance, const char_t *service, const char_t *domain, uint8_t *dest)
Encode instance, service and domain names using the DNS name notation.
error_t mdnsSendMessage(NetInterface *interface, const MdnsMessage *message, const IpAddr *destIpAddr, uint_t destPort)
Send mDNS message.
mDNS responder (Multicast DNS)
#define MDNS_RCLASS_CACHE_FLUSH
systime_t osGetSystemTime(void)
Retrieve system time.