Project 1: DNS Query Tool (UDP Basics)

A command-line tool that sends DNS queries over UDP, parses the binary response, and displays the resolved IP addresses—without using any DNS library.

Quick Reference

Attribute Value
Primary Language C++
Alternative Languages C, Rust, Go
Difficulty Level 1: Beginner
Time Estimate Weekend
Knowledge Area UDP Sockets, DNS Protocol, Binary Parsing
Tooling dig/nslookup replacement
Prerequisites Basic C++ (classes, pointers, arrays), understanding of hexadecimal, familiarity with command line

What You Will Build

A command-line tool that sends DNS queries over UDP, parses the binary response, and displays the resolved IP addresses—without using any DNS library.

Why It Matters

This project builds core skills that appear repeatedly in real-world systems and tooling.

Core Challenges

  • Creating and configuring a UDP socket → maps to socket() and addressing structures
  • Constructing DNS query packets in binary → maps to network byte order (htons/htonl)
  • Parsing variable-length DNS responses → maps to pointer arithmetic and buffer management
  • Handling timeouts for unreliable UDP → maps to setsockopt() and SO_RCVTIMEO

Key Concepts

  • Socket Creation: “The Linux Programming Interface” Chapter 56 - Michael Kerrisk
  • UDP Semantics: “TCP/IP Illustrated, Volume 1” Chapter 11 - W. Richard Stevens
  • DNS Wire Format: RFC 1035 Section 4
  • Network Byte Order: “UNIX Network Programming” Section 3.4 - W. Richard Stevens

Real-World Outcome

$ ./dnsquery google.com
Querying DNS server 8.8.8.8 for google.com (A record)...

Response received (52 bytes):
  Transaction ID: 0xAB12
  Flags: 0x8180 (Response, No Error)
  Questions: 1, Answers: 4

  Answer 1: google.com. 300 IN A 142.250.80.46
  Answer 2: google.com. 300 IN A 142.250.80.47
  Answer 3: google.com. 300 IN A 142.250.80.78
  Answer 4: google.com. 300 IN A 142.250.80.110

$ ./dnsquery -t MX gmail.com
Querying DNS server 8.8.8.8 for gmail.com (MX record)...

  Answer 1: gmail.com. 3600 IN MX 5 gmail-smtp-in.l.google.com.
  Answer 2: gmail.com. 3600 IN MX 10 alt1.gmail-smtp-in.l.google.com.

Implementation Guide

  1. Reproduce the simplest happy-path scenario.
  2. Build the smallest working version of the core feature.
  3. Add input validation and error handling.
  4. Add instrumentation/logging to confirm behavior.
  5. Refactor into clean modules with tests.

Milestones

  • Milestone 1: Minimal working program that runs end-to-end.
  • Milestone 2: Correct outputs for typical inputs.
  • Milestone 3: Robust handling of edge cases.
  • Milestone 4: Clean structure and documented usage.

Validation Checklist

  • Output matches the real-world outcome example
  • Handles invalid inputs safely
  • Provides clear errors and exit codes
  • Repeatable results across runs

References

  • Main guide: LEARN_CPP_NETWORK_PROGRAMMING.md
  • “TCP/IP Illustrated, Volume 1” by W. Richard Stevens