]> code.octet-stream.net Git - netwatcher/commitdiff
Move things around
authorThomas Karpiniec <tom.karpiniec@outlook.com>
Sat, 8 Jun 2024 11:32:39 +0000 (21:32 +1000)
committerThomas Karpiniec <tom.karpiniec@outlook.com>
Sat, 8 Jun 2024 11:32:39 +0000 (21:32 +1000)
src/lib.rs
src/list_unix.rs
src/util.rs [deleted file]
src/watch_linux.rs
src/watch_mac.rs

index e7bf15234aaaf92a217e90a7d56c57598fdf93b5..36cbddc7d5037a74bc13d654c7dea42f40aea2cb 100644 (file)
@@ -13,9 +13,6 @@ mod list;
 #[cfg_attr(target_os = "linux", path = "watch_linux.rs")]
 mod watch;
 
 #[cfg_attr(target_os = "linux", path = "watch_linux.rs")]
 mod watch;
 
-#[cfg(unix)]
-mod util;
-
 type IfIndex = u32;
 
 #[derive(Debug, Clone, PartialEq, Eq)]
 type IfIndex = u32;
 
 #[derive(Debug, Clone, PartialEq, Eq)]
index 4ae0fc7c8b6d1053b2f77bc69bc9dc4ec9089db7..a6b2bd3bec616d4237f86801e92b96c13cbcee47 100644 (file)
@@ -1,10 +1,10 @@
+use std::fmt::Write;
 use std::{collections::HashMap, net::IpAddr};
 
 use block2::Block;
 use nix::libc::c_long;
 use nix::{ifaddrs::getifaddrs, net::if_::if_nametoindex};
 
 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;
 use crate::{Error, IfIndex, Interface};
 
 struct CandidateInterface {
 use crate::{Error, IfIndex, Interface};
 
 struct CandidateInterface {
@@ -62,38 +62,13 @@ pub(crate) fn list_interfaces() -> Result<HashMap<IfIndex, Interface>, Error> {
     Ok(ifs)
 }
 
     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<dyn Fn(nw_path_t)>,
-    );
-    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;
-
-    #[test]
-    fn list() {
-        let ifaces = list_interfaces().unwrap();
-        println!("{:?}", ifaces);
+fn format_mac(bytes: &[u8]) -> Result<String, Error> {
+    let mut mac = String::with_capacity(bytes.len() * 3);
+    for i in 0..bytes.len() {
+        if i != 0 {
+            write!(mac, ":").map_err(|_| Error::Internal)?;
+        }
+        write!(mac, "{:02X}", bytes[i]).map_err(|_| Error::Internal)?;
     }
     }
+    Ok(mac)
 }
 }
diff --git a/src/util.rs b/src/util.rs
deleted file mode 100644 (file)
index bbc4e6c..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-use crate::Error;
-use std::fmt::Write;
-
-pub(crate) fn format_mac(bytes: &[u8]) -> Result<String, Error> {
-    let mut mac = String::with_capacity(bytes.len() * 3);
-    for i in 0..bytes.len() {
-        if i != 0 {
-            write!(mac, ":").map_err(|_| Error::Internal)?;
-        }
-        write!(mac, "{:02X}", bytes[i]).map_err(|_| Error::Internal)?;
-    }
-    Ok(mac)
-}
index 74c146558e19ca267bbb63feecf02a7f5dab165f..a987919360fc789c79a3478e19da048d9c47c963 100644 (file)
@@ -1,13 +1,13 @@
-use crate::Update;\r
-use crate::Error;\r
-\r
-pub(crate) struct WatchHandle;\r
-\r
-pub(crate) fn watch_interfaces<F: FnMut(Update) + 'static>(\r
-    callback: F,\r
-) -> Result<WatchHandle, Error> {\r
-    // stop current worker thread\r
-    // post this into a thread that will use it\r
-    drop(callback);\r
-    Ok(WatchHandle)\r
-}\r
+use crate::Error;
+use crate::Update;
+
+pub(crate) struct WatchHandle;
+
+pub(crate) fn watch_interfaces<F: FnMut(Update) + 'static>(
+    callback: F,
+) -> Result<WatchHandle, Error> {
+    // stop current worker thread
+    // post this into a thread that will use it
+    drop(callback);
+    Ok(WatchHandle)
+}
index 96e344bb97795bb495afead5c4024bb042b27d66..ed2879c6feff85a0c57c5fb9c08c3f2e48068df3 100644 (file)
@@ -1,12 +1,48 @@
-use crate::Update;\r
-\r
-pub(crate) struct WatchHandle;\r
-\r
-pub(crate) fn watch_interfaces<F: FnMut(Update) + 'static>(\r
-    callback: F,\r
-) -> Result<WatchHandle, Error> {\r
-    // stop current worker thread\r
-    // post this into a thread that will use it\r
-    drop(callback);\r
-    Ok(WatchHandle)\r
-}\r
+use crate::Update;
+
+// 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<dyn Fn(nw_path_t)>,
+    );
+    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;
+
+    #[test]
+    fn list() {
+        let ifaces = list_interfaces().unwrap();
+        println!("{:?}", ifaces);
+    }
+}
+
+pub(crate) struct WatchHandle;
+
+pub(crate) fn watch_interfaces<F: FnMut(Update) + 'static>(
+    callback: F,
+) -> Result<WatchHandle, Error> {
+    // stop current worker thread
+    // post this into a thread that will use it
+    drop(callback);
+    Ok(WatchHandle)
+}