Debian Codegraph @

src/raw_socket/macos.rs

raw symbols SCIP
1 use crate::cerr;
2
3 use super::RawSocket;
4
5 impl RawSocket {
6 pub(crate) fn so_timestamp(&self, options: u32) -> std::io::Result<()> {
7 // Documentation on the timestamping calls:
8 //
9 // - linux: https://www.kernel.org/doc/Documentation/networking/timestamping.txt
10 // - freebsd: https://man.freebsd.org/cgi/man.cgi?setsockopt
11 //
12 // SAFETY:
13 //
14 // - the socket is provided by (safe) rust, and will outlive the call
15 // - method is guaranteed to be a valid "name" argument
16 // - the options pointer outlives the call
17 // - the `option_len` corresponds with the options pointer
18 //
19 // Only some bits are valid to set in `options`, but setting invalid bits is
20 // perfectly safe
21 //
22 // > Setting other bit returns EINVAL and does not change the current state.
23 unsafe {
24 cerr(libc::setsockopt(
25 self.fd,
26 libc::SOL_SOCKET,
27 libc::SO_TIMESTAMP,
28 &options as *const _ as *const libc::c_void,
29 std::mem::size_of_val(&options) as libc::socklen_t,
30 ))
31 }?;
32
33 Ok(())
34 }
35 }