Skip to main content

SimpleMdnsResponder

Struct SimpleMdnsResponder 

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

A simple mDNS responder aimed for service discovery. In case you don’t have a mDNS responder in your network, or for some reason don’t want to use the ones available.

This responder will list for any mDNS query in the network via Multicast and will reply only to the resources that were added.

    use simple_mdns::sync_discovery::SimpleMdnsResponder;
    use simple_dns::{Name, CLASS, ResourceRecord, rdata::{RData, A, SRV}};
    use std::net::Ipv4Addr;


    let mut responder = SimpleMdnsResponder::new(10);
    let srv_name = Name::new_unchecked("_srvname._tcp.local");

    responder.add_resource(ResourceRecord::new(
        srv_name.clone(),
        CLASS::IN,
        10,
        RData::A(A { address: Ipv4Addr::LOCALHOST.into() }),
    ));

    responder.add_resource(ResourceRecord::new(
        srv_name.clone(),
        CLASS::IN,
        10,
        RData::SRV(SRV {
            port: 8080,
            priority: 0,
            weight: 0,
            target: srv_name
        })
    ));

This struct heavily relies on simple_dns crate and the same must be added as a dependency

Implementations§

Source§

impl SimpleMdnsResponder

Source

pub fn new(rr_ttl: u32) -> Self

Creates a new SimpleMdnsResponder with specified ttl and IPV4 scope with UNSPECIFIED Interface

Source

pub fn new_with_scope(rr_ttl: u32, scope: NetworkScope) -> Self

Creates a new SimpleMdnsResponder with specified ttl and network scope

Source

pub fn add_resource(&mut self, resource: ResourceRecord<'static>)

Register a Resource Record

Source

pub fn remove_resource_record(&mut self, resource: ResourceRecord<'static>)

Remove a resource record

Source

pub fn clear(&mut self)

Remove all resource records

Source

pub fn set_rr_ttl(&mut self, rr_default_ttl: u32)

Set the simple mdns responder’s rr default ttl in seconds (defaults to 300).

Trait Implementations§

Source§

impl Debug for SimpleMdnsResponder

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for SimpleMdnsResponder

Source§

fn default() -> Self

Returns the “default value” for a type. 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.