Build to Learn: DNS Server in Zig - Part 16

Опубликовано: 19 Февраль 2026
на канале: Sourcerer
141
5

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.

The progress in the previous session was perfect. I finally managed to refactor some parts of the code, into more reusable components, which improved the debugging experience. However, eventually I faced a nasty memory error. Today I'm going to focus on debugging that error and hopefully wrap up the challenge; hopefully 🤞🏻.
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:24 intro; progress and code cleanup
00:02:04 main bug: buffer offset math
00:02:18 LLDB tips: step in, callers, frames
00:03:06 fix: stop passing full buffer to `parseLabel`
00:03:36 slice vs absolute offsets clarified
00:05:04 make offset relative to slice base
00:06:25 compute `real_slice` and `real_offset`
00:08:00 breakpoint run; verify slice lengths
00:12:03 adjust call sites to pass start/end offsets
00:15:34 endian check; big-endian writes confirmed
00:17:05 mask/shift bytes: 8` and `& 0xFF`
00:21:07 types audit: `u16` class, `u32` TTL, `u16` rdlength
00:24:48 leak not allocator; data corruption suspected
00:27:57 trace bad `answer` init path
00:32:02 stack trace into `Message.parse`
00:37:38 label parse now correct
00:41:26 ttl offset wrong; recalc 4-byte field
00:42:27 `rdata` length off; fix indexing
00:42:57 symptom: `0xAA` poison bytes from overslice
00:48:33 root cause: slicing past `rdlength`
00:50:18 add bound: `offset + len buf.len`
00:53:39 fix arg type to parser
00:55:45 second answer still failing; prints first OK
00:57:16 partial output stable; continue narrowing
00:58:44 note: avoid partial-slice APIs next time
01:01:30 close to full parse; answering still pending
01:12:02 wrap; queue next debugging pass


#zig #lowlevelprogramming #systemprogramming #coding #codinglive