diff --git a/Cargo.toml b/Cargo.toml index c4c606b..f25717a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,6 @@ if-addrs = { version = "0.13", features = ["link-local"] } # get local IP addres log = { version = "0.4", optional = true } # logging mio = { version = "1.0", features = ["os-poll", "net"] } # select/poll sockets socket2 = { version = "0.5.5", features = ["all"] } # socket APIs -mdns-parser = { path = "mdns-parser" } # DNS message parsing [dev-dependencies] env_logger = { version = "= 0.10.2", default-features = false, features= ["humantime"] } diff --git a/mdns-parser/Cargo.toml b/mdns-parser/Cargo.toml deleted file mode 100644 index 053cac3..0000000 --- a/mdns-parser/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "mdns-parser" -version = "0.1.0" -edition = "2018" -rust-version = "1.65.0" -authors = ["keepsimple "] -keywords = ["mdns", "service-discovery", "zeroconf", "dns-sd"] -license = "Apache-2.0 OR MIT" -repository = "https://github.com/keepsimple1/mdns-sd" -description = "DNS message parsing for mDNS Service Discovery" - -[features] -logging = ["log"] - -[dependencies] -log = { version = "0.4", optional = true } # logging - -[dev-dependencies] -fastrand = "2.1" diff --git a/mdns-parser/README.md b/mdns-parser/README.md deleted file mode 100644 index 53df0ac..0000000 --- a/mdns-parser/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# mdns-parser - -A DNS message parsing utility for mDNS service discovery. Originally it was just a file in the [`mdns-sd`](https://crates.io/crates/mdns-sd) crate, and now it is built into its own crate so that it can be used in other cases. Please note that the API is still experimental and might change in near future. - -## Contribution - -Contributions are welcome! Please open an issue in GitHub if any questions. - -Unless you explicitly state otherwise, any contribution intentionally submitted -for inclusion in the work by you, as defined in the above license(s), shall be -dual licensed as above, without any additional terms or conditions. - diff --git a/mdns-parser/src/lib.rs b/mdns-parser/src/lib.rs deleted file mode 100644 index b34cf5c..0000000 --- a/mdns-parser/src/lib.rs +++ /dev/null @@ -1,28 +0,0 @@ -//! DNS parsing utility with a focus on mDNS service discovery. -//! -//! - [DnsIncoming] is the logic representation of an incoming DNS message. -//! - [DnsOutgoing] is the logic representation of an outgoing DNS message. - -// log for logging (optional). -#[cfg(feature = "logging")] -use log::trace; - -#[cfg(not(feature = "logging"))] -#[macro_use] -mod log { - macro_rules! trace { - ($($arg:expr),*) => { - { - let _ = ($($arg),*); // avoid warnings about unused variables. - } - }; - } -} - -mod dns_parser; - -pub use dns_parser::{ - ip_address_rr_type, DnsAddress, DnsEntryExt, DnsIncoming, DnsNSec, DnsOutgoing, DnsPointer, - DnsRecordBox, DnsRecordExt, DnsSrv, DnsTxt, RRType, TxtProperty, CLASS_CACHE_FLUSH, CLASS_IN, - FLAGS_AA, FLAGS_QR_QUERY, FLAGS_QR_RESPONSE, MAX_MSG_ABSOLUTE, -}; diff --git a/src/dns_cache.rs b/src/dns_cache.rs index 4efae24..9fc0537 100644 --- a/src/dns_cache.rs +++ b/src/dns_cache.rs @@ -4,9 +4,11 @@ #[cfg(feature = "logging")] use crate::log::trace; -use crate::service_info::{split_sub_domain, valid_two_addrs_on_intf}; +use crate::{ + dns_parser::{DnsAddress, DnsPointer, DnsRecordBox, DnsSrv, RRType}, + service_info::{split_sub_domain, valid_two_addrs_on_intf}, +}; use if_addrs::Interface; -use mdns_parser::{DnsAddress, DnsPointer, DnsRecordBox, DnsSrv, RRType}; use std::{ collections::{HashMap, HashSet}, net::IpAddr, diff --git a/mdns-parser/src/dns_parser.rs b/src/dns_parser.rs similarity index 99% rename from mdns-parser/src/dns_parser.rs rename to src/dns_parser.rs index c02aed3..5e2ac61 100644 --- a/mdns-parser/src/dns_parser.rs +++ b/src/dns_parser.rs @@ -883,18 +883,6 @@ pub struct TxtProperty { } impl TxtProperty { - /// Returns the key of a property. - pub fn key(&self) -> &str { - &self.key - } - - /// Returns the value of a property, which could be `None`. - /// - /// To obtain a `&str` of the value, use `val_str()` instead. - pub fn val(&self) -> Option<&[u8]> { - self.val.as_deref() - } - /// Returns the value of a property as str. pub fn val_str(&self) -> &str { self.val @@ -1085,7 +1073,7 @@ impl DnsNSec { } /// Returns the types marked by `type_bitmap` - pub fn types(&self) -> Vec { + pub fn _types(&self) -> Vec { // From RFC 4034: 4.1.2 The Type Bit Maps Field // https://datatracker.ietf.org/doc/html/rfc4034#section-4.1.2 // diff --git a/src/lib.rs b/src/lib.rs index 4988b2c..1f7164e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -146,10 +146,12 @@ mod log { } mod dns_cache; +mod dns_parser; mod error; mod service_daemon; mod service_info; +pub use dns_parser::RRType; pub use error::{Error, Result}; pub use service_daemon::{ DaemonEvent, DaemonStatus, DnsNameChange, HostnameResolutionEvent, IfKind, Metrics, @@ -160,6 +162,3 @@ pub use service_info::{AsIpAddrs, IntoTxtProperties, ServiceInfo, TxtProperties, /// A handler to receive messages from [ServiceDaemon]. Re-export from `flume` crate. pub use flume::Receiver; - -/// DNS Resource Record types. Re-export from `mdns-parser` crate. -pub use mdns_parser::RRType; diff --git a/src/service_daemon.rs b/src/service_daemon.rs index 6612991..ff21b52 100644 --- a/src/service_daemon.rs +++ b/src/service_daemon.rs @@ -32,6 +32,11 @@ use crate::log::{debug, trace}; use crate::{ dns_cache::{current_time_millis, DnsCache}, + dns_parser::{ + ip_address_rr_type, DnsAddress, DnsEntryExt, DnsIncoming, DnsOutgoing, DnsPointer, + DnsRecordBox, DnsRecordExt, DnsSrv, DnsTxt, RRType, CLASS_CACHE_FLUSH, CLASS_IN, FLAGS_AA, + FLAGS_QR_QUERY, FLAGS_QR_RESPONSE, MAX_MSG_ABSOLUTE, + }, error::{Error, Result}, service_info::{ split_sub_domain, valid_ip_on_intf, DnsRegistry, Probe, ServiceInfo, ServiceStatus, @@ -40,11 +45,6 @@ use crate::{ }; use flume::{bounded, Sender, TrySendError}; use if_addrs::{IfAddr, Interface}; -use mdns_parser::{ - ip_address_rr_type, DnsAddress, DnsEntryExt, DnsIncoming, DnsOutgoing, DnsPointer, - DnsRecordBox, DnsRecordExt, DnsSrv, DnsTxt, RRType, CLASS_CACHE_FLUSH, CLASS_IN, FLAGS_AA, - FLAGS_QR_QUERY, FLAGS_QR_RESPONSE, MAX_MSG_ABSOLUTE, -}; use mio::{net::UdpSocket as MioUdpSocket, Poll}; use socket2::Socket; use std::{ @@ -2210,7 +2210,7 @@ impl Zeroconf { || service .get_subtype() .as_ref() - .map_or(false, |v| v == question.entry_name()) + .is_some_and(|v| v == question.entry_name()) { add_answer_with_additionals(&mut out, &msg, service, intf, dns_registry); } else if question.entry_name() == META_QUERY { @@ -3497,8 +3497,10 @@ mod tests { HostnameResolutionEvent, ServiceDaemon, ServiceEvent, ServiceInfo, GROUP_ADDR_V4, MDNS_PORT, }; - use crate::service_daemon::check_hostname; - use mdns_parser::{DnsOutgoing, DnsPointer, RRType, CLASS_IN, FLAGS_AA, FLAGS_QR_RESPONSE}; + use crate::{ + dns_parser::{DnsOutgoing, DnsPointer, RRType, CLASS_IN, FLAGS_AA, FLAGS_QR_RESPONSE}, + service_daemon::check_hostname, + }; use std::{ net::{SocketAddr, SocketAddrV4}, time::Duration, diff --git a/src/service_info.rs b/src/service_info.rs index d510d8b..52e0c82 100644 --- a/src/service_info.rs +++ b/src/service_info.rs @@ -2,9 +2,11 @@ #[cfg(feature = "logging")] use crate::log::debug; -use crate::{Error, Result}; +use crate::{ + dns_parser::{DnsRecordBox, DnsRecordExt, DnsSrv, RRType}, + Error, Result, +}; use if_addrs::{IfAddr, Interface}; -use mdns_parser::{DnsRecordBox, DnsRecordExt, DnsSrv, RRType}; use std::{ cmp, collections::{HashMap, HashSet},