ESP8266 Developer Zone The Official ESP8266 Forum 2015-12-02T20:00:27+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=1438 2015-12-02T20:00:27+08:00 2015-12-02T20:00:27+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1438&p=4868#p4868 <![CDATA[Re: mDNS - wrong query response]]>
Strolch wrote:
are there any plans to extend the mDNS by a query for <hostname>.local?


1+

Statistics: Posted by rudi — Wed Dec 02, 2015 8:00 pm


]]>
2015-12-02T19:07:08+08:00 2015-12-02T19:07:08+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1438&p=4867#p4867 <![CDATA[Re: mDNS - wrong query response]]> Statistics: Posted by Strolch — Wed Dec 02, 2015 7:07 pm


]]>
2015-11-27T14:37:25+08:00 2015-11-27T14:37:25+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1438&p=4793#p4793 <![CDATA[Re: mDNS - wrong query response]]> The doc is pretty diffuse... but the source code (lwip template) is clear:

Code:

                if (i < DNS_TABLE_SIZE) {

                        nquestions = htons(hdr->numquestions);
                        //nanswers   = htons(hdr->numanswers);
                        /* if we have a question send an answer if necessary */
                        if (nquestions > 0) {
                                /* MDNS_DS_DOES_NAME_CHECK */
                                /* Check if the name in the "question" part match with the name of the MDNS DS service. */
                                if (mdns_compare_name((unsigned char *) DNS_SD_SERVICE,
                                                (unsigned char *) mdns_payload + SIZEOF_DNS_HDR) == 0) {
                                        /* respond with the puck service*/
                                        mdns_answer(MDNS_SD_ANSWER, PUCK_SERVICE, 0);
                                } else if (mdns_compare_name((unsigned char *) PUCK_SERVICE,
                                                (unsigned char *) mdns_payload + SIZEOF_DNS_HDR) == 0) {
                                        /* respond with the puck service*/
                                        mdns_send_service(info, 0);
                                } else
                                        goto memerr2;
                        }
                }

So, the mDNS resolver will only answer queries about "<servername>._tcp.local" and "_services._dns-sd._udp.local", but never <hostname>.local.
It's an fortunate coincidence it it works for <hostname>.local - because your client simply has the last response to <servername>._tcp.local in it's cache - but will forget about after 5min...

Statistics: Posted by Strolch — Fri Nov 27, 2015 2:37 pm


]]>
2015-11-27T10:59:28+08:00 2015-11-27T10:59:28+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1438&p=4791#p4791 <![CDATA[Re: mDNS - wrong query response]]>
Please do not set the mdns_info.server_name to be a protocol name.
You could set mdns_info.server_name = "esp8266"; instead of mdns_info.server_name = "http";

Thanks for your interest in ESP8266 !

Statistics: Posted by ESP_Faye — Fri Nov 27, 2015 10:59 am


]]>
2015-11-26T21:26:46+08:00 2015-11-26T21:26:46+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1438&p=4786#p4786 <![CDATA[Re: mDNS - wrong query response]]> But according to RFC, the hostname can be UTF8 (sure, using a . within hostnames wouldn't be wise...)

Statistics: Posted by Strolch — Thu Nov 26, 2015 9:26 pm


]]>
2015-11-26T20:02:06+08:00 2015-11-26T20:02:06+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1438&p=4784#p4784 <![CDATA[Re: mDNS - wrong query response]]>
What is your "flashConfig.hostname" ?

The "mdns_info.host_name" can not contain special characters, for example, can not contain "."

Statistics: Posted by ESP_Faye — Thu Nov 26, 2015 8:02 pm


]]>
2015-11-26T17:44:54+08:00 2015-11-26T17:44:54+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1438&p=4780#p4780 <![CDATA[mDNS - wrong query response]]> In addition, it fails to properly respond for <hostname>.local queries.

Code (from tve):

Code:

static bool mdns_started = false;
static struct mdns_info mdns_info;

static ICACHE_FLASH_ATTR
void wifiStartMDNS(struct ip_addr ip) {
  if (!mdns_started) {
    os_memset(&mdns_info, 0, sizeof(struct mdns_info));
    mdns_info.host_name = flashConfig.hostname;
    mdns_info.server_name = "http"; // service name
    mdns_info.server_port = 80;     // service port
    mdns_info.ipAddr = ip.addr;
    espconn_mdns_init(&mdns_info);
    mdns_started = true;
  }
}


wifiStartMDNS is called after the Wifi connection is stable, ESP is running in STATION mode.
Wireshark show the following advertisment:

Code:

No.     Time                          Source                Destination           Protocol Length Info
 107234 2015-11-26 09:55:20.922948000 192.168.254.82        224.0.0.251           MDNS     219    Standard query response 0x0000  PTR ems-link02._http._tcp.local TXT, cache flush SRV, cache flush 0 0 80 ems-link02.local A, cache flush 192.168.254.82

