On Sun, 13 Aug 2023, Bob Halley wrote:
> Dnspython's message object was not designed to be a Wireshark-like packet
> dissector. The to_wire() of something you from_wire()'d will be
> semantically equivalent, but may not have identical wire format due to rrset
> construction, TTL minimization, opt placement and compression.
> Can you say more about your use case? E.g. is it enough to stash a copy of
> the original wire and emit it for your purpose, or are you looking for
> something more Wireshark-like? Dnspython certainly has the pieces to write
> a wire-faithful message format, but it would be a different class I think.
Yes it is enough to save the original wire.
My use cases all involve looking at same DNS message and records using
dnspython PLUS:
1) parse the wire data to understand and show the initial
message for education or testing. I view the data in various formats,
like:
1a) plain hex dump output of entire message
1b) hex + ascii dump with offsets (similar to hexdump -C)
1c) show binary bits for wire headers (like 0 0 0 0 0 0 0 1 1 1 0 1 1 0
1 1 for the TXID)
1d) view compression pointers information like position number, label
length, label itself, compression pointer, compression label, etc. I use
struct to parse for example: (rrttl, rdlength) = struct.unpack('!IH',
thewire[position:position + 6])
1e) view the rdata as Ascii decimal and hex and as raw data (like A
address RDATA: 4\"T)
2) Or show there are no compression pointers. I think dnspython
to_wire() always adds them, if it can, even if the original message did
not use them.
3) be able to know length in bytes of the original message. For example,
I check for payload size: ... if len(response.to_wire()) >
EDNS_PAYLOAD_SIZE ...
4) I save the wire data: f.write(response.to_wire()) to look at it later
I already do all the above using to_wire(). I know I can get a lot of
this information without the original wire data, but I want to use it
too for education and for research.
Keeping the original wire would be useful to me.