Struct dnssector::parsed_packet::ParsedPacket
source · pub struct ParsedPacket {Show 13 fields
pub packet: Option<Vec<u8>>,
pub offset_question: Option<usize>,
pub offset_answers: Option<usize>,
pub offset_nameservers: Option<usize>,
pub offset_additional: Option<usize>,
pub offset_edns: Option<usize>,
pub edns_count: u16,
pub ext_rcode: Option<u8>,
pub edns_version: Option<u8>,
pub ext_flags: Option<u16>,
pub maybe_compressed: bool,
pub max_payload: usize,
pub cached: Option<(Vec<u8>, u16, u16)>,
}
Expand description
A ParsedPacket
structure contains information about a successfully parsed
DNS packet, that allows quick access to (extended) flags and to individual sections.
Fields
packet: Option<Vec<u8>>
offset_question: Option<usize>
offset_answers: Option<usize>
offset_nameservers: Option<usize>
offset_additional: Option<usize>
offset_edns: Option<usize>
edns_count: u16
ext_rcode: Option<u8>
edns_version: Option<u8>
ext_flags: Option<u16>
maybe_compressed: bool
max_payload: usize
cached: Option<(Vec<u8>, u16, u16)>
Implementations
sourceimpl ParsedPacket
impl ParsedPacket
sourcepub fn into_packet(self) -> Vec<u8>
pub fn into_packet(self) -> Vec<u8>
Converts a ParsedPacket
back into a raw packet.
sourcepub fn packet(&self) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
pub fn packet(&self) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
Returns a reference to the packet
pub fn packet_mut(&mut self) -> &mut Vec<u8>
sourcepub fn into_iter_question(&mut self) -> Option<QuestionIterator<'_>>
pub fn into_iter_question(&mut self) -> Option<QuestionIterator<'_>>
Iterates over the question section.
sourcepub fn into_iter_answer(&mut self) -> Option<AnswerIterator<'_>>
pub fn into_iter_answer(&mut self) -> Option<AnswerIterator<'_>>
Iterates over the answer section.
sourcepub fn into_iter_nameservers(&mut self) -> Option<NameServersIterator<'_>>
pub fn into_iter_nameservers(&mut self) -> Option<NameServersIterator<'_>>
Iterates over the list of name servers.
sourcepub fn into_iter_additional(&mut self) -> Option<AdditionalIterator<'_>>
pub fn into_iter_additional(&mut self) -> Option<AdditionalIterator<'_>>
Iterates over the additional section - OPT RRs are skipped.
sourcepub fn into_iter_additional_including_opt(
&mut self
) -> Option<AdditionalIterator<'_>>
pub fn into_iter_additional_including_opt(
&mut self
) -> Option<AdditionalIterator<'_>>
Iterates over the additional section - OPT RRs are included.
sourcepub fn into_iter_edns(&mut self) -> Option<EdnsIterator<'_>>
pub fn into_iter_edns(&mut self) -> Option<EdnsIterator<'_>>
Iterates over the records from the optional edns pseudo-section.
sourcepub fn copy_header(&self, header: &mut Vec<u8>)
pub fn copy_header(&self, header: &mut Vec<u8>)
Copy the packet header
sourcepub fn copy_raw_edns_section(&self, raw_edns: &mut Vec<u8>) -> usize
pub fn copy_raw_edns_section(&self, raw_edns: &mut Vec<u8>) -> usize
Copy the EDNS section
sourcepub fn flags(&self) -> u32
pub fn flags(&self) -> u32
Returns the flags, including extended flags. The extended flags optionally obtained using edns are exposed as the highest 16 bits, instead of having distinct sets of flags. The opcode and rcode are intentionally masked in order to prevent misuse: these bits are never supposed to be accessed individually.
sourcepub fn set_flags(&mut self, flags: u32)
pub fn set_flags(&mut self, flags: u32)
Changes the flags. Extended flags from the OPT section are currently ignored.
sourcepub fn dnssec(&self) -> bool
pub fn dnssec(&self) -> bool
Check if this is a question with the DO bit, or a response with the AD bit
sourcepub fn is_response(&self) -> bool
pub fn is_response(&self) -> bool
Check if this is a response
sourcepub fn set_response(&mut self, is_response: bool)
pub fn set_response(&mut self, is_response: bool)
Set the response bit
sourcepub fn set_opcode(&mut self, opcode: u8)
pub fn set_opcode(&mut self, opcode: u8)
Changes the operation code.
sourcepub fn max_payload(&self) -> usize
pub fn max_payload(&self) -> usize
Maximum payload size when using UDP
sourcepub fn rrcount_inc(&mut self, section: Section) -> Result<u16, Error>
pub fn rrcount_inc(&mut self, section: Section) -> Result<u16, Error>
Increments the number of records in a given section
sourcepub fn rrcount_dec(&mut self, section: Section) -> Result<u16, Error>
pub fn rrcount_dec(&mut self, section: Section) -> Result<u16, Error>
Decrements the number of records in a given section
pub fn insert_rr(&mut self, section: Section, rr: RR) -> Result<(), Error>
pub fn insert_rr_from_string(
&mut self,
section: Section,
rr_str: &str
) -> Result<(), Error>
sourcepub fn recompute(&mut self) -> Result<(), Error>
pub fn recompute(&mut self) -> Result<(), Error>
Recomputes all section offsets after an in-place decompression of the packet.
It is currently re-parsing everything by calling parse()
, but this can be
optimized later to skip over RDATA, and by assuming that the input
is always well-formed.
sourcepub fn question_raw0(&mut self) -> Option<(&[u8], u16, u16)>
pub fn question_raw0(&mut self) -> Option<(&[u8], u16, u16)>
Returns the question as a raw vector, without case conversion, as well as the query type and class
Names include a trailing 0
sourcepub fn question_raw(&mut self) -> Option<(&[u8], u16, u16)>
pub fn question_raw(&mut self) -> Option<(&[u8], u16, u16)>
Returns the question as a raw vector, without case conversion, as well as the query type and class
Names do not include trailing 0
sourcepub fn question(&mut self) -> Option<(Vec<u8>, u16, u16)>
pub fn question(&mut self) -> Option<(Vec<u8>, u16, u16)>
Returns the question as a string, without case conversion, as well as the query type and class
sourcepub fn qtype_qclass(&self) -> Option<(u16, u16)>
pub fn qtype_qclass(&self) -> Option<(u16, u16)>
Return the query type and class
sourcepub fn rename_with_raw_names(
&mut self,
target_name: &[u8],
source_name: &[u8],
match_suffix: bool
) -> Result<(), Error>
pub fn rename_with_raw_names(
&mut self,
target_name: &[u8],
source_name: &[u8],
match_suffix: bool
) -> Result<(), Error>
Replaces source_name
with target_name
in all names, in all records.
If match_suffix
is true
, do suffix matching instead of exact matching
This allows renaming *.example.com
into *.example.net
.