How do I turn dns_parser::Packet back into bytes?
Opened this issue · 4 comments
How do I serialize it back?
I want the library to be able to round-trip DNS packet from bytes to structured representation and back.
There is no such thing out of the box. We can probably add one, but I guess there are few more complications:
- Some hop-by-hop things might need to be changed when forwarding, like EDNS0 records
- AA bit and authority header might need to be changed as far as I understand
- And request_id have to be updated
- Also, the structure of
Packet
itself doesn't make it easy to edit things in the packet (i.e. slices pointing to the original buffer)
All of that makes it doubtful to have a generic round-trip function. But it should be easy enough to write the one for your specific use case. We might provide some helper functions, though. So contributions are welcome.
Is owned, static PacketBuf
and corresponding bytes generation function, maybe with "forwarding helper" function which modifies things as you suggested in scope of this crate of better be done as separate crate?
Implemented deep_clone
on multiple types, leading to parallel hierarchy of PacketBuf
, QuesitonBuf
, ResourceRecordBuf
, RDataBuf
and so on. Started implementing write_to
that converts those types back into bytes.
Is pull request welcome or it's better to have it in a separate fork to avoid cluttering dns-parser
?
Hi!
Sorry, for a late response. Please open a PR! It's easier to judge looking at the code.