From a43fb222e9ddfcdb0d07f8a53da65dcfd3eb067d Mon Sep 17 00:00:00 2001 From: qiujiangkun Date: Thu, 1 Jul 2021 22:22:44 +0800 Subject: [PATCH] pcap timestamp bugfix --- src/phy/pcap_writer.rs | 2 +- src/time.rs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/phy/pcap_writer.rs b/src/phy/pcap_writer.rs index 2d96fb3..03fee45 100644 --- a/src/phy/pcap_writer.rs +++ b/src/phy/pcap_writer.rs @@ -73,7 +73,7 @@ pub trait PcapSink { assert!(length <= 65535); self.write_u32(timestamp.secs() as u32); // timestamp seconds - self.write_u32(timestamp.millis() as u32); // timestamp microseconds + self.write_u32(timestamp.micros() as u32); // timestamp microseconds self.write_u32(length as u32); // captured length self.write_u32(length as u32); // original length } diff --git a/src/time.rs b/src/time.rs index ebf13d3..d2f0cc1 100644 --- a/src/time.rs +++ b/src/time.rs @@ -59,6 +59,12 @@ impl Instant { self.millis % 1000 } + /// The fractional number of microseconds that have passed + /// since the beginning of time. + pub const fn micros(&self) -> i64 { + self.millis % 1000 * 1000 + } + /// The number of whole seconds that have passed since the /// beginning of time. pub const fn secs(&self) -> i64 {