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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**/target
tmp
4 changes: 2 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "3"
members = [
"zeroconf",
"zeroconf-macros",
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "zeroconf-browser-example"
version = "0.1.0"
authors = ["Walker Crouse <walkercrouse@hotmail.com>"]
edition = "2018"
edition = "2024"

[dependencies]
zeroconf = { path = "../../zeroconf" }
Expand Down
2 changes: 1 addition & 1 deletion examples/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "zeroconf-service-example"
version = "0.1.0"
authors = ["Walker Crouse <walkercrouse@hotmail.com>"]
edition = "2018"
edition = "2024"

[dependencies]
zeroconf = { path = "../../zeroconf" }
Expand Down
4 changes: 2 additions & 2 deletions zeroconf-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "zeroconf-macros"
version = "0.1.4"
version = "0.2.0"
authors = ["Walker Crouse <walkercrouse@hotmail.com>"]
edition = "2018"
edition = "2024"
description = "Macros for zeroconf crate"
readme = "../README.md"
homepage = "https://github.com/windy1/zeroconf-rs"
Expand Down
16 changes: 8 additions & 8 deletions zeroconf-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ fn impl_from_raw(ast: &DeriveInput) -> TokenStream {
let name = &ast.ident;
let generics = &ast.generics;

let gen = quote! {
let result = quote! {
impl #generics crate::ffi::FromRaw<#name #generics> for #name #generics {}
};

gen.into()
result.into()
}

#[proc_macro_derive(CloneRaw)]
Expand All @@ -29,11 +29,11 @@ fn impl_clone_raw(ast: &DeriveInput) -> TokenStream {
let name = &ast.ident;
let generics = &ast.generics;

let gen = quote! {
let result = quote! {
impl #generics crate::ffi::CloneRaw<#name #generics> for #name #generics {}
};

gen.into()
result.into()
}

#[proc_macro_derive(AsRaw)]
Expand All @@ -45,11 +45,11 @@ fn impl_as_raw(ast: &DeriveInput) -> TokenStream {
let name = &ast.ident;
let generics = &ast.generics;

let gen = quote! {
let result = quote! {
impl #generics crate::ffi::AsRaw for #name #generics {}
};

gen.into()
result.into()
}

#[proc_macro_derive(BuilderDelegate)]
Expand All @@ -65,9 +65,9 @@ fn impl_builder_delegate(ast: &DeriveInput) -> TokenStream {

let generics = &ast.generics;

let gen = quote! {
let result = quote! {
impl #generics crate::prelude::BuilderDelegate<#builder #generics> for #name #generics {}
};

gen.into()
result.into()
}
6 changes: 3 additions & 3 deletions zeroconf/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "zeroconf"
version = "0.16.0"
version = "0.17.0"
authors = ["Walker Crouse <walkercrouse@hotmail.com>"]
edition = "2018"
edition = "2024"
description = "cross-platform library that wraps ZeroConf/mDNS implementations like Bonjour or Avahi"
readme = "../README.md"
homepage = "https://github.com/windy1/zeroconf-rs"
Expand All @@ -25,7 +25,7 @@ derive_builder = "0.9.0"
derive-new = "0.5.9"
log = "0.4.20"
libc = "0.2.148"
zeroconf-macros = { path = "../zeroconf-macros", version = "0.1.4" }
zeroconf-macros = { path = "../zeroconf-macros", version = "0.2.0" }

[dev-dependencies]
env_logger = "0.10.0"
Expand Down
38 changes: 22 additions & 16 deletions zeroconf/src/avahi/avahi_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use crate::ffi::c_str;
use avahi_sys::{
avahi_address_snprint, avahi_alternative_service_name, avahi_strerror, AvahiAddress,
AvahiClient,
AvahiAddress, AvahiClient, avahi_address_snprint, avahi_alternative_service_name,
avahi_strerror,
};
use libc::c_char;
use std::ffi::CStr;
Expand All @@ -22,11 +22,13 @@ pub unsafe fn avahi_address_to_string(addr: *const AvahiAddress) -> String {

let addr_str = c_string!(alloc(avahi_sys::AVAHI_ADDRESS_STR_MAX as usize));

avahi_address_snprint(
addr_str.as_ptr() as *mut c_char,
avahi_sys::AVAHI_ADDRESS_STR_MAX as usize,
addr,
);
unsafe {
avahi_address_snprint(
addr_str.as_ptr() as *mut c_char,
avahi_sys::AVAHI_ADDRESS_STR_MAX as usize,
addr,
);
}

String::from(c_str::to_str(&addr_str))
.trim_matches(char::from(0))
Expand All @@ -38,17 +40,19 @@ pub unsafe fn avahi_address_to_string(addr: *const AvahiAddress) -> String {
/// # Safety
/// This function is unsafe because of internal Avahi calls.
pub unsafe fn get_error<'a>(code: i32) -> &'a str {
CStr::from_ptr(avahi_strerror(code))
.to_str()
.expect("could not fetch Avahi error string")
unsafe {
CStr::from_ptr(avahi_strerror(code))
.to_str()
.expect("could not fetch Avahi error string")
}
}

/// Returns the last error message associated with the specified `*mut AvahiClient`.
///
/// # Safety
/// This function is unsafe because of internal Avahi calls.
pub unsafe fn get_last_error<'a>(client: *mut AvahiClient) -> &'a str {
get_error(avahi_sys::avahi_client_errno(client))
unsafe { get_error(avahi_sys::avahi_client_errno(client)) }
}

/// Converts the specified [`NetworkInterface`] to the Avahi expected value.
Expand Down Expand Up @@ -77,7 +81,7 @@ pub unsafe fn sys_exec<F: FnOnce() -> i32>(func: F, message: &str) -> Result<()>
let err = func();

if err < 0 {
Err(format!("{}: `{}`", message, get_error(err)).into())
Err(format!("{}: `{}`", message, unsafe { get_error(err) }).into())
} else {
Ok(())
}
Expand All @@ -98,7 +102,9 @@ pub fn format_browser_type(service_type: &ServiceType) -> String {
}

if sub_types.len() > 1 {
warn!("browsing by multiple sub-types is not supported on Avahi devices, using first sub-type only");
warn!(
"browsing by multiple sub-types is not supported on Avahi devices, using first sub-type only"
);
}

format_sub_type(&sub_types[0], &kind)
Expand All @@ -119,15 +125,15 @@ pub fn format_sub_type(sub_type: &str, kind: &str) -> String {
/// # Safety
/// This function is unsafe because of the call to `avahi_alternative_service_name`.
pub unsafe fn alternative_service_name(name: &CStr) -> &CStr {
CStr::from_ptr(avahi_alternative_service_name(name.as_ptr()))
unsafe { CStr::from_ptr(avahi_alternative_service_name(name.as_ptr())) }
}

#[cfg(test)]
mod tests {
use super::*;
use avahi_sys::{
AvahiAddress__bindgen_ty_1, AvahiIPv4Address, AvahiIPv6Address, AVAHI_PROTO_INET,
AVAHI_PROTO_INET6,
AVAHI_PROTO_INET, AVAHI_PROTO_INET6, AvahiAddress__bindgen_ty_1, AvahiIPv4Address,
AvahiIPv6Address,
};

#[test]
Expand Down
Loading
Loading