Simple mDNS responder

Modified version of the IP stack with an extra 'mDNS' rendezvous or zeroconf serivce added can be found at http://mbed.org/users/dirkx/programs/Bonjour.

The main purpose of this is to make it easier to find & access your device - as it now self announces and there is no need to hardcode, or use serial, to figure out the IP address.

Typical use is something like:

EthernetNetIf eth;

HTTPServer svr; // some sample TCP or UDP service

mDNSResponder mdns;

  int main() {

     // get internet

     EthernetErr ethErr = eth.setup();

    ... etc ..

    // set up some server

    svr.addHandler<SimpleHandler>("/"); //Default handler

    svr.bind(80);

     // Extract the IP address (as we need to advertise this to the world).

    IpAddr ip = eth.getIp();

    printf("mbed IP Address is %d.%d.%d.%d\r\n", ip[0], ip[1], ip[2], ip[3]);

     // Announce ourselves.

    mdns.announce(ip, "_http._tcp", 80, "The Little Server that Could",
"path=/demo");

     while()... enter some run loop

Or as another example: (http://files.dns-sd.org/draft-cheshire-dnsext-dns- sd.txt) and the various RFCs consider something like this:

mdns.announce(ip, "_ssh._tcp", 22, SSH to Serial Gateway", NULL);

Next download and start. And then either use a command line tool or any rendesvours (web) browser and observe:

{{{

pappamoem:tmp dirkx$ dns-sd -B _http._tcp

Browsing for _http._tcp

Timestamp     A/R Flags if Domain                    Service Type
Instance Name

19:34:31.572  Add     3  4 local.                    _http._tcp.
Brother HL-5170DN series (BRN_3A6100_P1_AT)

19:34:31.573  Add     3  4 local.                    _http._tcp.
EyeTV pappamoem

19:34:31.573  Add     2  4 local.                    _http._tcp.
moi

19:35:12.616  Rmv     0  4 local.                    _http._tcp.
moi

19:58:15.924  Add     2  4 local.                    _http._tcp.
May the blood run free

19:59:16.920  Rmv     0  4 local.                    _http._tcp.
May the blood run free

20:09:11.601  Add     2  4 local.                    _http._tcp.
May the blood run free

}}}

As your embed comes on-line and drops off (Rmv) again. Alternatively you'll see them appear in your webbrowser (try Safari):

http://mbed.org/media/uploads/dirkx/bj.png

Selecting it will go to the URL constructed from the 'Path' field prefixed by http: and the FQDN or IP address (depending).

CAVEAT: this code is not production ready. I stripped a lot of the buffer hacking/protection out - and did not port the memory mngt and other routines which made it (threat)safe.


Please log in to post comments.