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.
On Thu, Jul 12, 2012 at 04:14:16PM +0100, Chris Green wrote:
Have I missed something obvious or is this really wierd? Any/all ideas very welcome.
Aahh, I think I *may* have missed something obvious, the NBNS in the names is the clue. It's the NETBIOS NAME SERVICE that this is responding to, not DNS.
So, some of the questions still stand, can anyone explain the odd encoding given that it is a NETBIOS request? ... and is this the code that's being exercised when I send a 'host' command to the device, I suspect not!
On Thu, Jul 12, 2012 at 04:21:01PM +0100, Chris Green wrote:
On Thu, Jul 12, 2012 at 04:14:16PM +0100, Chris Green wrote:
Have I missed something obvious or is this really wierd? Any/all ideas very welcome.
Aahh, I think I *may* have missed something obvious, the NBNS in the names is the clue. It's the NETBIOS NAME SERVICE that this is responding to, not DNS.
So, some of the questions still stand, can anyone explain the odd encoding given that it is a NETBIOS request? ... and is this the code that's being exercised when I send a 'host' command to the device, I suspect not!
... and after much searching I found this:-
Each half-octet of the NetBIOS name is encoded into 1 byte of the 32-byte field. The first half-octet is encoded into the first byte, the second half- octet into the second byte, and so on. Each 4-bit, half-octet of the NetBIOS name is treated as an 8-bit, right-adjusted, zero-filled binary number. This number is added to the value of the ASCII character 'A' (hexadecimal 41). The resulting 8-bit number is stored in the appropriate byte.
Grrr! How to make something which is fundamentally simple much more complicated than necessary, Microsoft at work again! :-)
I'm still confused as to why this bit of code is even necessary on my Nanode/Arduino, will some (old) PCs be upset if they can't do Netbios name requests?