pub struct DnsPacket<'a> { /* private fields */ }Expand description
A read/write wrapper around a DNS packet buffer.
Implementations§
Source§impl<'a> Packet<'a>
impl<'a> Packet<'a>
Sourcepub const fn new_unchecked(buffer: &'a mut [u8]) -> Packet<'a>
pub const fn new_unchecked(buffer: &'a mut [u8]) -> Packet<'a>
Imbue a raw octet buffer with DNS packet structure.
Sourcepub fn new_checked(buffer: &'a mut [u8]) -> Result<Packet<'a>>
pub fn new_checked(buffer: &'a mut [u8]) -> Result<Packet<'a>>
Shorthand for a combination of new_unchecked and check_len.
Sourcepub fn check_len(&self) -> Result<()>
pub fn check_len(&self) -> Result<()>
Ensure that no accessor method will panic if called.
Returns Err(Error) if the buffer is smaller than
the header length.
Sourcepub fn into_inner(self) -> &'a mut [u8] ⓘ
pub fn into_inner(self) -> &'a mut [u8] ⓘ
Consume the packet, returning the underlying buffer.
Sourcepub fn transaction_id(&self) -> u16
pub fn transaction_id(&self) -> u16
Return the transaction ID field.
Sourcepub fn question_count(&self) -> u16
pub fn question_count(&self) -> u16
Return the question count field.
Sourcepub fn answer_record_count(&self) -> u16
pub fn answer_record_count(&self) -> u16
Return the answer record count field.
Return the authority record count field.
Sourcepub fn additional_record_count(&self) -> u16
pub fn additional_record_count(&self) -> u16
Return the additional record count field.
Sourcepub fn parse_name<'b>(
&'b self,
bytes: &'b [u8],
) -> impl Iterator<Item = Result<&'b [u8]>>
pub fn parse_name<'b>( &'b self, bytes: &'b [u8], ) -> impl Iterator<Item = Result<&'b [u8]>>
Parse a name from bytes, following compression pointers into this packet.
Yields one label at a time. Pointers are only allowed to point backwards, so pointer loops end the iteration with an error.
Sourcepub fn payload_mut(&mut self) -> &mut [u8] ⓘ
pub fn payload_mut(&mut self) -> &mut [u8] ⓘ
The bytes after the header, mutable.
Sourcepub fn set_transaction_id(&mut self, val: u16)
pub fn set_transaction_id(&mut self, val: u16)
Set the transaction ID field.
Sourcepub fn set_flags(&mut self, val: Flags)
pub fn set_flags(&mut self, val: Flags)
Set the flags field. Leaves the opcode and rcode bits alone.
Sourcepub fn set_opcode(&mut self, val: Opcode)
pub fn set_opcode(&mut self, val: Opcode)
Set the opcode field.
Sourcepub fn set_question_count(&mut self, val: u16)
pub fn set_question_count(&mut self, val: u16)
Set the question count field.
Sourcepub fn set_answer_record_count(&mut self, val: u16)
pub fn set_answer_record_count(&mut self, val: u16)
Set the answer record count field.
Set the authority record count field.
Sourcepub fn set_additional_record_count(&mut self, val: u16)
pub fn set_additional_record_count(&mut self, val: u16)
Set the additional record count field.