@@ -198,6 +198,28 @@ pub enum SockProtocol {
198
198
NetlinkCrypto = libc:: NETLINK_CRYPTO ,
199
199
}
200
200
201
+ #[ cfg( any( target_os = "linux" ) ) ]
202
+ libc_bitflags ! {
203
+ /// Configuration flags for `SO_TIMESTAMPING` interface
204
+ ///
205
+ /// For use with [`Timestamping`][sockopt::Timestamping].
206
+ /// [Further reading](https://www.kernel.org/doc/html/latest/networking/timestamping.html)
207
+ pub struct TimestampingFlag : c_uint {
208
+ /// Report any software timestamps when available.
209
+ SOF_TIMESTAMPING_SOFTWARE ;
210
+ /// Report hardware timestamps as generated by SOF_TIMESTAMPING_TX_HARDWARE when available.
211
+ SOF_TIMESTAMPING_RAW_HARDWARE ;
212
+ /// Collect transmiting timestamps as reported by hardware
213
+ SOF_TIMESTAMPING_TX_HARDWARE ;
214
+ /// Collect transmiting timestamps as reported by software
215
+ SOF_TIMESTAMPING_TX_SOFTWARE ;
216
+ /// Collect receiving timestamps as reported by hardware
217
+ SOF_TIMESTAMPING_RX_HARDWARE ;
218
+ /// Collect receiving timestamps as reported by software
219
+ SOF_TIMESTAMPING_RX_SOFTWARE ;
220
+ }
221
+ }
222
+
201
223
libc_bitflags ! {
202
224
/// Additional socket options
203
225
pub struct SockFlag : c_int {
@@ -641,6 +663,11 @@ pub enum ControlMessageOwned {
641
663
/// # }
642
664
/// ```
643
665
ScmTimestamp ( TimeVal ) ,
666
+ /// A set of nanosecond resolution timestamps
667
+ ///
668
+ /// [Further reading](https://www.kernel.org/doc/html/latest/networking/timestamping.html)
669
+ #[ cfg( all( target_os = "linux" ) ) ]
670
+ ScmTimestampsns ( Timestamps ) ,
644
671
/// Nanoseconds resolution timestamp
645
672
///
646
673
/// [Further reading](https://www.kernel.org/doc/html/latest/networking/timestamping.html)
@@ -732,6 +759,18 @@ pub enum ControlMessageOwned {
732
759
Unknown ( UnknownCmsg ) ,
733
760
}
734
761
762
+ /// For representing packet timestamps via `SO_TIMESTAMPING` interface
763
+ #[ cfg( all( target_os = "linux" ) ) ]
764
+ #[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
765
+ pub struct Timestamps {
766
+ /// software based timestamp, usually one containing data
767
+ pub system: TimeSpec ,
768
+ /// legacy timestamp, usually empty
769
+ pub hw_trans: TimeSpec ,
770
+ /// hardware based timestamp
771
+ pub hw_raw: TimeSpec ,
772
+ }
773
+
735
774
impl ControlMessageOwned {
736
775
/// Decodes a `ControlMessageOwned` from raw bytes.
737
776
///
@@ -776,6 +815,18 @@ impl ControlMessageOwned {
776
815
let ts: libc:: timespec = ptr:: read_unaligned( p as * const _) ;
777
816
ControlMessageOwned :: ScmTimestampns ( TimeSpec :: from( ts) )
778
817
}
818
+ #[ cfg( all( target_os = "linux" ) ) ]
819
+ ( libc:: SOL_SOCKET , libc:: SCM_TIMESTAMPING ) => {
820
+ let tp = p as * const libc:: timespec;
821
+ let ts: libc:: timespec = ptr:: read_unaligned( tp) ;
822
+ let system = TimeSpec :: from( ts) ;
823
+ let ts: libc:: timespec = ptr:: read_unaligned( tp. add( 1 ) ) ;
824
+ let hw_trans = TimeSpec :: from( ts) ;
825
+ let ts: libc:: timespec = ptr:: read_unaligned( tp. add( 2 ) ) ;
826
+ let hw_raw = TimeSpec :: from( ts) ;
827
+ let timestamping = Timestamps { system, hw_trans, hw_raw } ;
828
+ ControlMessageOwned :: ScmTimestampsns ( timestamping)
829
+ }
779
830
#[ cfg( any(
780
831
target_os = "android" ,
781
832
target_os = "freebsd" ,
0 commit comments