Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
35 changes: 16 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions zeroconf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions zeroconf/src/bonjour/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion zeroconf/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<T> UnwrapMutOrNull<T> 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};
Expand Down
12 changes: 6 additions & 6 deletions zeroconf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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};
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading