@@ -198,6 +198,28 @@ pub enum SockProtocol {
198198 NetlinkCrypto = libc:: NETLINK_CRYPTO ,
199199}
200200
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+
201223libc_bitflags ! {
202224 /// Additional socket options
203225 pub struct SockFlag : c_int {
@@ -641,6 +663,11 @@ pub enum ControlMessageOwned {
641663 /// # }
642664 /// ```
643665 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 ) ,
644671 /// Nanoseconds resolution timestamp
645672 ///
646673 /// [Further reading](https://www.kernel.org/doc/html/latest/networking/timestamping.html)
@@ -732,6 +759,18 @@ pub enum ControlMessageOwned {
732759 Unknown ( UnknownCmsg ) ,
733760}
734761
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+
735774impl ControlMessageOwned {
736775 /// Decodes a `ControlMessageOwned` from raw bytes.
737776 ///
@@ -776,6 +815,18 @@ impl ControlMessageOwned {
776815 let ts: libc:: timespec = ptr:: read_unaligned( p as * const _) ;
777816 ControlMessageOwned :: ScmTimestampns ( TimeSpec :: from( ts) )
778817 }
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+ }
779830 #[ cfg( any(
780831 target_os = "android" ,
781832 target_os = "freebsd" ,
0 commit comments