You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found I minor issue with information about domain name lengths in the book and it's reflected int the dns_query.c code from chapter 5.
Specifically, the book mentions:
It also checks that the hostname isn't more than 255
characters long. Hostnames longer than that aren't allowed by the DNS standard, and
checking it now ensures that we don't need to allocate too much memory.
To simplify implementations, the total number of octets that represent a
domain name (i.e., the sum of all label octets and label lengths) is
limited to 255.
That effectively limits readable ASCII domain names to only 253 characters (excluding the optional . at the end).
For example using the dns_query program from the book as such: ./dns_query 123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789a.xyz a
Leads to a response indicating a format error:
QR = 1 response
OPCODE = 0 standard
AA = 0
TC = 0
RD = 1 recursion desired
RCODE = 1 format error
That is a readable domain name of length 254, which is more than the allowed 253 readable characters. Encoded in the DNS binary format, the total number of octets that it's represented by is 256 which is more than the allowed 255.
So as expected trying with a domain name that's only 253 characters long works just fine (notice the second level domain name is changed from 123456789a to 123456789):
./dns_query 123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.xyz a
Hi!
I found I minor issue with information about domain name lengths in the book and it's reflected int the
dns_query.c
code from chapter 5.Specifically, the book mentions:
Which is reflected in the code here:
Hands-On-Network-Programming-with-C/chap05/dns_query.c
Lines 236 to 241 in 54be3ed
But the DNS specification mentions:
See https://datatracker.ietf.org/doc/html/rfc1034#section-3.1
That effectively limits readable ASCII domain names to only 253 characters (excluding the optional . at the end).
For example using the
dns_query
program from the book as such:./dns_query 123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789a.xyz a
Leads to a response indicating a format error:
That is a readable domain name of length 254, which is more than the allowed 253 readable characters. Encoded in the DNS binary format, the total number of octets that it's represented by is 256 which is more than the allowed 255.
So as expected trying with a domain name that's only 253 characters long works just fine (notice the second level domain name is changed from
123456789a
to123456789
):./dns_query 123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.xyz a
Reference to a practical explanation: https://devblogs.microsoft.com/oldnewthing/?p=7873
P.S.: I'm not a complete newbie in network programming but I still found your book useful, and I quite like it as a reference material.
The text was updated successfully, but these errors were encountered: