DNS 01 and 02: The UDP Socket and the Header

A real dig example.com, byte by byte. Its first section, the 12-byte header with every flag boxed, is the thing this lesson builds a parser for.
Before you start. Build Your Own DNS Server set out the build: a DNS server answers one question packet with one answer packet, over UDP, and every packet starts with a 12-byte header. This lesson covers the first two stages, because each is small: 01-udp opens the socket and proves bytes arrive, and 02-header reads the 12 bytes and answers with a header alone. A byte is a number from 0 to 255; a packet is a run of them, shown below in hexadecimal, so d0 is 208.