o
odinpkg.dev
packages / library / dns_resolver_odin

dns_resolver_odin

9609d14library

Writing my own DNS resolver to learn more about fundamental networking and to get more experience with the Odin programming language

No license · updated 3 weeks ago

DNS Resolver in Odin

This DNS Resolver was project for me to learn more about system level networking and to get more experience in the Odin programming language

Requirements

Build and Run

odin run . -- <domain>

Example Output

odin run . -- google.com
142.250.113.101
142.250.113.139
142.250.113.138
142.250.113.100
142.250.113.102
142.250.113.113

How It Works

You type a domain name. The program builds a binary message following the DNS spec from RFC 1035, a 12 byte header, followed by the domain name encoded as length-prefixed labels, followed by a record type and class. It sends that message over UDP to Google's DNS server at 8.8.8.8:53. The server sends back a response in the same binary format with answer records appended. The program parses those records, skipping past the header and question section, and extracts the last 4 bytes of each answer — which are the raw IPv4 address bytes. It prints those as human-readable IP addresses.