X-Git-Url: https://code.octet-stream.net/netwatcher/blobdiff_plain/846b618fe219c44dfc7b3a13aadace2198442c9c..0fdfcccec1a2e6cbd70ec47a57a255fbe1e285e0:/src/imp_mac.rs?ds=inline diff --git a/src/imp_mac.rs b/src/imp_mac.rs index c4fc8d6..4ae0fc7 100644 --- a/src/imp_mac.rs +++ b/src/imp_mac.rs @@ -1,5 +1,7 @@ use std::{collections::HashMap, net::IpAddr}; +use block2::Block; +use nix::libc::c_long; use nix::{ifaddrs::getifaddrs, net::if_::if_nametoindex}; use crate::util::format_mac; @@ -60,6 +62,31 @@ pub(crate) fn list_interfaces() -> Result, Error> { Ok(ifs) } +// The "objc2" project aims to provide bindings for all frameworks but Network.framework +// isn't ready yet so let's kick it old-school + +struct nw_path_monitor; +type nw_path_monitor_t = *mut nw_path_monitor; +struct nw_path; +type nw_path_t = *mut nw_path; +struct dispatch_queue; +type dispatch_queue_t = *mut dispatch_queue; +const QOS_CLASS_BACKGROUND: usize = 0x09; + +#[link(name = "Network", kind = "framework")] +extern "C" { + fn nw_path_monitor_create() -> nw_path_monitor_t; + fn nw_path_monitor_set_update_handler( + monitor: nw_path_monitor_t, + update_handler: &Block, + ); + fn nw_path_monitor_set_queue(monitor: nw_path_monitor_t, queue: dispatch_queue_t); + fn nw_path_monitor_start(monitor: nw_path_monitor_t); + fn nw_path_monitor_cancel(monitor: nw_path_monitor_t); + + fn dispatch_get_global_queue(identifier: usize, flag: usize) -> dispatch_queue_t; +} + #[cfg(test)] mod test { use super::list_interfaces;