Skip to content

Commit 30720ce

Browse files
unaiurigrr
authored andcommitted
Fix #2015 ESP8266mDNS doesn't accept queryService responses from avahi-daemon (#2023)
Ignore unknown records (AAAA) in the query response; this way we can extract the IPv4 address and connect to the server.
1 parent d60d744 commit 30720ce

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

libraries/ESP8266mDNS/ESP8266mDNS.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,8 @@ void MDNSResponder::_parsePacket(){
470470
}
471471

472472
int numAnswers = packetHeader[3];
473-
// Assume that the PTR answer always comes first and that it is always accompanied by a TXT, SRV and A answer in the same packet.
474-
if (numAnswers != 4) {
473+
// Assume that the PTR answer always comes first and that it is always accompanied by a TXT, SRV, AAAA (optional) and A answer in the same packet.
474+
if (numAnswers < 4) {
475475
#ifdef MDNS_DEBUG_RX
476476
Serial.println("Expected a packet with 4 answers, returning");
477477
#endif
@@ -550,7 +550,7 @@ void MDNSResponder::_parsePacket(){
550550
#endif
551551
}
552552

553-
if (answerType == MDNS_TYPE_TXT) {
553+
else if (answerType == MDNS_TYPE_TXT) {
554554
partsCollected |= 0x02;
555555
_conn_readS(hostName, answerRdlength); // Read rdata
556556
#ifdef MDNS_DEBUG_RX
@@ -561,7 +561,7 @@ void MDNSResponder::_parsePacket(){
561561
#endif
562562
}
563563

564-
if (answerType == MDNS_TYPE_SRV) {
564+
else if (answerType == MDNS_TYPE_SRV) {
565565
partsCollected |= 0x04;
566566
uint16_t answerPrio = _conn_read16(); // Read priority
567567
uint16_t answerWeight = _conn_read16(); // Read weight
@@ -589,12 +589,19 @@ void MDNSResponder::_parsePacket(){
589589
}
590590
}
591591

592-
if (answerType == MDNS_TYPE_A) {
592+
else if (answerType == MDNS_TYPE_A) {
593593
partsCollected |= 0x08;
594594
for (int i = 0; i < 4; i++) {
595595
answerIp[i] = _conn_read8();
596596
}
597597
}
598+
else {
599+
#ifdef MDNS_DEBUG_RX
600+
Serial.printf("Ignoring unsupported type %d\n", tmp8);
601+
#endif
602+
for (int n = 0; n < answerRdlength; n++)
603+
(void)_conn_read8();
604+
}
598605

599606
if ((partsCollected == 0x0F) && serviceMatch) {
600607
#ifdef MDNS_DEBUG_RX

0 commit comments

Comments
 (0)