npn
npn

Reputation: 401

Timestamping UDP packets

I'm making an UNIX application where I need to order messages, for which I need to timestamp all outgoing packets. I could use the functions defined in time.h and just append the timestamp to the packet, but it seems Linux already provides a timestamping option in the socket API. What is generally the best way to timestamp a UDP packet?

Upvotes: 2

Views: 5089

Answers (1)

Kaz
Kaz

Reputation: 58500

The Linux-specific timestamping options you can set on sockets do not do what you think they do. In a nutshell, they cause skbuff objects to be attributed with timestamps. The purpose is to get accurate timestamps about when packets were actually sent out and when they arrived. I.e. these stamps are local metadata.

If you need timestamps in the actual communication protocol, you have to add them yourself as another field in the packet format.

Since you say that this is "to order messages", if that is the only purpose, it may be a better idea to stamp packets not with time, but with an incrementing sequence number. Incrementing sequence numbers not only establish order, but also help detect missing packets, which timestamps will not do.

Upvotes: 4

Related Questions