Skip to content

eschmechel/codecrafters-dns-server-cpp

Repository files navigation

DNS Server in C++

A DNS server implementation in C++ that handles recursive resolution, various record types, and packet parsing. Built as a learning project to get deeper into networking and systems programming.

What it does

  • parses DNS packets from raw bytes
  • handles A, AAAA, CNAME, MX, NS, and other common record types
  • performs recursive resolution against root and authoritative servers
  • responds to DNS queries with the appropriate answers This was my way of understanding how DNS actually works under the hood. Reading RFC 1035 and implementing the protocol piece by piece taught me more about networking than any textbook did.

Why C++

I wanted to build something in C++ that wasn't a game or a graphics demo. DNS is a good fit because:

  • packet parsing requires careful memory handling
  • recursive resolution involves a lot of async-style state management
  • it forces you to think about buffers, sockets, and protocol details

What I learned

  • DNS packet structure and wire format
  • how recursive resolvers chase down answers
  • the difference between authoritative and caching servers
  • handling UDP/TCP sockets in a systems language
  • why DNS caching matters and how TTLs work

Build and run

# with cmake
mkdir build && cd build
cmake ..
make
./dns_server
# or use the provided script
./your_program.sh

The server binds to port 53 and responds to queries.

What's here

src/
  main.cpp       - entry point and server loop
  dns/           - packet parsing and record types
  resolver/      - recursive resolution logic
  cache/         - basic caching implementation

Limitations

This is a learning project, not production software. It doesn't handle:

  • DNSSEC validation
  • zone transfers
  • high-performance concurrency
  • complex record types But it does answer basic queries and demonstrates the core DNS concepts.

About

C++ DNS server implementing recursive resolution and packet parsing. Built to understand networking and systems programming.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors