DNS - Domain Name System¶
pcapkit.protocols.application.dns.protocol contains
DNS only, which implements
an extractor for Domain Name System (DNS) messages [RFC 1035], whose header
is:
Octets |
Bits |
Name |
Description |
|---|---|---|---|
0 |
0 |
|
Message Length (over TCP only) |
0 |
0 |
|
Identifier |
2 |
16 |
|
QR, Opcode, AA, TC, RD, RA, Z, AD, CD, RCODE |
4 |
32 |
|
Question Count |
6 |
48 |
|
Answer Count |
8 |
64 |
|
Authority Count |
10 |
80 |
|
Additional Count |
Over TCP, the two-octet length precedes the message, so every offset above moves two octets on (RFC 1035 Section 4.2.2, RFC 7766 Section 8).
How a parse reads a message:
flowchart TD
IN["octets at port 53"] --> GIVEN{"framed= given?"}
GIVEN -->|yes| READ["read as it says"]
GIVEN -->|no| WHOLE{"a whole message that fits<br/>behind a length field?"}
WHOLE -->|no| UNFRAMED["one message, unframed"]
WHOLE -->|yes| PLAIN{"do the sections the header<br/>counts fit the octets?"}
PLAIN -->|no| FRAMED["one message, framed"]
PLAIN -->|yes| EXACT{"does the framed one end<br/>exactly at its length?"}
EXACT -->|no| UNFRAMED
EXACT -->|yes| END{"does the plain one stop<br/>short of the end?"}
END -->|yes| FRAMED
END -->|no| TIE{"a question in the framed one only,<br/>or a further exact framed message?"}
TIE -->|yes| FRAMED
TIE -->|no| UNFRAMED
FRAMED --> NEXT{"a whole framed message after it?"}
NEXT -->|yes| CHAIN["a further DNS layer"]
NEXT -->|no| REST["the rest as Raw"]
Added in version 1.7.0.
- class pcapkit.protocols.application.dns.protocol.DNS(file, length=None, /, *, framed=None, layer=None, protocol=None, context=None)[source]¶
Bases:
Application[DNS,DNS]This class implements Domain Name System.
- Overloads:
file (
IO[bytes] |bytes), length (int|None) =..., /, *, framed (bool|None) =..., layer (str|None) =..., protocol (str|ProtocolBase|Type[ProtocolBase] |None) =..., context (ContextRegistry|ProtocolContext|Mapping[str,ProtocolContext] |Iterable[ProtocolContext] |None) =...*, framed (
bool|None) =..., context (ContextRegistry|ProtocolContext|Mapping[str,ProtocolContext] |Iterable[ProtocolContext] |None) =..., **fields (Any)
A message is parsed whole: the header, the four sections, the RDATA of the types
__rdata__registers and the options of the OPT pseudo-record of EDNS(0) (RFC 6891) that__option__registers. Each domain name records the compression it was read with (Name), so a message rebuilds as captured.Over TCP the two-octet length precedes the message, which
framed=Truereads and writes. A parse not givenframedreads the length where a whole message decodes behind it and the octets read worse as a plain message, as_frames_message()weighs them, much as TLS tries SSLv2 on what its own parser refuses (The SSL Family): the port the transport dispatches on is the same for TCP and UDP. A further whole message after a framed one is dissected as anotherDNSlayer, the previous one’s payload, as TLS records are; a message the segment ends inside is not reassembled and staysRaw.The RDATA each type carries:
RR Type
Data Model
OPT, the whole recordAny other type, and RDATA its decoder cannot read exactly, is kept as raw octets. The EDNS(0) options decoded are
edns-client-subnet(ClientSubnet),COOKIE(Cookie),edns-tcp-keepalive(TCPKeepalive) andExtended DNS Error(ExtendedError); any other is kept as raw octets.Defaults
- __rdata__: DefaultDict[RRType | int, str | tuple[Callable[[RRType, bytes, bytes, int], RData | bytes], Callable[[RRType, Mapping[str, Any], int, dict[tuple[bytes, ...], int] | None], bytes]]]¶
RR type to method mapping, see
_read_dns_record()and_make_dns_record(). Astrvalue names the methods_read_rdata_${name}and_make_rdata_${name}, falling back to_read_rdata_unknown()and_make_rdata_unknown()when the class has no such method; any other value is a(parser, constructor)pair of callables. The OPT pseudo-record is read whole by_read_dns_opt(), outside this map.
- __option__: DefaultDict[Option | int, str | tuple[Callable[[Option, bytes], OptionData | bytes], Callable[[Option, Mapping[str, Any]], bytes]]]¶
EDNS(0) option code to method mapping, see
_read_dns_options()and_make_dns_options(). Astrvalue names the methods_read_opt_${name}and_make_opt_${name}, falling back to_read_opt_unknown()and_make_opt_unknown(); any other value is a(parser, constructor)pair of callables.
Properties
- property length: int¶
Header length of current protocol, i.e. the message with its TCP length field.
- property rcode: RCode | int¶
Response code, extended by the OPT pseudo-record’s upper bits if any (RFC 6891 Section 6.1.3).
Methods
- read(length=None, **kwargs)[source]¶
Read Domain Name System.
Structure of DNS header [RFC 1035]:
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 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
- Parameters:
- Return type:
- Returns:
Parsed packet data.
- Raises:
ProtocolError – If the TCP length field counts fewer octets than the header, or a section entry runs past the message or holds a malformed domain name.
- make(*, id=0, qr=False, opcode=Opcode.Query, aa=False, tc=False, rd=False, ra=False, z=0, ad=False, cd=False, rcode=RCode.NoError, question=(), answer=(), authority=(), additional=(), framed=False, message_length=None, compress=False, trailer=b'', payload=b'', **kwargs)[source]¶
Make (construct) packet data.
The section counts are those of the entries given. A question entry is a mapping of
name,typeandclass, asQuestionis. A record is a mapping ofname,type,class,ttl,rdlengthandrdata, asResourceRecordis, or, for the OPT pseudo-record, of the fields ofOPT.rdatais raw octets, or a mapping of the fields of the type’s data model, as__rdata__registers it. A name is aName, which writes the compression it records, its labels, or its presentation form.- Parameters:
id (
int) – Identifier.qr (
bool) – Whether the message is a response.aa (
bool) – Authoritative answer.tc (
bool) – Truncation.rd (
bool) – Recursion desired.ra (
bool) – Recursion available.z (
int) – Reserved bit.ad (
bool) – Authentic data.cd (
bool) – Checking disabled.rcode (
RCode|int) – Response code, the header’s four bits.authority (
Iterable[Mapping[str,Any]]) – Authority section.additional (
Iterable[Mapping[str,Any]]) – Additional section.framed (
bool) – Whether to write the TCP length field.message_length (
int|None) – TCP length field, written whenever given; the message’s own length otherwise.compress (
bool) – Whether to compress the names given as labels or text against those written before them (RFC 1035 Section 4.1.4), where the type allows it.trailer (
bytes) – Octets of the message past its last record.payload (
bytes|ProtocolBase|Schema) – Payload data, after the message.**kwargs (
Any) – Arbitrary keyword arguments.
- Return type:
- Returns:
Constructed packet data.
- Raises:
ProtocolError – If a field does not fit its width, an enumeration field is a name or a
boolfor a field wider than a bit, a name is malformed, orrdatais a mapping for a type with no constructor.
- classmethod register_option(code, meth)[source]¶
Register an EDNS(0) option parser.
- Parameters:
- Warns:
RegistryWarning– If a different entry is already registered forcode; it is overwritten. Handing back the entry already stored, or one equal to it, is a silent no-op.
- classmethod register_rdata(code, meth)[source]¶
Register an RDATA parser.
- Parameters:
code (
RRType) – RR type.meth (
str|tuple[Callable[[RRType,bytes,bytes,int],RData|bytes],Callable[[RRType,Mapping[str,Any],int,dict[tuple[bytes,...],int] |None],bytes]]) – Name of the_read_rdata_${name}and_make_rdata_${name}methods, or a(parser, constructor)pair of callables; see__rdata__.
- Warns:
RegistryWarning– If a different entry is already registered forcode; it is overwritten. Handing back the entry already stored, or one equal to it, is a silent no-op.
Data Models
- classmethod __index__()[source]¶
Numeral registry index of the protocol.
- Return type:
- Returns:
Numeral registry index of the protocol in IANA service names and port numbers: port 53, the port of
UDP.domainas anint, at whichUDP.__proto__andTCP.__proto__dispatch here (The Registry Index).
- __init__(file=NO_VALUE, length=None, /, *, framed=None, layer=None, protocol=None, context=None, **fields)[source]¶
Parse a protocol instance from its octets, or construct one from its fields.
- Overloads:
file (
IO[bytes] |bytes), length (int|None) =..., /, *, framed (bool|None) =..., layer (str|None) =..., protocol (str|ProtocolBase|Type[ProtocolBase] |None) =..., context (ContextRegistry|ProtocolContext|Mapping[str,ProtocolContext] |Iterable[ProtocolContext] |None) =...→None*, framed (
bool|None) =..., context (ContextRegistry|ProtocolContext|Mapping[str,ProtocolContext] |Iterable[ProtocolContext] |None) =..., **fields (Any) →None
- Parameters:
file (
IO[bytes] |bytes|NoValueType) – Source packet stream; omitted to construct.framed (
bool|None) – Whether the TCP length field precedes the message. WhenNone, it does where_frames_message()finds a whole message behind a length field that reads better than the octets as a plain one, which is how a TCP segment carries one.layer (
str|None) – AsProtocol.__init__.protocol (
str|ProtocolBase|Type[ProtocolBase] |None) – AsProtocol.__init__.context (
ContextRegistry|ProtocolContext|Mapping[str,ProtocolContext] |Iterable[ProtocolContext] |None) – AsProtocol.__init__.**fields (
Any) – AsProtocol.__init__.
Changed in version 1.8.0: Declares
framed, its only parse keyword besides the stops and the context (#2840).
- __post_init__(file=None, length=None, **kwargs)[source]¶
Post initialisation hook.
- Parameters:
framed (
Optional[bool]) – Parsing, whether the TCP length field precedes the message. When not given, it does where_frames_message()finds a whole message behind a length field that reads better than the octets as a plain one, which is how a TCP segment carries one.**kwargs (
Any) – Arbitrary keyword arguments.
- Return type:
See also
self.makefor the construction arguments.
Utilities
- _read_dns_question(message, pos)[source]¶
Read a question section entry.
Structure of a question entry [RFC 1035 Section 4.1.2]:
1 1 1 1 1 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ / QNAME / +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | QTYPE | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | QCLASS | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
- _read_dns_record(message, pos)[source]¶
Read a resource record.
Structure of a resource record [RFC 1035 Section 4.1.3]:
1 1 1 1 1 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ / NAME / +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | TYPE | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | CLASS | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | TTL | | | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | RDLENGTH | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--| / RDATA / +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
The RDATA is read by the parser
__rdata__registers for its type. Its length delimits it, so RDATA its parser rejects with aProtocolErroris kept as raw octets, quietly, as a TLS extension body is.
- _make_dns_record(record, *, offset, table)[source]¶
Make a resource record, or the OPT pseudo-record.
- _read_rdata_unknown(rr_type, data, *, message, offset)[source]¶
Read an RDATA with no decoder registered: its raw octets.
- _read_rdata_a(rr_type, data, *, message, offset)[source]¶
Read an
ARDATA (RFC 1035 Section 3.4.1).
- _read_rdata_ns(rr_type, data, *, message, offset)[source]¶
Read an
NSRDATA (RFC 1035 Section 3.3.11).
- _read_rdata_cname(rr_type, data, *, message, offset)[source]¶
Read a
CNAMERDATA (RFC 1035 Section 3.3.1).
- _read_rdata_soa(rr_type, data, *, message, offset)[source]¶
Read an
SOARDATA (RFC 1035 Section 3.3.13).
- _read_rdata_ptr(rr_type, data, *, message, offset)[source]¶
Read a
PTRRDATA (RFC 1035 Section 3.3.12).
- _read_rdata_mx(rr_type, data, *, message, offset)[source]¶
Read an
MXRDATA (RFC 1035 Section 3.3.9).
- _read_rdata_txt(rr_type, data, *, message, offset)[source]¶
Read a
TXTRDATA (RFC 1035 Section 3.3.14).
- _read_rdata_aaaa(rr_type, data, *, message, offset)[source]¶
Read an
AAAARDATA (RFC 3596 Section 2.2).
- _read_rdata_caa(rr_type, data, *, message, offset)[source]¶
Read a
CAARDATA (RFC 8659 Section 4.1).
- _read_opt_unknown(code, data)[source]¶
Read an EDNS(0) option with no decoder registered: its raw octets.
- _read_opt_client_subnet(code, data)[source]¶
Read an
edns-client-subnetoption (RFC 7871 Section 6).- Parameters:
- Return type:
- Returns:
Parsed OPTION-DATA.
- _read_opt_cookie(code, data)[source]¶
Read a
COOKIEoption (RFC 7873 Section 4).- Parameters:
- Return type:
- Returns:
Parsed OPTION-DATA.
- Raises:
ProtocolError – If
datais neither the 8-octet client cookie nor that and a server cookie of 8 to 32 octets.
- _read_opt_tcp_keepalive(code, data)[source]¶
Read an
edns-tcp-keepaliveoption (RFC 7828 Section 3.1).- Parameters:
- Return type:
- Returns:
Parsed OPTION-DATA.
- Raises:
ProtocolError – If
datais neither empty nor two octets.
- _read_opt_extended_error(code, data)[source]¶
Read an
Extended DNS Erroroption (RFC 8914 Section 2).- Parameters:
- Return type:
- Returns:
Parsed OPTION-DATA.
- _make_rdata_unknown(rr_type, data, *, offset, table)[source]¶
Make an RDATA with no constructor registered.
- Parameters:
- Return type:
- Returns:
Empty RDATA, for no fields.
- Raises:
ProtocolError – If
dataholds a field.
- _make_rdata_soa(rr_type, data, *, offset, table)[source]¶
Make an
SOARDATA.- Parameters:
- Return type:
- Returns:
RDATA octets.
- _make_rdata_txt(rr_type, data, *, offset, table)[source]¶
Make a
TXTRDATA.- Parameters:
- Return type:
- Returns:
RDATA octets.
- Raises:
ProtocolError – If a string is not
bytesof at most 255 octets.
- _make_rdata_srv(rr_type, data, *, offset, table)[source]¶
Make an
SRVRDATA; its target is never compressed (RFC 2782).
- _make_rdata_caa(rr_type, data, *, offset, table)[source]¶
Make a
CAARDATA.- Parameters:
- Return type:
- Returns:
RDATA octets.
- Raises:
ProtocolError – If
tagis notbytesof 1 to 255 octets, orvalueis notbytes.
- _read_dns_name(message, pos, *, limit=None)[source]¶
Read a domain name, following its compression pointers.
- Parameters:
- Return type:
- Returns:
The name, and the offset just past it.
- Raises:
ProtocolError – As
read_name()raises it, or if the name ends pastlimit.
- _read_rdata_name(data, message, offset, *, skip=0)[source]¶
Read the domain name that ends an RDATA.
- _make_dns_name(name, *, offset, table)[source]¶
Make a domain name.
- Parameters:
name (
str| Iterable[bytes] | Mapping[str, Any]) – AName, or itsdictform, written with the compression it records; or its labels, or its presentation form, compressed againsttableif given.offset (
int) – Offset of the name in the message.table (
dict[tuple[bytes,...],int] |None) – Names written so far, when compressing; the suffixes this name writes in full are added to it.
- Return type:
- Returns:
The name’s octets.
- Raises:
ProtocolError – If
nameis none of those, or is malformed.
- _read_dns_opt(name, udp_payload_size, ttl, rdata)[source]¶
Read the OPT pseudo-record of EDNS(0).
Structure of the OPT record’s TTL field [RFC 6891 Section 6.1.3]:
+0 (MSB) +1 (LSB) +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ 0: | EXTENDED-RCODE | VERSION | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ 2: | DO| Z | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
- _read_dns_options(data)[source]¶
Read the options of the OPT pseudo-record.
Structure of an option [RFC 6891 Section 6.1.2]:
+0 (MSB) +1 (LSB) +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ 0: | OPTION-CODE | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ 2: | OPTION-LENGTH | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ 4: | | / OPTION-DATA / / / +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
Each OPTION-DATA is read by the parser
__option__registers for its code, and kept as raw octets where that parser rejects it.- Parameters:
data (
bytes) – The OPT record’s RDATA.- Return type:
- Returns:
The options, in order.
- Raises:
ProtocolError – If an option’s header or data runs past
data.
- _import_next_layer(proto, length=None, *, packet=None)[source]¶
Import next layer extractor: a further whole message, or the rest undissected.
Over TCP, a segment may carry several messages, each behind its length field. So the
-1remainder after a framed message is dissected as this class when_opens_whole_message()finds a whole message opening it, and is otherwise kept asApplication._import_next_layerkeeps it.- Parameters:
- Return type:
- Returns:
Instance of this class for a further message, or as
Application._import_next_layerreturns otherwise.
- _import_next_message(proto, length=None, *, packet=None)[source]¶
Import the further message
_import_next_layer()found.- Parameters:
- Return type:
- Returns:
Instance of this class, or of
Rawwhenbeholder()replaces a message that fails to parse.
Auxiliary Functions¶
- pcapkit.protocols.application.dns.protocol._opens_whole_message(octets)[source]¶
Whether
octetsopen with a whole message behind a TCP length field.
- pcapkit.protocols.application.dns.protocol._sections_end(message)[source]¶
Where the sections the header of
messagecounts end, if they fit in it.
- pcapkit.protocols.application.dns.protocol._frames_message(octets)[source]¶
Whether
octetsare a message behind the TCP length field.- Parameters:
octets (
bytes) – Octets of a DNS layer, withframednot given.- Return type:
- Returns:
Whether a whole message behind a length field opens
octetsand decodes, andoctetsdo not decode as a message, or decode no better. Where both readings decode and the framed message ends exactly at its length, the framed one is taken if the plain one stops short of the end ofoctets; if it reads to the end, the framed one is taken where it counts a question and the plain one none, or where a further framed message follows that ends exactly at its length too. So a plain message whose ID equals the octets after it, with its question, stays plain.
Note
A length read as an ID makes the flags read as the question count, which flags of zero leave at zero, so the plain reading of a framed message with such flags can decode: it stops short of the end, or reads an octet run it lands on, such as a following message’s length, as an RDLENGTH counting the rest.
Header Schemas¶
- class pcapkit.protocols.application.dns.schema.DNS(length=NO_VALUE, id=NO_VALUE, flags=NO_VALUE, qdcount=NO_VALUE, ancount=NO_VALUE, nscount=NO_VALUE, arcount=NO_VALUE, body=NO_VALUE, payload=NO_VALUE, *, __packet__=None, **kwargs)[source]¶
Bases:
SchemaHeader schema for DNS message.
The two-octet length precedes the message over TCP alone (RFC 1035 Section 4.2.2), which
__framed__in the packet context says when unpacking; packing, alengthgiven says it.
Type Stubs¶
Domain Name Codec¶
The codec works on octets and labels, with no protocol state, so another protocol carrying domain names can call it.
- pcapkit.protocols.application.dns.schema.read_name(data, pos, *, compression=True, alias='DNS')[source]¶
Read the domain name at
posindata.- Parameters:
- Return type:
- Returns:
Every label of the name, the root’s left out; how many of them are written in full at
pos; the offset the pointer ending the name there points to, orNonewhere the root label ends it; and the offset just past the name atpos.- Raises:
ProtocolError – If the name runs past the end of
data, holds a label type other than a plain label or, wherecompressionallows one, a pointer (RFC 6891 Section 5), or its pointers loop.
- pcapkit.protocols.application.dns.schema.make_name(labels, *, literal=None, pointer=None, alias='DNS')[source]¶
Write a domain name, the inverse of
read_name().- Parameters:
labels (
Sequence[bytes]) – Every label of the name, the root’s left out.literal (
int|None) – How many oflabelsto write in full; all of them ifNone.pointer (
int|None) – Offset a compression pointer after them points to, orNoneto end the name with the root label.alias (
str) – Prefix of the error message.
- Return type:
- Returns:
The name’s octets.
- Raises:
ProtocolError – If a label written is empty or longer than 63 octets,
literalis not a count oflabels, orpointerdoes not fit in 14 bits.
- pcapkit.protocols.application.dns.schema.compress_name(labels, table, offset)[source]¶
Choose how to write a name against the names already written.
- Parameters:
- Returns:
the longest suffix in
tableis pointed to, and the labels before it written.- Return type:
- pcapkit.protocols.application.dns.schema.record_name(labels, literal, table, offset)[source]¶
Add the label suffixes a name writes in full to
table.
- pcapkit.protocols.application.dns.schema.name_to_text(labels)[source]¶
Render labels in presentation form (RFC 1035 Section 5.1).
- pcapkit.protocols.application.dns.schema.text_to_labels(text, *, alias='DNS')[source]¶
Read a name in presentation form into labels, the inverse of
name_to_text().- Parameters:
- Return type:
- Returns:
Every label of the name, the root’s left out.
- Raises:
ProtocolError – If
textholds an empty label, or a backslash not followed by a character or by three decimal digits up to 255.
Data Models¶
- class pcapkit.protocols.application.dns.data.DNS(id, flags, qdcount, ancount, nscount, arcount, question, answer, authority, additional)[source]¶
Bases:
ProtocolData model for a DNS message (RFC 1035 Section 4.1).
- answer: tuple[ResourceRecord | OPT, ...]¶
Answer section.
- authority: tuple[ResourceRecord | OPT, ...]¶
Authority section.
- additional: tuple[ResourceRecord | OPT, ...]¶
Additional section, holding the OPT pseudo-record of EDNS(0) if any.
- length: int¶
Message length, the two-octet field preceding the message over TCP (RFC 1035 Section 4.2.2); present only for such a message.
- class pcapkit.protocols.application.dns.data.Flags(qr, opcode, aa, tc, rd, ra, z, ad, cd, rcode)[source]¶
Bases:
DataData model for the DNS header flags (RFC 1035 Section 4.1.1).
- ad: bool¶
Authentic data (RFC 4035 Section 3.2.3).
- cd: bool¶
Checking disabled (RFC 4035 Section 3.2.2).
- rcode: RCode¶
Response code, the low four bits of an extended one (RFC 6891 Section 6.1.3).
- class pcapkit.protocols.application.dns.data.Name(name, labels, literal, pointer)[source]¶
Bases:
DataData model for a domain name (RFC 1035 Section 3.1).
literalandpointerrecord how the name was written, so that it is rebuilt with the compression it was read with (RFC 1035 Section 4.1.4).
- class pcapkit.protocols.application.dns.data.Question(name, type)[source]¶
Bases:
DataData model for a question section entry (RFC 1035 Section 4.1.2).
Its
classkey, a keyword in Python, holds theRRClass.
- class pcapkit.protocols.application.dns.data.ResourceRecord(name, type, ttl, rdlength, rdata)[source]¶
Bases:
DataData model for a resource record (RFC 1035 Section 4.1.3).
Its
classkey, a keyword in Python, holds theRRClass.rdataholds the decoded RDATA whereDNS.__rdata__registers a decoder fortype, and the raw octets otherwise, including RDATA its decoder cannot read exactly.
- class pcapkit.protocols.application.dns.data.OPT(name, type, udp_payload_size, extended_rcode, version, do, z, rdlength, options)[source]¶
Bases:
DataData model for the OPT pseudo-record of EDNS(0) (RFC 6891 Section 6.1.2).
The CLASS and TTL fields of a resource record are redefined for it, and each of their parts has a field here.
- do: bool¶
DNSSEC OK bit (RFC 3225 Section 3).
- class pcapkit.protocols.application.dns.data.Option(code, length, data)[source]¶
Bases:
DataData model for an EDNS(0) option (RFC 6891 Section 6.1.2).
dataholds the decoded OPTION-DATA whereDNS.__option__registers a decoder forcode, and the raw octets otherwise.- data: OptionData | bytes¶
OPTION-DATA, decoded or as raw octets.
RDATA¶
- class pcapkit.protocols.application.dns.data.RData(*args, **kwargs)[source]¶
Bases:
DataData model for the decoded RDATA of a resource record.
Each subclass is the structure one
RRTypecarries, its fields named as its specification names them.
- class pcapkit.protocols.application.dns.data.A(address)[source]¶
Bases:
RDataData model for the
ARDATA (RFC 1035 Section 3.4.1).- address: IPv4Address¶
IPv4 address.
- class pcapkit.protocols.application.dns.data.NS(nsdname)[source]¶
Bases:
RDataData model for the
NSRDATA (RFC 1035 Section 3.3.11).
- class pcapkit.protocols.application.dns.data.CNAME(cname)[source]¶
Bases:
RDataData model for the
CNAMERDATA (RFC 1035 Section 3.3.1).
- class pcapkit.protocols.application.dns.data.SOA(mname, rname, serial, refresh, retry, expire, minimum)[source]¶
Bases:
RDataData model for the
SOARDATA (RFC 1035 Section 3.3.13).- minimum: int¶
Minimum TTL, in seconds; the negative-caching TTL (RFC 2308 Section 4).
- class pcapkit.protocols.application.dns.data.PTR(ptrdname)[source]¶
Bases:
RDataData model for the
PTRRDATA (RFC 1035 Section 3.3.12).
- class pcapkit.protocols.application.dns.data.MX(preference, exchange)[source]¶
Bases:
RDataData model for the
MXRDATA (RFC 1035 Section 3.3.9).
- class pcapkit.protocols.application.dns.data.TXT(strings)[source]¶
Bases:
RDataData model for the
TXTRDATA (RFC 1035 Section 3.3.14).
- class pcapkit.protocols.application.dns.data.AAAA(address)[source]¶
Bases:
RDataData model for the
AAAARDATA (RFC 3596 Section 2.2).- address: IPv6Address¶
IPv6 address.
EDNS(0) Options¶
- class pcapkit.protocols.application.dns.data.OptionData(*args, **kwargs)[source]¶
Bases:
DataData model for the decoded OPTION-DATA of an EDNS(0) option.
Each subclass is the structure one
Optioncarries, its fields named as its specification names them.
- class pcapkit.protocols.application.dns.data.ClientSubnet(family, source_prefix, scope_prefix, address)[source]¶
Bases:
OptionDataData model for the
edns-client-subnetoption (RFC 7871 Section 6).- address: bytes¶
Address, as many octets as
source_prefixcovers.
- class pcapkit.protocols.application.dns.data.Cookie(client, server)[source]¶
Bases:
OptionDataData model for the
COOKIEoption (RFC 7873 Section 4).
- class pcapkit.protocols.application.dns.data.TCPKeepalive(timeout)[source]¶
Bases:
OptionDataData model for the
edns-tcp-keepaliveoption (RFC 7828 Section 3.1).
- class pcapkit.protocols.application.dns.data.ExtendedError(info_code, extra_text)[source]¶
Bases:
OptionDataData model for the
Extended DNS Erroroption (RFC 8914 Section 2).
Constants¶
- pcapkit.protocols.application.dns.const.HEADER_LENGTH = 12¶
Length of the fixed header, before the sections (RFC 1035 Section 4.1.1).
- pcapkit.protocols.application.dns.const.POINTER_LIMIT = 16383¶
Largest offset a compression pointer can carry, in its 14 bits.