This is again related to my Nanode (Arduino lookalike) programming, it's more of a "why on earth is it like this" sort of question than needing to know how it works.
The Nanode/Arduino sits waiting for things to do which are sent as requests to its ethernet interface. It also handles DHCP, DNS, ARP and other requests in the same loop.
When it gets a DNS request it checks a few things and then does the following:-
// // // Check if we have a valid query for us, compare name in DNS request with our name // p=(uint8_t *)settings.Name; // set pointer to our name stored at startup if (valid) // valid set by earlier checks { for (i = NBNS_NAME+1; i < NBNS_NAME+1+32; i += 2) { c = ((buf[i] - 0x41) << 4) + (buf[i+1] - 0x41);
if (*p) { if (*p!=c) { valid=0; } p++; } else { if ((c != 0) && (c != 0x20)) { valid=0; } } } }
The comment at the top is mine, I *think* that's what it's doing!
However I really don't understand why it's doing that strange shifting and subtracting 0x41 (yes, I know it's 'A'). It's as if the name coming in with the DNS query is two bytes per character with a strange encoding as well. I can't see anywhere else in the code where characters are spread over two bytes, and the SPI interface seems to transfer 8 bit bytes all the time to/from the ethernet hardware.
I also don't understand why it's comparing only 16 characters (is it just an arbitrary local limit) and/or why the name it's receiving in the DNS request is just the hostname, not a fully qualified name.
It doesn't work for lower-case characters either, the name defined for the Nanode/Arduino has to be upper case for it to respond to DNS requests.
If valid is still non-zero after this it sends its IP address back to the DNS requester.
Have I missed something obvious or is this really wierd? Any/all ideas very welcome.