How do I tell libpcap v1.6.2 to store nanosecond values in struct pcap_pkthdr::ts.tv_usec
(instead of microsecond values) when capturing live packets?
(Note: This question is similar to How to enable nanosecond resolution when capturing live packets in libpcap? but that question is vague enough that I decided to ask a new question.)
For offline and "dead" captures, the following functions can be used to tell libpcap to fill the struct pcap_pkthdr
's ts.tv_usec
member with nanosecond values:
pcap_open_dead_with_tstamp_precision()
pcap_open_offline_with_tstamp_precision()
pcap_fopen_offline_with_tstamp_precision()
Unfortunately, there does not appear to be _with_tstamp_precision
variants for pcap_open_live()
or pcap_create()
.
I believe that capturing live packets with nanosecond resolution should be possible, because the changelog for v1.5.0 says (emphasis mine):
Add support for getting nanosecond-resolution time stamps when capturing and reading capture files
I did see the pcap_set_tstamp_type()
function and the pcap-tstamp
man page, which says:
PCAP_TSTAMP_HOST
—host
: Time stamp provided by the host on which the capture is being done. The precision of this time stamp is unspecified; it might or might not be synchronized with the host operating system's clock.PCAP_TSTAMP_HOST_LOWPREC
—host_lowprec
: Time stamp provided by the host on which the capture is being done. This is a low-precision time stamp, synchronized with the host operating system's clock.PCAP_TSTAMP_HOST_HIPREC
—host_hiprec
: Time stamp provided by the host on which the capture is being done. This is a high-precision time stamp; it might or might not be synchronized with the host operating system's clock. It might be more expensive to fetch thanPCAP_TSTAMP_HOST_LOWPREC
.PCAP_TSTAMP_ADAPTER
—adapter
: Time stamp provided by the network adapter on which the capture is being done. This is a high-precision time stamp, synchronized with the host operating system's clock.PCAP_TSTAMP_ADAPTER_UNSYNCED
—adapter_unsynced
: Time stamp provided by the network adapter on which the capture is being done. This is a high-precision time stamp; it is not synchronized with the host operating system's clock.
Does the phrase "high-precision time stamp" here mean that nanosecond values are stored in the header's ts.tv_usec
field? If so, PCAP_TSTAMP_HOST
says "unspecified", so how do I determine at runtime whether the ts.tv_usec
field holds microseconds or nanoseconds? And which of these is the default if pcap_set_tstamp_type()
is never called?