Frame 107234: 219 bytes on wire (1752 bits), 219 bytes captured (1752 bits) on interface 0
    Interface id: 0
    Encapsulation type: Linux cooked-mode capture (25)
    Arrival Time: Nov 26, 2015 09:55:20.922948000 CET
    [Time shift for this packet: 0.000000000 seconds]
    Epoch Time: 1448528120.922948000 seconds
    [Time delta from previous captured frame: 0.045418000 seconds]
    [Time delta from previous displayed frame: 0.045418000 seconds]
    [Time since reference or first frame: 2327.739204000 seconds]
    Frame Number: 107234
    Frame Length: 219 bytes (1752 bits)
    Capture Length: 219 bytes (1752 bits)
    [Frame is marked: False]
    [Frame is ignored: False]
    [Protocols in frame: sll:ip:udp:dns]
    [Coloring Rule Name: ems-link02]
    [Coloring Rule String: ip.addr==192.168.254.82]
Linux cooked capture
    Packet type: Multicast (2)
    Link-layer address type: 1
    Link-layer address length: 6
    Source: Espressi_f3:bf:0f (18:fe:34:f3:bf:0f)
    Protocol: IP (0x0800)
Internet Protocol Version 4, Src: 192.168.254.82 (192.168.254.82), Dst: 224.0.0.251 (224.0.0.251)
    Version: 4
    Header length: 20 bytes
    Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00: Not-ECT (Not ECN-Capable Transport))
        0000 00.. = Differentiated Services Codepoint: Default (0x00)
        .... ..00 = Explicit Congestion Notification: Not-ECT (Not ECN-Capable Transport) (0x00)
    Total Length: 203
    Identification: 0x0012 (18)
    Flags: 0x00
        0... .... = Reserved bit: Not set
        .0.. .... = Don't fragment: Not set
        ..0. .... = More fragments: Not set
    Fragment offset: 0
    Time to live: 255
    Protocol: UDP (17)
    Header checksum: 0x1b19 [validation disabled]
        [Good: False]
        [Bad: False]
    Source: 192.168.254.82 (192.168.254.82)
    Destination: 224.0.0.251 (224.0.0.251)
    [Source GeoIP: Unknown]
    [Destination GeoIP: Unknown]
User Datagram Protocol, Src Port: mdns (5353), Dst Port: mdns (5353)
    Source port: mdns (5353)
    Destination port: mdns (5353)
    Length: 183
    Checksum: 0x65b5 [validation disabled]
        [Good Checksum: False]
        [Bad Checksum: False]
Domain Name System (response)
    Transaction ID: 0x0000
    Flags: 0x8400 Standard query response, No error
        1... .... .... .... = Response: Message is a response
        .000 0... .... .... = Opcode: Standard query (0)
        .... .1.. .... .... = Authoritative: Server is an authority for domain
        .... ..0. .... .... = Truncated: Message is not truncated
        .... ...0 .... .... = Recursion desired: Don't do query recursively
        .... .... 0... .... = Recursion available: Server can't do recursive queries
        .... .... .0.. .... = Z: reserved (0)
        .... .... ..0. .... = Answer authenticated: Answer/authority portion was not authenticated by the server
        .... .... ...0 .... = Non-authenticated data: Unacceptable
        .... .... .... 0000 = Reply code: No error (0)
    Questions: 0
    Answer RRs: 4
    Authority RRs: 0
    Additional RRs: 0
    Answers
        _http._tcp.local: type PTR, class IN, ems-link02._http._tcp.local
            Name: _http._tcp.local
            Type: PTR (Domain name pointer)
            .000 0000 0000 0001 = Class: IN (0x0001)
            0... .... .... .... = Cache flush: False
            Time to live: 5 minutes
            Data length: 13
            Domain Name: ems-link02._http._tcp.local
        ems-link02._http._tcp.local: type TXT, class IN, cache flush
            Name: ems-link02._http._tcp.local
            Type: TXT (Text strings)
            .000 0000 0000 0001 = Class: IN (0x0001)
            1... .... .... .... = Cache flush: True
            Time to live: 5 minutes
            Data length: 19
            TXT Length: 18
            TXT: vendor = Espressif
        ems-link02._http._tcp.local: type SRV, class IN, cache flush, priority 0, weight 0, port 80, target ems-link02.local
            Service: ems-link02
            Protocol: _http
            Name: _tcp.local
            Type: SRV (Service location)
            .000 0000 0000 0001 = Class: IN (0x0001)
            1... .... .... .... = Cache flush: True
            Time to live: 5 minutes
            Data length: 24
            Priority: 0
            Weight: 0
            Port: 80
            Target: ems-link02.local
        ems-link02.local: type A, class IN, cache flush, addr 192.168.254.82
            Name: ems-link02.local
            Type: A (Host address)
            .000 0000 0000 0001 = Class: IN (0x0001)
            1... .... .... .... = Cache flush: True
            Time to live: 5 minutes
            Data length: 4
            Addr: 192.168.254.82 (192.168.254.82)

Imho, the response has multiple errors:
a) _http._tcp.local (the service_name) is an ambiguous RR, because it's missing the hostname
b) the PTR doesn't refer to an resolvable RR (neither PTR nor A record for ems-link02._http._tcp.local)
c) the PTR should refer to ems-link02.local

When trying to query for "ems-link02.local" the device doesn't respond at all. Instead, when querying for "_http._tcp.local" it responds with the wrong query result. So it looks like the query is only compared against the (wrong) PTR record, but not against the A record.

As sidenote, it would be really nice to have some additional mDNS API to add a service name or remove a service name.

Statistics: Posted by Strolch — Thu Nov 26, 2015 5:44 pm


]]>