From fcbf82c86eeee03b137b71068842db58639913bf Mon Sep 17 00:00:00 2001 From: Andrew Rioux Date: Tue, 4 Aug 2026 23:20:06 -0400 Subject: [PATCH] fix: use better timings Linux beacons weren't timing out and attempting to continue driving the connection Windows beacons still get stuck on their first connection, but that is good enough for demonstration purposes --- flake.lock | 6 +++--- pcap-sys/src/lib.rs | 12 ++++++++++-- sparse-beacon/src/socket.rs | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/flake.lock b/flake.lock index b5a6642..d0cf0ed 100644 --- a/flake.lock +++ b/flake.lock @@ -52,13 +52,13 @@ "freebsd-libs-packed": { "flake": false, "locked": { - "narHash": "sha256-l9YQPyra0F4guqiI4rW5XsZxGP1Usy//nglUVFlqY1c=", + "narHash": "sha256-2CAlSeK9dsP6RG9UDZJo2gaxRUdJw/DDTSyJibU2N5c=", "type": "file", - "url": "https://download.freebsd.org/releases/amd64/14.1-RELEASE/base.txz" + "url": "https://download.freebsd.org/releases/amd64/14.3-RELEASE/base.txz" }, "original": { "type": "file", - "url": "https://download.freebsd.org/releases/amd64/14.1-RELEASE/base.txz" + "url": "https://download.freebsd.org/releases/amd64/14.3-RELEASE/base.txz" } }, "libcap-src": { diff --git a/pcap-sys/src/lib.rs b/pcap-sys/src/lib.rs index bd188ef..045b8e1 100644 --- a/pcap-sys/src/lib.rs +++ b/pcap-sys/src/lib.rs @@ -438,9 +438,17 @@ impl WaitHandle { } #[cfg(unix)] - pub async fn wait(&self, _timeout: Option) -> error::Result<()> { + pub async fn wait(&self, timeout: Option) -> error::Result<()> { let async_fd = tokio::io::unix::AsyncFd::new(self.0)?; - let mut guard = async_fd.ready(tokio::io::Interest::READABLE).await?; + let mut guard = match tokio::time::timeout( + timeout.unwrap_or(std::time::Duration::from_millis(50)), + async_fd.ready(tokio::io::Interest::READABLE) + ).await { + Ok(v) => v, + Err(_) => { + return Ok(()) + } + }?; guard.clear_ready(); drop(guard); async_fd.into_inner(); diff --git a/sparse-beacon/src/socket.rs b/sparse-beacon/src/socket.rs index 71d1b1a..06f2a29 100644 --- a/sparse-beacon/src/socket.rs +++ b/sparse-beacon/src/socket.rs @@ -24,7 +24,7 @@ impl RawSocket { let name = std::str::from_utf8(&name_raw)?; let mut lower = Interface::new(name)?; - let mtu = a_interface.mtu as usize - if cfg!(unix) { 14 } else { 0 }; + let mtu = a_interface.mtu as usize - if cfg!(unix) { 28 } else { 0 }; lower.set_promisc(promisc)?; lower.set_buffer_size(mtu as i32)?;