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 started using the lldb debugger to debug my code, and while resolving some issues on the output, I found out the decompression logic for the question section of the DNS message is not working properly. In this session, I'm going to continue on that journey and try to fix it.
I'm sure it'll 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 Stream Warm Up
00:01:15 intro; stuck on DNS header compression logic
00:01:34 plans quieter debugging session to focus on breakthroughs
00:02:14 reflection on how over-explaining slows actual problem solving
00:02:52 starts new debugging phase
00:13:58 fix found; index counting error in `parseLabel`
00:14:32 identifies missing header offset in compressed pointer references
00:14:40 considers two solutions: full-message buffer vs offset adjustment
00:15:47 settles on offset correction with comment for later refactor
00:16:14 rethinks long-term rewrite toward production-ready DNS server
00:16:27 inspects `main.zig` size calculations to trace earlier error
00:22:05 detects duplicate question parsing output (`abc.*` repeating)
00:23:55 confirms question allocator behaves correctly
00:32:35 discovers wrong message start index in parser
00:32:48 realizes buffer index always started from zero
00:34:20 corrected; buffer alignment restored
00:35:17 reviews unnecessary bytes and offset mismatches
00:35:44 locates error in answer section offset pointing to wrong domain
00:36:18 reconsiders compression after CodeCrafters test expectations
00:37:04 investigates large gap after domain section in answers
00:38:11 fixes spacing issue; validates domain offsets
00:38:16 only compressed value pending fix
00:40:37 tests uncompressed response first
00:44:43 bug found: duplicated content appended twice
00:49:14 error persists in CodeCrafters despite local fixes
00:49:48 decides to consult GPT for analysis
00:51:30 revisits older logic; notes partial regression
00:51:54 explores workaround via helper function
00:53:52 starts writing helper to handle label formatting
01:20:31 helper integrated; refines answer building
01:21:50 sets temporary answer count equal to question count
01:22:00 checks response record order requirements
01:22:22 identifies structural issue in response composition
01:23:02 suspects incorrect label assignment inside answer section
01:23:28 confirms correct name and label mapping
01:24:11 ends session; defers remaining fix to next stream
#zig #lowlevelprogramming #systemprogramming #coding #codinglive