Skip to main content

OneShotMdnsResolver

Struct OneShotMdnsResolver 

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

Provides One Shot queries (legacy mDNS)

Every query will timeout after query_timeout elapses (defaults to 3 seconds)

One Shot queries returns only the first valid response to arrive

    use simple_mdns::sync_discovery::OneShotMdnsResolver;
    use std::time::Duration;
     
    let mut resolver = OneShotMdnsResolver::new().expect("Can't create one shot resolver");
    resolver.set_query_timeout(Duration::from_secs(1));
     
    // querying for IP Address
    let answer = resolver.query_service_address("_myservice._tcp.local").expect("Failed to query service address");
    println!("{:?}", answer);
    // IpV4Addr or IpV6Addr, depending on what was returned
    
    let answer = resolver.query_service_address_and_port("_myservice._tcp.local").expect("Failed to query service address and port");
    println!("{:?}", answer);
    // SocketAddr, "127.0.0.1:8080", with a ipv4 or ipv6

Implementations§

Source§

impl OneShotMdnsResolver

Source

pub fn new() -> Result<Self, SimpleMdnsError>

Creates a new OneShotMdnsResolver using IP V4 with unspecified interface

Source

pub fn new_with_scope( network_scope: NetworkScope, ) -> Result<Self, SimpleMdnsError>

Creates a new OneShotMdnsResolver with the specified scope

Source

pub fn query_packet( &self, packet: Packet<'_>, ) -> Result<Option<Vec<u8>>, SimpleMdnsError>

Send a query packet and returns the first response

Source

pub fn query_service_address( &self, service_name: &str, ) -> Result<Option<IpAddr>, SimpleMdnsError>

Send a query for A or AAAA (IP v4 and v6 respectively) resources and return the first address

Source

pub fn query_service_address_and_port( &self, service_name: &str, ) -> Result<Option<SocketAddr>, SimpleMdnsError>

Send a query for SRV resources and return the first address and port

Source

pub fn set_query_timeout(&mut self, query_timeout: Duration)

Set the one shot mdns resolver’s query timeout.

Source

pub fn set_unicast_response(&mut self, unicast_response: bool)

Set the one shot mdns resolver’s unicast response.

Trait Implementations§

Source§

impl Debug for OneShotMdnsResolver

Source§

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

Formats the value using the given formatter. Read more

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.