#![no_std] mod dns; pub(crate) mod encoder; pub mod server; mod service; mod state; extern crate alloc; use core::net::{Ipv4Addr, SocketAddrV4}; pub use crate::service::Service; pub use crate::state::MdnsAction; use crate::{dns::flags::Flags, server::Server, state::MdnsStateMachine}; /// Standard port for mDNS (5353). pub const MDNS_PORT: u16 = 5353; /// Standard IPv4 multicast address for mDNS (224.0.0.251). pub const GROUP_ADDR_V4: Ipv4Addr = Ipv4Addr::new(224, 0, 0, 251); pub const GROUP_SOCK_V4: SocketAddrV4 = SocketAddrV4::new(GROUP_ADDR_V4, MDNS_PORT); #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct MdnsService { server: Server, state: MdnsStateMachine, } impl MdnsService { pub fn new(service: Service) -> Self { Self { server: Server::new(service), state: Default::default(), } } pub fn next_action(&mut self) -> MdnsAction { self.state.drive_next_action() } pub fn send_announcement<'buffer>(&self, outgoing: &'buffer mut [u8]) -> Option<&'buffer [u8]> { self.server.broadcast( server::ResponseKind::Announcement, Flags::standard_response(), 1, alloc::vec::Vec::new(), outgoing, ) } pub fn listen_for_queries<'buffer>( &mut self, incoming: &[u8], outgoing: &'buffer mut [u8], ) -> Option<&'buffer [u8]> { self.server.respond(incoming, outgoing) } }