Accessing unix socket timestamps in Rust

Viewed 142

I am trying to get the NIC hardware receive timestamps for TcpStream messages. I found some code examples in C (https://stackoverflow.com/a/42210708, and https://stackoverflow.com/a/47329376/9518712) but I'm struggling to implement them in Rust.

I also wondered if there is a better abstraction for it through something like socket ancillary data https://doc.rust-lang.org/std/os/unix/net/struct.SocketAncillary.html

I would be grateful for any simple working code examples.

let (mut socket, response) = connect(Url::parse("wss://myurl.com/ws")?)?;

let stream = socket.get_mut();
let tcp_stream = match stream {
    MaybeTlsStream::Rustls(ref s) => &s.sock,
    _ => panic!(),
};
let fd = tcp_stream.as_raw_fd();

let msg = socket.read_message().expect("Error reading message");
println!("Received: {}", msg);

// ??? code to get socket timestamp ???
0 Answers
Related