From c4befeb40b9dc19533b67a27f9c639fdfa91cf0b Mon Sep 17 00:00:00 2001 From: shellrow Date: Sun, 9 Aug 2026 17:38:31 +0900 Subject: [PATCH 1/4] fix: make timespec nanosecond conversion portable --- nex-sys/src/unix.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nex-sys/src/unix.rs b/nex-sys/src/unix.rs index 58c92af..623bc06 100644 --- a/nex-sys/src/unix.rs +++ b/nex-sys/src/unix.rs @@ -117,7 +117,7 @@ pub fn timespec_to_duration(ts: libc::timespec) -> Duration { pub fn duration_to_timespec(dur: Duration) -> libc::timespec { libc::timespec { tv_sec: dur.as_secs() as libc::time_t, - tv_nsec: (dur.subsec_nanos() as TvUsecType).into(), + tv_nsec: dur.subsec_nanos() as _, } } From 54e54e90b760be26a3de183ee5e05b0ecde1a1c5 Mon Sep 17 00:00:00 2001 From: shellrow Date: Sun, 9 Aug 2026 17:45:52 +0900 Subject: [PATCH 2/4] fix: address Clippy warnings on Rust 1.97 --- nex-datalink/src/linux.rs | 15 +++------------ nex-datalink/src/pcap.rs | 2 +- nex-packet/src/dns.rs | 6 ++---- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/nex-datalink/src/linux.rs b/nex-datalink/src/linux.rs index 47ce6c9..ebac769 100644 --- a/nex-datalink/src/linux.rs +++ b/nex-datalink/src/linux.rs @@ -293,10 +293,7 @@ impl RawSender for RawSenderImpl { return Some(Err(e)); } } else { - return Some(Err(io::Error::new( - io::ErrorKind::Other, - "Unexpected poll event", - ))); + return Some(Err(io::Error::other("Unexpected poll event"))); } } @@ -349,10 +346,7 @@ impl RawSender for RawSenderImpl { Ok(_) => Some(Ok(())), } } else { - Some(Err(io::Error::new( - io::ErrorKind::Other, - "Unexpected poll event", - ))) + Some(Err(io::Error::other("Unexpected poll event"))) } } } @@ -403,10 +397,7 @@ impl RawReceiver for RawReceiverImpl { Err(e) => Err(e), } } else { - Err(io::Error::new( - io::ErrorKind::Other, - "Unexpected poll event", - )) + Err(io::Error::other("Unexpected poll event")) } } } diff --git a/nex-datalink/src/pcap.rs b/nex-datalink/src/pcap.rs index ebf7b47..b507caa 100644 --- a/nex-datalink/src/pcap.rs +++ b/nex-datalink/src/pcap.rs @@ -183,7 +183,7 @@ impl RawReceiver for RawReceiverImpl { let mut cap = lock_capture(&self.capture)?; match cap.next_packet() { Ok(pkt) => { - self.read_buffer.truncate(0); + self.read_buffer.clear(); self.read_buffer.extend(pkt.data); } Err(e) => return Err(io::Error::other(e)), diff --git a/nex-packet/src/dns.rs b/nex-packet/src/dns.rs index ec0d0ad..c0458d4 100644 --- a/nex-packet/src/dns.rs +++ b/nex-packet/src/dns.rs @@ -733,10 +733,8 @@ impl DnsQueryPacket { if !qname.is_empty() { qname.push('.'); } - match str::from_utf8(&name[offset + 1..offset + 1 + label_len]) { - Ok(label) => qname.push_str(label), - Err(e) => return Err(e), - } + let label = str::from_utf8(&name[offset + 1..offset + 1 + label_len])?; + qname.push_str(label); offset += label_len + 1; } Ok(qname) From e013b53e92bd7ad5088a810efa9956d850ed2461 Mon Sep 17 00:00:00 2001 From: shellrow Date: Sun, 9 Aug 2026 17:51:54 +0900 Subject: [PATCH 3/4] fix: address Linux Clippy warnings --- nex-datalink/src/linux.rs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/nex-datalink/src/linux.rs b/nex-datalink/src/linux.rs index ebac769..3eaae17 100644 --- a/nex-datalink/src/linux.rs +++ b/nex-datalink/src/linux.rs @@ -6,7 +6,6 @@ use crate::bindings::linux; use crate::{RawReceiver, RawSender}; use nex_core::interface::Interface; use nex_core::mac::MacAddr; -use nex_sys; use std::io; use std::mem; use std::sync::Arc; @@ -64,13 +63,13 @@ pub(crate) struct Config { fn poll_timeout_ms(timeout: Option) -> libc::c_int { timeout .map(|to| { - let ms = (to.tv_sec as i64 * 1000) + (to.tv_nsec as i64 / 1_000_000); - ms.clamp(i64::from(libc::c_int::MIN), i64::from(libc::c_int::MAX)) as libc::c_int + let ms = i128::from(to.tv_sec) * 1000 + i128::from(to.tv_nsec) / 1_000_000; + ms.clamp(i128::from(libc::c_int::MIN), i128::from(libc::c_int::MAX)) as libc::c_int }) .unwrap_or(-1) } -impl<'a> From<&'a super::Config> for Config { +impl From<&super::Config> for Config { fn from(config: &super::Config) -> Config { Config { write_buffer_size: config.write_buffer_size, @@ -166,11 +165,11 @@ pub(crate) fn channel(network_interface: &Interface, config: Config) -> io::Resu } as u32; // set defrag flag if fanout.defrag { - typ = typ | linux::PACKET_FANOUT_FLAG_DEFRAG; + typ |= linux::PACKET_FANOUT_FLAG_DEFRAG; } // set rollover flag if fanout.rollover { - typ = typ | linux::PACKET_FANOUT_FLAG_ROLLOVER; + typ |= linux::PACKET_FANOUT_FLAG_ROLLOVER; } // set uniqueid flag -- probably not needed atm. // PACKET_FANOUT_FLAG_UNIQUEID @@ -207,16 +206,12 @@ pub(crate) fn channel(network_interface: &Interface, config: Config) -> io::Resu // live while this same-sized value is copied. send_addr: unsafe { *(send_addr as *const libc::sockaddr_ll) }, send_addr_len: len, - timeout: config - .write_timeout - .map(|to| nex_sys::duration_to_timespec(to)), + timeout: config.write_timeout.map(nex_sys::duration_to_timespec), }); let receiver = Box::new(RawReceiverImpl { socket: fd.clone(), read_buffer: vec![0; config.read_buffer_size], - timeout: config - .read_timeout - .map(|to| nex_sys::duration_to_timespec(to)), + timeout: config.read_timeout.map(nex_sys::duration_to_timespec), }); Ok(super::Channel::Ethernet(sender, receiver)) From 32fd102babbe1b6065bdf0a7afe6e238c92e7701 Mon Sep 17 00:00:00 2001 From: shellrow Date: Sun, 9 Aug 2026 17:57:47 +0900 Subject: [PATCH 4/4] ci: install libpcap for Linux tests --- .github/workflows/rust.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 1de0518..00aadad 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -21,6 +21,10 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Install libpcap + run: | + sudo apt-get update + sudo apt-get install --yes libpcap-dev - uses: dtolnay/rust-toolchain@stable with: components: clippy, rustfmt