Struct DnsSocket

Source
pub struct DnsSocket { /* private fields */ }
Expand description

Represents a socket transmitting DNS messages.

Implementations§

Source§

impl DnsSocket

Source

pub fn new() -> Result<DnsSocket>

Returns a DnsSocket, bound to an unspecified address.

Source

pub fn bind<A: ToSocketAddrs>(addr: A) -> Result<DnsSocket>

Returns a DnsSocket, bound to the given address.

Source

pub fn get(&self) -> &UdpSocket

Returns a reference to the wrapped UdpSocket.

Source

pub fn send_message<A: ToSocketAddrs>( &self, message: &Message<'_>, addr: A, ) -> Result<(), Error>

Sends a message to the given address.

Source

pub fn recv_from<'buf>( &self, buf: &'buf mut [u8], ) -> Result<(Message<'buf>, SocketAddr), Error>

Receives a message, returning the address of the sender. The given buffer is used to store and parse message data.

The buffer should be exactly MESSAGE_LIMIT bytes in length.

Source

pub fn recv_message<'buf>( &self, addr: &SocketAddr, buf: &'buf mut [u8], ) -> Result<Option<Message<'buf>>, Error>

Attempts to read a DNS message. The message will only be decoded if the remote address matches addr. If a packet is received from a non-matching address, the message is not decoded and Ok(None) is returned.

The buffer should be exactly MESSAGE_LIMIT bytes in length.

Auto Trait Implementations§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

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.