Preliminary note
Yes, I am aware of the existence of DNS libraries and easy-to-use DNS servers. I am doing this purely for academic purposes, and to get a grasp of how DNS queries work.
The question
I was looking at RFC 1035 to get an idea of how DNS messages work. I think I more or less understood everything in that memo. There is one thing that I can't interpret autonomously, however. If you look at Section 4.1.3, here is how the resource record format is described:
1 1 1 1 1 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| |
/ /
/ NAME /
| |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| TYPE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| CLASS |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| TTL |
| |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| RDLENGTH |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
/ RDATA /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
In this scheme, NAME
ends at the end of a two-bytes block. Does this mean that its length in bytes should always be a multiple of two? The format for names is described earlier in the RFC as a sequence of labels, terminated by a zero-length label. This means that, depending on the name, its length can arbitrarily be even or odd. So does NAME
need padding to an even number of bytes? And if so, how should I pad?
I would have ignored the issue and assumed that no padding is required, if it wasn't that in Section 4.1.1 it specifies that QNAME
does not need padding. Since they didn't specify the same for NAME
in the answer RRs, I was wondering if I should assume that there is some difference.
There is no padding. If you have doubt, capture a query about the root zone (the name of which is a single NULL octet, so an odd length) from a root server (they can be trusted to get the protocol right as it is used in the real world) and look at it.