summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
authorLu, Wangshan <wisagan@gmail.com>2021-03-20 22:36:36 +0800
committerLu, Wangshan <wisagan@gmail.com>2021-04-08 10:41:38 +0800
commit830bab64a8615642ea7de69952b5ae122a124285 (patch)
treeb4d07b07e0abb496bbbe94852b1ad02f0bb2f64e /src/sys
parent3f8a66dc69ba3ae4df6a0f3eb879dc30020965bc (diff)
downloadnix-830bab64a8615642ea7de69952b5ae122a124285.zip
Support TIMESTAMPNS for linux
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/socket/mod.rs12
-rw-r--r--src/sys/socket/sockopt.rs2
2 files changed, 14 insertions, 0 deletions
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs
index 2725e57c..6e22274c 100644
--- a/src/sys/socket/mod.rs
+++ b/src/sys/socket/mod.rs
@@ -7,6 +7,8 @@ use libc::{self, c_void, c_int, iovec, socklen_t, size_t,
CMSG_FIRSTHDR, CMSG_NXTHDR, CMSG_DATA, CMSG_LEN};
use std::{mem, ptr, slice};
use std::os::unix::io::RawFd;
+#[cfg(all(target_os = "linux"))]
+use crate::sys::time::TimeSpec;
use crate::sys::time::TimeVal;
use crate::sys::uio::IoVec;
@@ -554,6 +556,11 @@ pub enum ControlMessageOwned {
/// # }
/// ```
ScmTimestamp(TimeVal),
+ /// Nanoseconds resolution timestamp
+ ///
+ /// [Further reading](https://www.kernel.org/doc/html/latest/networking/timestamping.html)
+ #[cfg(all(target_os = "linux"))]
+ ScmTimestampns(TimeSpec),
#[cfg(any(
target_os = "android",
target_os = "ios",
@@ -645,6 +652,11 @@ impl ControlMessageOwned {
let tv: libc::timeval = ptr::read_unaligned(p as *const _);
ControlMessageOwned::ScmTimestamp(TimeVal::from(tv))
},
+ #[cfg(all(target_os = "linux"))]
+ (libc::SOL_SOCKET, libc::SCM_TIMESTAMPNS) => {
+ let ts: libc::timespec = ptr::read_unaligned(p as *const _);
+ ControlMessageOwned::ScmTimestampns(TimeSpec::from(ts))
+ }
#[cfg(any(
target_os = "android",
target_os = "freebsd",
diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs
index fd9a710c..fe17395f 100644
--- a/src/sys/socket/sockopt.rs
+++ b/src/sys/socket/sockopt.rs
@@ -272,6 +272,8 @@ sockopt_impl!(Both, BindToDevice, libc::SOL_SOCKET, libc::SO_BINDTODEVICE, OsStr
#[cfg(any(target_os = "android", target_os = "linux"))]
sockopt_impl!(GetOnly, OriginalDst, libc::SOL_IP, libc::SO_ORIGINAL_DST, libc::sockaddr_in);
sockopt_impl!(Both, ReceiveTimestamp, libc::SOL_SOCKET, libc::SO_TIMESTAMP, bool);
+#[cfg(all(target_os = "linux"))]
+sockopt_impl!(Both, ReceiveTimestampns, libc::SOL_SOCKET, libc::SO_TIMESTAMPNS, bool);
#[cfg(any(target_os = "android", target_os = "linux"))]
sockopt_impl!(Both, IpTransparent, libc::SOL_IP, libc::IP_TRANSPARENT, bool);
#[cfg(target_os = "openbsd")]