Every DNS message begins with a fixed 12-byte header - six 16-bit fields in a row. Today you define the header struct and encode it to those exact 12 bytes, leaving the flag bits (a field of their own) as zero for now.
Encode a header struct to its exact 12 bytes with the flags word left zero.
Every DNS message - query or response - starts with a 12-byte header made of six 16-bit fields laid out in a fixed order: the ID (a number the client picks so it can match a reply to its question), a flags word (sixteen packed control bits we will unpack next), and four section counts - QDCOUNT, ANCOUNT, NSCOUNT, ARCOUNT - saying how many entries follow in the question, answer, authority, and additional sections.
Today you only need to lay those six fields down in order using the big-endian
helper from lesson 1. Leave the flags word as 0 for now; a query with one
question and nothing else has QDCOUNT 1 and the rest 0, which is exactly the
header you encode here. Getting the field order and the fixed 12-byte width right
is the point.
type Header struct {ID uint16Flags uint16 // packed bits - stays 0 todayQDCOUNT, ANCOUNT, NSCOUNT, ARCOUNT uint16}func (h Header) Encode() []byte {// append putUint16 of each field, in order}