Skip to main content

Packet

Struct Packet 

Source
pub struct Packet<'a> {
    pub questions: Vec<Question<'a>>,
    pub answers: Vec<ResourceRecord<'a>>,
    pub name_servers: Vec<ResourceRecord<'a>>,
    pub additional_records: Vec<ResourceRecord<'a>>,
    /* private fields */
}
Expand description

Represents a DNS message packet

When working with EDNS packets, use Packet::opt and Packet::opt_mut to add or access OPT packet information

Fields§

§questions: Vec<Question<'a>>

Questions section

§answers: Vec<ResourceRecord<'a>>

Answers section

§name_servers: Vec<ResourceRecord<'a>>

Name servers section

§additional_records: Vec<ResourceRecord<'a>>

Aditional records section.
DO NOT use this field to add OPT record, use Packet::opt_mut instead

Implementations§

Source§

impl<'a> Packet<'a>

Source

pub fn new_query(id: u16) -> Self

Creates a new empty packet with a query header

Source

pub fn new_reply(id: u16) -> Self

Creates a new empty packet with a reply header

Source

pub fn id(&self) -> u16

Get packet id

Source

pub fn set_id(&mut self, id: u16)

Set packet id

Source

pub fn set_flags(&mut self, flags: PacketFlag)

Set flags in the packet

Source

pub fn remove_flags(&mut self, flags: PacketFlag)

Remove flags present in the packet

Source

pub fn has_flags(&self, flags: PacketFlag) -> bool

Check if the packet has flags set

Source

pub fn rcode(&self) -> RCODE

Get this packet RCODE information

Source

pub fn rcode_mut(&mut self) -> &mut RCODE

Get a mutable reference for this packet RCODE information Warning, if the RCODE value is greater than 15 (4 bits), you MUST provide an OPT resource record through the Packet::opt_mut function

Source

pub fn opcode(&self) -> OPCODE

Get this packet OPCODE information

Source

pub fn opcode_mut(&mut self) -> &mut OPCODE

Get a mutable reference for this packet OPCODE information

Source

pub fn opt(&self) -> Option<&OPT<'a>>

Get the OPT resource record for this packet, if present

Source

pub fn opt_mut(&mut self) -> &mut Option<OPT<'a>>

Get a mutable reference for this packet OPT resource record.

Source

pub fn into_reply(self) -> Self

Changes this packet into a reply packet by replacing its header

Source

pub fn parse(data: &'a [u8]) -> Result<Self>

Parses a packet from a slice of bytes

Source

pub fn build_bytes_vec(&self) -> Result<Vec<u8>>

Creates a new Vec<u8> and write the contents of this package in wire format

This call will allocate a Vec<u8> of 900 bytes, which is enough for a jumbo UDP packet

Source

pub fn build_bytes_vec_compressed(&self) -> Result<Vec<u8>>

Creates a new Vec<u8> and write the contents of this package in wire format with compression enabled

Names are only compressed against byte-identical names. Names that are equal under DNS case-insensitive comparison but differ in casing (Foo.local and foo.local) are written in full, so the casing of every name is preserved when the packet is parsed again.

This call will allocate a Vec<u8> of 900 bytes, which is enough for a jumbo UDP packet

Source

pub fn write_to<T: Write>(&self, out: &mut T) -> Result<()>

Write the contents of this package in wire format into the provided writer

Source

pub fn write_compressed_to<T: Write + Seek>(&self, out: &mut T) -> Result<()>

Write the contents of this package in wire format with enabled compression into the provided writer

Names are only compressed against byte-identical names. Names that are equal under DNS case-insensitive comparison but differ in casing (Foo.local and foo.local) are written in full, so the casing of every name is preserved when the packet is parsed again.

Trait Implementations§

Source§

impl<'a> Clone for Packet<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Packet<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Packet<'a>

§

impl<'a> RefUnwindSafe for Packet<'a>

§

impl<'a> Send for Packet<'a>

§

impl<'a> Sync for Packet<'a>

§

impl<'a> Unpin for Packet<'a>

§

impl<'a> UnsafeUnpin for Packet<'a>

§

impl<'a> UnwindSafe for Packet<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.