dnsbase
Copyright(c) Viktor Dukhovni 2026
LicenseBSD-3-Clause
Maintainerietf-dane@dukhovni.org
Stabilityunstable
Safe HaskellNone
LanguageGHC2024

Net.DNSBase.Message

Description

A DNSMessage is the full DNS-protocol packet (RFC 1035 section 4.1): a 16-bit query identifier, the flag word, and four sections (question, answer, authority, additional) carrying the associated RR lists. The lookup functions return either a whole DNSMessage (via lookupRaw / lookupRawCtl) or just the filtered answer RR list (via lookupAnswers and the per-RR-type lookups).

putMessage and putRequest are the wire-format encoders. Applications building responses use putMessage directly; putRequest is the stub-resolver path used by Net.DNSBase.Internal.Transport.

Synopsis

DNS Message data type

data DNSMessage Source #

DNS query or response header, here consisting of just the query ID and the flags, sans the record counts, which are implicit in the corresponding lists, RFC1035 4.1.1, updated by RFC2535.

The basic DNS header contains the following fields:

                                1  1  1  1  1  1
  0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                      ID                       |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|QR|   Opcode  |AA|TC|RD|RA| Z|AD|CD|   RCODE   |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                    QDCOUNT                    |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                    ANCOUNT                    |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                    NSCOUNT                    |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                    ARCOUNT                    |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

The basic 4-bit RCODE is augmented with 8 bits from the EDNS header, forming a single extended 12-bit RCODE, with the basic RCODE as its least-significant 4 bits. Similarly, the extended 32-bit DNSFlags are a combination of the basic flags above with 16 more flag bits from the EDNS header, with the basic flags in the low 16-bits (with the Opcode and RCODE bits always cleared).

DNS message format for queries and replies, RFC1035 4.1

 +---------------------+
 |        Header       |
 +---------------------+
 |       Question      | the question for the name server
 +---------------------+
 |        Answer       | RRs answering the question
 +---------------------+
 |      Authority      | RRs pointing toward an authority
 +---------------------+
 |      Additional     | RRs holding additional information
 +---------------------+

Constructors

DNSMessage 

Fields

Instances

Instances details
Show DNSMessage Source # 
Instance details

Defined in Net.DNSBase.Internal.Message

Eq DNSMessage Source # 
Instance details

Defined in Net.DNSBase.Internal.Message

type QueryID = Word16 Source #

DNS over UDP uses 16-bit query ids to better correlate questions and answers and to (inadequately) reduce the risk of cache-poisoning through forged response packets. They are still used with TCP to keep the header format the same.

putMessage :: DNSMessage -> SPut s RData Source #

General-purpose wire-form encoder for a DNSMessage. Emits the 12-byte header followed by each section (question, answer, authority, additional) in turn, appending the OPT pseudo-RR to the additional section when dnsMsgEx is present. Use this for responses or any message with non-trivial section contents; for the stub-resolver request path putRequest is more direct.

putRequest :: QueryID -> DNSFlags -> Maybe EDNS -> DnsTriple -> SPut s RData Source #

Stub-resolver fast path for building an outgoing query: emits the DNS header (with the given query ID, request flags, and the four section counts hard-coded for a single question), the single question, and — unless EDNS is disabled — the OPT pseudo-RR carrying the supplied EDNS record. Used by the resolver in Net.DNSBase.Internal.Transport. Fails with EDNSRequired when extended flag bits are set but no EDNS record was supplied.