A DNS resolver
Stage 3 of 8v2 · 54742247

Response validation

Validate the identifier, QR bit, response code, and truncation before reading sections.

Response validation

Validate the identifier, QR bit, response code, and truncation before reading sections. Keep the capabilities from earlier stages working.

Observable contract

The harness uses JSON and represents DNS packets as lowercase hexadecimal. Network exchanges are modelled with responses supplied in the request so assessment stays deterministic.

{ "op": "decode-header", "hex": "123481800001000100000000" }

must produce exactly:

{
  "id": 4660,
  "response": true,
  "truncated": false,
  "rcode": 0,
  "counts": { "question": 1, "answer": 1, "authority": 0, "additional": 0 }
}

Output is compact JSON followed by a newline. Invalid input leaves stdout empty, writes a diagnostic containing error to stderr, and exits non-zero.

Implementation

Keep encoding, validation, and traversal separate. Check every length before advancing the cursor, interpret integers in network byte order, and bound all pointer or reference following. Fixtures replace transport only: the logic must later be reusable with real UDP.

Also test truncated packets, overlong labels, out-of-range offsets, and cycles. Do not use the system DNS resolver for the mechanism taught in this stage.

Acceptance criteria

  • The example matches byte for byte.
  • Malformed data fails in a controlled way.
  • Record and result ordering is deterministic.