Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 06 · From Scratch · DNS Server · with code: Go · about 13 min to read

Play it as a journeyTutor comes with a plan

DNS 01 and 02: The UDP Socket and the Header

DNS Wire Format
DNS Wire Format · Open board

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.

Lesson 39 of 117 in From Scratch

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • 28 August 1980: a few pages for the protocol DNS rides on
  • Stage 1: a socket that hands you whole packets
  • The header: 12 bytes, six fields
  • The flags: 16 bits, each one a yes or a no
  • Stage 2: read the header, answer with only a header
  • Dropping what you should not answer

Terms it explains: byte, datagram, socket, ID, flags, QDCOUNT, ANCOUNT, NSCOUNT, ARCOUNT, QR, OPCODE, AA, TC, RD, RA, RCODE, Packing, Mistakes this stage invites.

Review From Scratch