diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a999eee..575fd71 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -49,3 +49,28 @@ jobs: - name: Run Clippy run: cargo clippy --features "${{ matrix.features }}" -- -D warnings + + build-freebsd: + name: zeroconf-rs (FreeBSD) + runs-on: ubuntu-latest + strategy: + matrix: + features: [serde, ""] + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Build and test on FreeBSD + uses: vmactions/freebsd-vm@v1 + with: + usesh: true + prepare: | + pkg install -y curl rust mDNSResponder llvm + sysrc mdnsd_enable="YES" + service mdnsd start + run: | + cargo build --features "${{ matrix.features }}" + cargo test --features "${{ matrix.features }}" -- --skip service_register_is_browsable + cargo fmt -- --check + cargo clippy --features "${{ matrix.features }}" -- -D warnings diff --git a/Cargo.lock b/Cargo.lock index 4d5f8ee..e891780 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,22 +73,22 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.68.1" +version = "0.69.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "726e4313eb6ec35d2730258ad4e15b547ee75d6afaa1361a922e78e59b7d8078" +checksum = "271383c67ccabffb7381723dea0672a673f292304fcb45c01cc648c7a8d58088" dependencies = [ "bitflags", "cexpr", "clang-sys", + "itertools", "lazy_static", "lazycell", "log", - "peeking_take_while", "prettyplease", "proc-macro2", "quote", "regex", - "rustc-hash", + "rustc-hash 1.1.0", "shlex", "syn 2.0.110", "which", @@ -96,25 +96,22 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.69.5" +version = "0.72.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "271383c67ccabffb7381723dea0672a673f292304fcb45c01cc648c7a8d58088" +checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895" dependencies = [ "bitflags", "cexpr", "clang-sys", "itertools", - "lazy_static", - "lazycell", "log", "prettyplease", "proc-macro2", "quote", "regex", - "rustc-hash", + "rustc-hash 2.1.1", "shlex", "syn 2.0.110", - "which", ] [[package]] @@ -125,11 +122,11 @@ checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" [[package]] name = "bonjour-sys" -version = "0.3.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be8655c4daf1447c831970e4134e8312a15c63fbff109b353cfe934c22f2b61a" +checksum = "73af71be57caf454918b16e5f4ac6bfcbe2dcd68c381f080a4cd1df598a24627" dependencies = [ - "bindgen 0.68.1", + "bindgen 0.72.1", "libc", ] @@ -473,12 +470,6 @@ version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" -[[package]] -name = "peeking_take_while" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" - [[package]] name = "prettyplease" version = "0.2.37" @@ -542,6 +533,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc-hash" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" + [[package]] name = "rustix" version = "0.38.44" diff --git a/README.md b/README.md index 5a523fe..8fd641e 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,34 @@ On Windows: Bonjour must be installed. It comes bundled with [iTunes][] or [Bonjour Print Services][]. Further redistribution & bundling details are available on the [Apple Developer Site][]. +On FreeBSD: + +Bonjour/mDNSResponder must be installed. + +```bash +sudo pkg install mDNSResponder +``` + +After installing mDNSResponder, you need to enable and start the service: + +``` bash +sudo sysrc mdnsd_enable="YES" +sudo service mdnsd start +``` + +You might also need the development headers/libraries for linking. Check if you have the necessary files: +Check for mDNS headers + +``` bash +ls /usr/local/include/dns_sd.h +``` + +Check for libraries + +``` bash +ls /usr/local/lib/libdns_sd.so* +``` + ## Examples ### Register a service diff --git a/zeroconf/Cargo.toml b/zeroconf/Cargo.toml index 7c927c8..d690a31 100644 --- a/zeroconf/Cargo.toml +++ b/zeroconf/Cargo.toml @@ -37,10 +37,13 @@ clap = { version = "4.4.4", features = ["derive"] } avahi-sys = "0.10.1" [target.'cfg(target_vendor = "apple")'.dependencies] -bonjour-sys = "0.3.0" +bonjour-sys = { version = "0.4.0" } [target.'cfg(target_vendor = "pc")'.dependencies] -bonjour-sys = "0.3.0" +bonjour-sys = { version = "0.4.0" } + +[target.'cfg(target_os = "freebsd")'.dependencies] +bonjour-sys = { version = "0.4.0" } [package.metadata.docs.rs] default-target = "x86_64-unknown-linux-gnu" diff --git a/zeroconf/src/bonjour/browser.rs b/zeroconf/src/bonjour/browser.rs index bebf7aa..e28b553 100644 --- a/zeroconf/src/bonjour/browser.rs +++ b/zeroconf/src/bonjour/browser.rs @@ -12,7 +12,7 @@ use crate::{EventLoop, NetworkInterface, Result, ServiceType, TxtRecord}; #[cfg(target_vendor = "pc")] use bonjour_sys::sockaddr_in; use bonjour_sys::{DNSServiceErrorType, DNSServiceFlags, DNSServiceRef}; -#[cfg(target_vendor = "apple")] +#[cfg(any(target_vendor = "apple", target_os = "freebsd"))] use libc::sockaddr_in; use libc::{c_char, c_uchar, c_void}; use std::any::Any; @@ -308,7 +308,7 @@ unsafe fn handle_get_address_info( let port: u16 = ctx.resolved_port.to_be(); // on macOS the bytes are swapped for the ip - #[cfg(target_vendor = "apple")] + #[cfg(any(target_vendor = "apple", target_os = "freebsd"))] let ip = { let address = address as *const sockaddr_in; assert_not_null!(address); diff --git a/zeroconf/src/ffi/mod.rs b/zeroconf/src/ffi/mod.rs index 6ff1458..ad03124 100644 --- a/zeroconf/src/ffi/mod.rs +++ b/zeroconf/src/ffi/mod.rs @@ -51,7 +51,7 @@ impl UnwrapMutOrNull for Option<*mut T> { } } -#[cfg(target_vendor = "apple")] +#[cfg(any(target_vendor = "apple", target_os = "freebsd"))] pub(crate) mod bonjour { use crate::Result; use libc::{fd_set, suseconds_t, time_t, timeval}; diff --git a/zeroconf/src/lib.rs b/zeroconf/src/lib.rs index a0c7b42..a1a655c 100644 --- a/zeroconf/src/lib.rs +++ b/zeroconf/src/lib.rs @@ -194,7 +194,7 @@ extern crate derive_builder; extern crate zeroconf_macros; #[cfg(target_os = "linux")] extern crate avahi_sys; -#[cfg(any(target_vendor = "apple", target_vendor = "pc"))] +#[cfg(any(target_vendor = "apple", target_vendor = "pc", target_os = "freebsd"))] extern crate bonjour_sys; #[macro_use] extern crate derive_getters; @@ -225,7 +225,7 @@ pub mod txt_record; #[cfg(target_os = "linux")] pub mod avahi; -#[cfg(any(target_vendor = "apple", target_vendor = "pc"))] +#[cfg(any(target_vendor = "apple", target_vendor = "pc", target_os = "freebsd"))] pub mod bonjour; pub use browser::{BrowserEvent, ServiceBrowserCallback, ServiceDiscovery, ServiceRemoval}; @@ -237,21 +237,21 @@ pub use service_type::*; #[cfg(target_os = "linux")] pub type MdnsBrowser = avahi::browser::AvahiMdnsBrowser; /// Type alias for the platform-specific mDNS browser implementation -#[cfg(any(target_vendor = "apple", target_vendor = "pc"))] +#[cfg(any(target_vendor = "apple", target_vendor = "pc", target_os = "freebsd"))] pub type MdnsBrowser = bonjour::browser::BonjourMdnsBrowser; /// Type alias for the platform-specific mDNS service implementation #[cfg(target_os = "linux")] pub type MdnsService = avahi::service::AvahiMdnsService; /// Type alias for the platform-specific mDNS service implementation -#[cfg(any(target_vendor = "apple", target_vendor = "pc"))] +#[cfg(any(target_vendor = "apple", target_vendor = "pc", target_os = "freebsd"))] pub type MdnsService = bonjour::service::BonjourMdnsService; /// Type alias for the platform-specific structure responsible for polling the mDNS event loop #[cfg(target_os = "linux")] pub type EventLoop = avahi::event_loop::AvahiEventLoop; /// Type alias for the platform-specific structure responsible for polling the mDNS event loop -#[cfg(any(target_vendor = "apple", target_vendor = "pc"))] +#[cfg(any(target_vendor = "apple", target_vendor = "pc", target_os = "freebsd"))] pub type EventLoop = bonjour::event_loop::BonjourEventLoop; /// Type alias for the platform-specific structure responsible for storing and accessing TXT @@ -260,7 +260,7 @@ pub type EventLoop = bonjour::event_loop::BonjourEventLoop; pub type TxtRecord = avahi::txt_record::AvahiTxtRecord; /// Type alias for the platform-specific structure responsible for storing and accessing TXT /// record data -#[cfg(any(target_vendor = "apple", target_vendor = "pc"))] +#[cfg(any(target_vendor = "apple", target_vendor = "pc", target_os = "freebsd"))] pub type TxtRecord = bonjour::txt_record::BonjourTxtRecord; /// Result type for this library