Skip to content

Commit

Permalink
Fix esp8266#2015 ESP8266mDNS doesn't accept queryService responses fr…
Browse files Browse the repository at this point in the history
…om avahi-daemon (esp8266#2023)

Ignore unknown records (AAAA) in the query response; this way we can extract
the IPv4 address and connect to the server.
  • Loading branch information
unaiur authored and igrr committed Jun 1, 2016
1 parent d60d744 commit 30720ce
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions libraries/ESP8266mDNS/ESP8266mDNS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,8 @@ void MDNSResponder::_parsePacket(){
}

int numAnswers = packetHeader[3];
// 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.
if (numAnswers != 4) {
// 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.
if (numAnswers < 4) {
#ifdef MDNS_DEBUG_RX
Serial.println("Expected a packet with 4 answers, returning");
#endif
Expand Down Expand Up @@ -550,7 +550,7 @@ void MDNSResponder::_parsePacket(){
#endif
}

if (answerType == MDNS_TYPE_TXT) {
else if (answerType == MDNS_TYPE_TXT) {
partsCollected |= 0x02;
_conn_readS(hostName, answerRdlength); // Read rdata
#ifdef MDNS_DEBUG_RX
Expand All @@ -561,7 +561,7 @@ void MDNSResponder::_parsePacket(){
#endif
}

if (answerType == MDNS_TYPE_SRV) {
else if (answerType == MDNS_TYPE_SRV) {
partsCollected |= 0x04;
uint16_t answerPrio = _conn_read16(); // Read priority
uint16_t answerWeight = _conn_read16(); // Read weight
Expand Down Expand Up @@ -589,12 +589,19 @@ void MDNSResponder::_parsePacket(){
}
}

if (answerType == MDNS_TYPE_A) {
else if (answerType == MDNS_TYPE_A) {
partsCollected |= 0x08;
for (int i = 0; i < 4; i++) {
answerIp[i] = _conn_read8();
}
}
else {
#ifdef MDNS_DEBUG_RX
Serial.printf("Ignoring unsupported type %d\n", tmp8);
#endif
for (int n = 0; n < answerRdlength; n++)
(void)_conn_read8();
}

if ((partsCollected == 0x0F) && serviceMatch) {
#ifdef MDNS_DEBUG_RX
Expand Down

0 comments on commit 30720ce

Please sign in to comment.