Hardware Timestamps in Wireshark with SocketCAN

This forum covers PCAN-Linux and Linux development issues concerning our products
Post Reply
ckeydel
Posts: 26
Joined: Thu 4. Nov 2010, 16:06

Hardware Timestamps in Wireshark with SocketCAN

Post by ckeydel » Mon 17. Mar 2025, 21:12

Hello Guys,

For a research project we want to write a Wireshark protocol interpreter and need to have access to accurate hardware timestamps. I've seen this but am not familiar with the inner workings of Wireshark. Do you have any idea how to get access to the stamp[2] value in Wireshark?

Cheers,
Chris

User avatar
S.Grosjean
Software Development
Software Development
Posts: 357
Joined: Wed 4. Jul 2012, 17:02

Re: Hardware Timestamps in Wireshark with SocketCAN

Post by S.Grosjean » Wed 19. Mar 2025, 14:14

Hi,

If you're asking to get the so-called "hardware timestamp" from socket-CAN API, then the socket application has to set the corresponding socket option, something like:

Code: Select all

int flags = SOF_TIMESTAMPING_SOFTWARE |
            SOF_TIMESTAMPING_RX_SOFTWARE |
            SOF_TIMESTAMPING_RAW_HARDWARE;
setsockopt(s, SOL_SOCKET, SO_TIMESTAMPING, &flags, sizeof(flags));
Then, you should check your CMSG list on rx side with:

Code: Select all

if (cmsg->cmsg_type == SO_TIMESTAMPING) {
      struct timespec *stamp = (struct timespec *)CMSG_DATA(cmsg);
stamp[2] is the raw hardware timestamp.

(see also chapter 2.2. Receive timestamps in linux/Documentation/networking/timestamping.txt)

But... I admit, this has nothing to do with Wireshark and we actually don't absolutely know how a Wireshark plug-in could sniff these data structures.

Regards,
— Stéphane

Post Reply