Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDNS: fix legacy unicast responses #6613

Merged
merged 2 commits into from
Oct 7, 2019

Conversation

mcspr
Copy link
Collaborator

@mcspr mcspr commented Oct 7, 2019

When trying to resolve mdns hostname using lwip built-in resolver (WiFi.hostByName("something.local")), LeaMDNS responder does not construct a response that lwip expects. While it does preserve the request ID here:

DEBUG_EX_RX(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _parseQuery: Legacy query from local host %s!\n"), IPAddress(m_pUDPContext->getRemoteAddress()).toString().c_str()););
sendParameter.m_u16ID = p_MsgHeader.m_u16ID;

This ID is never set when preparing the message:

[MDNSResponder] _parseQuery: Legacy query from local host 10.0.0.22, id 30!
...
[MDNSResponder] _prepareMDNSMessage: ID:0 QR:1 OP:0 AA:1 TC:0 RD:0 RA:0 R:0 QD:1 AN:1 NS:0 AR:0
...

(debugging message could be improved though)

@mcspr
Copy link
Collaborator Author

mcspr commented Oct 7, 2019

For posterity's sake, small example with dig failing:

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>

#define HOSTNAME "something"

#ifndef USE_SETTINGS
#define WIFI_SSID "SSID"
#define WIFI_PASSWORD "PASSWORD"
#else
#include "settings.h"
#endif

void setup() {

    Serial.begin(115200);
    Serial.println();
    Serial.println();

    delay(1000);

    Serial.printf("> MDNS test\n");
    Serial.printf("> hostname=%s ssid=%s password=%s\n",
        HOSTNAME, WIFI_SSID, WIFI_PASSWORD
    );

    WiFi.persistent(false);
    WiFi.mode(WIFI_STA);
    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }

    Serial.println();
    Serial.println("> connected")

    MDNS.begin(HOSTNAME);

}

void loop() {
    MDNS.update();
}
$ dig -p 5353 @224.0.0.251 something.local
;; Warning: ID mismatch: expected ID 12327, got 0

Copy link
Collaborator

@devyte devyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code wise this looks ok

@d-a-v d-a-v merged commit d62fb9f into esp8266:master Oct 7, 2019
@mcspr mcspr deleted the mdns/legacy-query-same-id branch October 7, 2019 17:49
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants