hickory_proto/multicast/mod.rs
1// Copyright 2015-2018 Benjamin Fry <benjaminfry@me.com>
2//
3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4// https://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// https://opensource.org/licenses/MIT>, at your option. This file may not be
6// copied, modified, or distributed except according to those terms.
7
8//! Multicast protocol related components for DNS
9
10#[cfg(feature = "tokio")]
11mod mdns_client_stream;
12#[cfg(feature = "tokio")]
13mod mdns_stream;
14
15#[cfg(feature = "tokio")]
16pub use self::mdns_client_stream::{MdnsClientConnect, MdnsClientStream};
17#[cfg(feature = "tokio")]
18pub use self::mdns_stream::{MDNS_IPV4, MDNS_IPV6, MdnsStream};
19
20/// See [rfc6762](https://tools.ietf.org/html/rfc6762#section-5) details on these different types.
21#[derive(Clone, Copy, Debug, Eq, PartialEq)]
22pub enum MdnsQueryType {
23 /// The querier using this socket will only perform standard DNS queries over multicast. (clients only)
24 ///
25 /// Effectively treats mDNS as essentially no different than any other DNS query; one request followed by one response.
26 /// Only one UDP socket will be created.
27 OneShot,
28 /// The querier is fully compliant with [rfc6762](https://tools.ietf.org/html/rfc6762#section-5). (servers, clients)
29 ///
30 /// mDNS capable clients will sent messages with many queries, and they will expect many responses. Two UDP sockets will be
31 /// created, one for receiving multicast traffic, the other used for sending queries and direct responses. This requires
32 /// port 5353 to be available on the system (many modern OSes already have mDNSResponders running taking this port).
33 Continuous,
34 /// The querier operates under the OneShot semantics, but also joins the multicast group. (non-compliant servers, clients)
35 ///
36 /// This is not defined in the mDNS RFC, but allows for a multicast client to join the group, receiving all multicast network
37 /// traffic. This is useful where listening for all mDNS traffic is of interest, but because another mDNS process may have
38 /// already taken the known port, 5353. Query responses will come from and to the standard UDP socket with a random port,
39 /// multicast traffic will come from the multicast socket. This will create two sockets.
40 OneShotJoin,
41 /// The querier operates under the OneShot semantics, but also joins the multicast group. (servers)
42 ///
43 /// Not defined in the RFC, allows for a passive listener to receive all mDNS traffic.
44 Passive,
45}
46
47impl MdnsQueryType {
48 /// This will be sending packets, i.e. a standard UDP socket will be created
49 pub fn sender(self) -> bool {
50 match self {
51 Self::Passive => false,
52 Self::OneShot | Self::OneShotJoin => true,
53 Self::Continuous => true,
54 }
55 }
56
57 /// Returns true if this process can bind to *:5353
58 pub fn bind_on_5353(self) -> bool {
59 match self {
60 Self::OneShot | Self::OneShotJoin | Self::Passive => false,
61 Self::Continuous => true,
62 }
63 }
64
65 /// Returns true if this mDNS client should join, listen, on the multicast address
66 pub fn join_multicast(self) -> bool {
67 match self {
68 Self::OneShot => false,
69 Self::Continuous | Self::OneShotJoin | Self::Passive => true,
70 }
71 }
72}