Struct simple_dns::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

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

Trait Implementations§

source§

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

source§

fn clone(&self) -> Packet<'a>

Returns a copy of the value. Read more
1.0.0 · 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> 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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

§

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>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.