go-ruby-resolv

Ruby's Resolv DNS primitives in pure Go — wire format, names, records, addresses, hosts; MRI byte-exact, no cgo.

pure Go · zero cgo MRI byte-exact DNS wire format Message encode/decode Name + compression A · AAAA · MX · SOA · SRV … IPv4 · IPv6 Hosts no networking 100% coverage 6 arches
Documentation GitHub
Documentation (MkDocs Material + mike) License: BSD-3-Clause Go 1.26.4+ Coverage 100%

go-ruby-resolv is a pure-Go (no cgo) reimplementation of the deterministic, pure-compute core of Ruby's Resolv library — the DNS wire format, domain names, resource records, address parsing and /etc/hosts parsing of MRI, without any Ruby runtime. It encodes and decodes DNS messages byte-for-byte like Resolv::DNS::Message#encode / .decode, parses Resolv::IPv4 / IPv6 addresses with MRI's exact :: compression, builds Resolv::DNS::Names with length-prefixed labels and 0xC0 compression pointers, and reproduces Resolv::Hosts tables. The actual resolution — networking, file I/O — is the host's job; this library is pure compute. It was extracted from rbgo's internals into a reusable standalone library and bound by rbgo as a native module — differential-tested against MRI, 100% coverage, CI green across 6 arches and 3 OSes.

Resolv::DNS::Message ready

Full header (ID, QR/Opcode/AA/TC/RD/RA/RCODE), the question section, and the answer / authority / additional sections. Encode and Decode round-trip byte-for-byte, including the truncation-bit short-circuit MRI applies on decode.

Resolv::DNS::Name ready

Dotted-name parse / print, the absolute (trailing-dot) flag, case-insensitive Equal and SubdomainOf, and wire encoding with RFC 1035 length-prefixed labels and case-insensitive 0xC0 compression pointers (with backward-pointer and 255-octet guards on decode).

Resource records ready

A, AAAA, CNAME, NS, PTR, MX, TXT, SOA, SRV (target encoded uncompressed, per MRI), HINFO, plus a Generic fallback that round-trips any other TYPE/CLASS opaquely.

Resolv::IPv4 / IPv6 ready

Create parse with the exact MRI Regex / Regex256 acceptance set, canonical String rendering (IPv6 uses MRI’s first-run :: compression), the raw Addr bytes, Equal, and the exported IPv4Regex / IPv6Regex constants.

Resolv::Hosts ready

Parse /etc/hosts-format text into name↔address maps and query them with GetAddress / GetAddresses / GetName / GetNames, reproducing MRI’s comment stripping, whitespace split, and reversed per-name address ordering.

Differential oracle & coverage ready

Messages, names, addresses and hosts tables built here and compared byte-for-byte (base64-framed) against the system ruby; 100% coverage, gofmt + go vet clean, green across all six 64-bit Go arches and three OSes.

A faithful, pure-Go port of Ruby's Resolv, cgo disabled, so it cross-compiles and embeds anywhere. Validated differentially against the system ruby binary — output compared byte-for-byte. It is a standalone, reusable module extracted from rbgo's internals, and a backend for the sibling org github.com/go-embedded-ruby.