1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//! Unicast and Multicast DNS and DNS Service Discovery implementation.

#![forbid(unaligned_references)]

use std::net::IpAddr;

pub mod packet;
pub mod resolver;
pub mod service;
pub mod tap;

/// Unicast DNS messages are limited to 512 Bytes.
const DNS_BUFFER_SIZE: usize = 512;

/// DNS messages are limited to 512 Bytes, but mDNS works entirely within a local network, so it can
/// use larger messages.
///
/// This constant is the size of packet receive buffers and does not have to accomodate IP and UDP
/// headers. It still does, because I cannot be bothered.
const MDNS_BUFFER_SIZE: usize = 1500;

/// Iterator over IP addresses received from a name server.
pub struct IpAddrIter<'a> {
    inner: std::slice::Iter<'a, IpAddr>,
}

impl<'a> Iterator for IpAddrIter<'a> {
    type Item = IpAddr;

    fn next(&mut self) -> Option<Self::Item> {
        match self.inner.next() {
            Some(ip) => Some(*ip),
            None => None,
        }
    }
}