Skip to content

Commit

Permalink
Merge pull request kaitai-io#291 from NN---/patch-6
Browse files Browse the repository at this point in the history
Support TXT, SRV and PTR records
  • Loading branch information
GreyCat authored May 30, 2020
2 parents 0070bb7 + b6fb961 commit 8678108
Showing 1 changed file with 38 additions and 11 deletions.
49 changes: 38 additions & 11 deletions network/dns_packet.ksy
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ meta:
rfc: 1035
license: CC0-1.0
endian: be
encoding: utf-8
doc: |
(No support for Auth-Name + Add-Name for simplicity)
seq:
Expand Down Expand Up @@ -46,7 +47,7 @@ seq:
repeat-expr: arcount
types:
query:
seq:
seq:
- id: name
type: domain_name
- id: type
Expand All @@ -71,19 +72,23 @@ types:
- id: rdlength
doc: "Length in octets of the following payload"
type: u2
- id: ptrdname
type: domain_name
if: "type == type_type::ptr"
- id: address
type: address
if: "type == type_type::a"
- id: payload
size: rdlength
type:
switch-on: type
cases:
"type_type::ptr": domain_name
"type_type::a": address
"type_type::cname": domain_name
"type_type::srv": service
"type_type::txt": txt_body
domain_name:
seq:
- id: name
type: label
repeat: until
doc: "Repeat until the length is 0 or it is a pointer (bit-hack to get around lack of OR operator)"
repeat-until: "_.length == 0 or _.length == 0b1100_0000"
repeat-until: "_.length == 0 or _.length >= 192"
label:
seq:
- id: length
Expand All @@ -96,11 +101,10 @@ types:
if: "not is_pointer"
doc: "Otherwise its a string the length of the length value"
type: str
encoding: "ASCII"
size: length
instances:
is_pointer:
value: length == 0b1100_0000
value: length >= 192
pointer_struct:
seq:
- id: value
Expand All @@ -109,7 +113,7 @@ types:
instances:
contents:
io: _root._io
pos: value
pos: value + ((_parent.length - 192) << 8)
type: domain_name
address:
seq:
Expand Down Expand Up @@ -144,6 +148,28 @@ types:
value: (flag & 0b0000_0000_0000_1111) >> 0
is_opcode_valid:
value: opcode == 0 or opcode == 1 or opcode == 2
service:
seq:
- id: priority
type: u2
- id: weight
type: u2
- id: port
type: u2
- id: target
type: domain_name
txt:
seq:
- id: length
type: u1
- id: text
type: str
size: length
txt_body:
seq:
- id: data
type: txt
repeat: eos

enums:
class_type:
Expand All @@ -168,3 +194,4 @@ enums:
14: minfo
15: mx
16: txt
33: srv

0 comments on commit 8678108

Please sign in to comment.