DwmDns Class Library


This library contains C++ classes for DNS message transmission and reception and a simple Resolver class. While it requires libDwm, it is essentially a standalone DNS implementation for DNS client applications.

Most common resource record types are supported, and new resource record types are fairly easy to add. The library was motivated by the lack of a decent C++ DNS library with liberal licensing.

Most applications will just use members of the Dwm::Dns::Resolver class to perform DNS lookups, and members of the associated resource record data class to retrieve usable data from the returned Dwm::Dns::ResourceRecord objects. All resource record data classes derive from Dwm::Dns::RRData.

More advanced usage is possible via the Dwm::Dns::NameServer and Dwm::Dns::Message classes.

The library contains rudimentary support for EDNS, and the library supports DNSSEC record types. The list of currently supported resource record types:

Mnemonic Resource Record Type Reference Data class
A1 RFC 1035 Dwm::Dns::RRDataA
NS2 RFC 1035 Dwm::Dns::RRDataNS
CNAME5 RFC 1035 Dwm::Dns::RRDataCNAME
SOA6 RFC 1035 Dwm::Dns::RRDataSOA
MB7 RFC 1035 Dwm::Dns::RRDataMB
MG8 RFC 1035 Dwm::Dns::RRDataMG
MR9 RFC 1035 Dwm::Dns::RRDataMR
PTR12 RFC 1035 Dwm::Dns::RRDataPTR
HINFO13 RFC 1035 Dwm::Dns::RRDataHINFO
MINFO14 RFC 1035 Dwm::Dns::RRDataMINFO
MX15 RFC 1035 Dwm::Dns::RRDataMX
TXT16 RFC 1035 Dwm::Dns::RRDataTXT
RP17 RFC 1183 Dwm::Dns::RRDataRP
KEY25 RFC 4034 Dwm::Dns::RRDataKEY
AAAA28 RFC 3596 Dwm::Dns::RRDataAAAA
LOC29 RFC 1876 Dwm::Dns::RRDataLOC
SRV33 RFC 2782 Dwm::Dns::RRDataSRV
CERT37 RFC 4398 Dwm::Dns::RRDataCERT
DS43 RFC 4034 Dwm::Dns::RRDataDS
SSHFP44 RFC 4255 Dwm::Dns::RRDataSSHFP
RRSIG46 RFC 4034 Dwm::Dns::RRDataRRSIG
NSEC47 RFC 4034 Dwm::Dns::RRDataNSEC
DNSKEY48 RFC 4034 Dwm::Dns::RRDataDNSKEY
DHCID49 RFC 4071 Dwm::Dns::RRDataDHCID
NSEC350 RFC 5155 Dwm::Dns::RRDataNSEC3
TLSA52 RFC 6698 Dwm::Dns::RRDataTLSA
SMIMEA53 RFC 8162 Dwm::Dns::RRDataSMIMEA
CDS59 RFC 7344 Dwm::Dns::RRDataDS
URI256 RFC 7553 Dwm::Dns::RRDataURI
CAA257 RFC 6844 Dwm::Dns::RRDataCAA


libDwm is needed to compile the library.

We need an implementation of variant for resource record data. Depending on your installed C++ library and compiler, you may have it (it's part of the C++17 standard). The configure script will check if you have it, and fall back to using mpark::variant from Michael Park if the standard version is not found. This fallback is included in the mpark_variant header file I include with the library source. Note that the fallback appears to fill this requirement for older compilers such as g++ 6.3.0, clang on macOS Sierra, etc. In other words, you don't need full C++17 support.


Some of the library code dates back to the year 2000 when we didn't have widespread resolver support for various types of records newer than those in RFC 1035. I've since significantly refactored the code twice, in 2016 and 2017/2018. Some functionality was lost in the refactoring, which will likely return when I find time to work on it. And there are currently a few nits to fix, like the TCP fallback in the Dwm::Dns::Resolver class not set to always be used when the TC (truncated) bit is set in the UDP response from a name server. But as a first release, I think the library is definitely in a usable state for many C++ applications that have needs beyond what's possible with getaddrinfo() and getnameinfo(). Especially those applications that want a C++ API.