Building a DNS Server from Scratch in Zig! After completing Ziglings, I'm taking on the #codecrafters DNS challenge to push deeper into systems programming. Live and unfiltered.
In the last session, I realized I need to refactor the parser method for the question section to have more context and be able to parse compressed question labels but couldn't add the compressed logic. Here I'm planning to spend another hour on this challenge.
I'm sure it's going to be fun; so CHALLENGE ACCEPTED 💪🏼🤓.
Related Playlists:
• Build to Learn: DNS Server in Zig
• Ziglings: Livecoding
Notes:
✅ Session 1: https://sourcery.zone/articles/2025/0...
✅ Session 2: https://sourcery.zone/articles/2025/0...
✅ Session 3: https://sourcery.zone/articles/2025/0...
✅ Session 4: https://sourcery.zone/articles/2025/0...
✅ Session 5: https://sourcery.zone/articles/2025/0...
✅ Session 6, 7, and 8: https://sourcery.zone/articles/2025/0...
✅ Session 9, and 10: https://sourcery.zone/articles/2025/0...
⭐ Sessions 11 to 17: https://sourcery.zone/articles/2025/1...
Reach out and Chat
Matrix: https://matrix.to/#/#sourcery-zone:matrix.org
Timestamps
00:00:00 Streamp Warm Up
00:02:10 recap; stuck on compressed question label parsing
00:03:03 reimplementing the compressed-label flow from scratch
00:04:14 allocator ownership bug postmortem; client vs callee free
00:05:09 using ArrayList(u8).toOwnedSlice for safe return
00:06:04 drop recursion; procedural pointer jump strategy
00:06:29 introduce final_offset to preserve read cursor
00:07:26 plan to rewrite `parseLabel` while reasoning out loud
00:08:46 function signature; consistent naming pass
00:10:06 loop scaffold; offset bookkeeping set up
00:12:28 detect compression by masking the top two bits
00:14:16 derive 14-bit pointer target from two bytes
00:17:22 manage jumped state; update final_offset correctly
00:18:26 bounds checks on offsets vs buffer len
00:20:14 fix incorrect offset comparison
00:21:02 compute `label_start` and slice label bytes
00:24:30 assemble name with ArrayList(u8)
00:25:47 convert to owned slice via `toOwnedSlice`
00:26:37 ensure pointer jump resumes at correct offset
00:27:22 add dot separators between labels
00:30:00 confirm Zig slice end index is exclusive
00:31:22 skip null terminator when label is compressed
00:33:08 simplify boundary checks and concatenation
00:35:12 hit U3 shift error during bit shifts
00:39:05 review Zig shift typing; cast RHS to width log2
00:42:07 fix shift by explicit casts and masks
00:46:41 root cause found: unintended `u3` type creeping in
00:48:24 resolve panic and index-out-of-bounds
00:51:07 domain print sanity checks
00:52:47 revisit null-byte handling
00:55:30 single-domain test passes
01:00:19 off-by-one in label length fixed
01:01:03 labels parse correctly end-to-end
01:03:13 audit question parsing path in main
01:05:41 wrong offset in compressed question handling
01:07:15 implement two-byte question writer
01:10:49 CodeCrafters validation shows BAD RDATA; investigate
01:13:15 propagate correct offset after `parseLabel`
01:15:43 reproduce final index OOB for follow-up
01:15:58 wrap with next actionable fix queued
#zig #lowlevelprogramming #systemprogramming #coding #codinglive