How do I turn on nanosecond precision when capturing live traffic?

Richard Hansen

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:

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_HOSThost: 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_LOWPREChost_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_HIPREChost_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 than PCAP_TSTAMP_HOST_LOWPREC.
  • PCAP_TSTAMP_ADAPTERadapter: 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_UNSYNCEDadapter_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?

user862787

pcap_create() does little if anything to set parameters for the capture device, and has no alternative calls for setting those parameters; this is by design. The intent, at the time pcap_create() and pcap_activate() were introduced, was that neither of those calls would have to be changed in order to support new parameters, and that new APIs would be introduced as new parameters are introduced.

You're supposed to call pcap_create() to create a not-yet-activated handle, set the parameters with the appropriate calls, and then attempt to activate the handle with pcap_activate().

One of the appropriate calls is pcap_set_tstamp_precision(), which is the call you use between pcap_create() and pcap_activate() to specify that you want nanosecond-precision time stamps. The default is microsecond-precision time stamps, for backwards source and binary compatibility.

Note that pcap_set_tstamp_precision() will fail if you can't get nanosecond-precision time stamps from the device on which you're capturing, so you must check whether it succeeds or fails or call pcap_get_tstamp_precision() after activating the pcap_t in order to see what time stamp precision you'll be getting.

And, no, "high-precision" has nothing to do with whether you get microseconds or nanoseconds, it has to do with whether the nominal microseconds or nanoseconds value really provide microsecond or nanosecond granularity or whether you'll always get values that are multiples of a power of 10 because the clock being used doesn't measure down to the microsecond or nanosecond.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How do I turn off the annoying clicking sound when browsing web pages in Internet Explorer?

분류에서Dev

How do I view my website traffic for a GAE product?

분류에서Dev

How do I turn off all the password prompts?

분류에서Dev

How do I turn on sticky keys from the CLI?

분류에서Dev

How do I turn on advanced telemetry in an AIR app?

분류에서Dev

How do I install the latest TeX Live 2012?

분류에서Dev

How do I set up a local SOCKS proxy that tunnels traffic through SSH?

분류에서Dev

How to turn off the boot up beep of Ubuntu Live USB?

분류에서Dev

How do I turn off bullet list formatting all of the lines to bullet lists in Word 2013?

분류에서Dev

How do I turn on the Volume system icon without uninstalling my audio driver?

분류에서Dev

My Toshiba Satellite C55-B5319 fans will not turn on; how do I make them work?

분류에서Dev

How do I set up live audio streams to a DLNA compliant device?

분류에서Dev

How do I get my USB back to its original settings after using as a live usb?

분류에서Dev

Do I need to open a specific port on an OpenVPN server for torrent traffic

분류에서Dev

Fiddler capturing traffic from a specific process stopped working in Chrome

분류에서Dev

How can I capture the outgoing traffic from a Bridge?

분류에서Dev

How do I turn "www.example.com/test.html" to "www.example.com/test" ? (.htaccess)

분류에서Dev

How do I turn off the little CTRL-SHIFT bubble that pops up on Windows 7 around my cursor?

분류에서Dev

How do I output a button and a text when I hover on an image? Do I need to use JQuery?

분류에서Dev

How do I set the computer to suspend when battery is critically low?

분류에서Dev

How do I continue even when a function errors?

분류에서Dev

How do I ensure that the right ViewController is loaded when accepting a file?

분류에서Dev

How do I change the default domain when browsing Windows shares?

분류에서Dev

How do I get a CR/LF when setting textContent?

분류에서Dev

How do I send values with POST when redirecting in Perl?

분류에서Dev

How do I catch json parse error when using acceptWithActor?

분류에서Dev

How do I enable a button when fields are filled in?

분류에서Dev

How do I run function in vala asynchronously when a button is clicked

분류에서Dev

How do I skip a listview row when saving into the Database?

Related 관련 기사

  1. 1

    How do I turn off the annoying clicking sound when browsing web pages in Internet Explorer?

  2. 2

    How do I view my website traffic for a GAE product?

  3. 3

    How do I turn off all the password prompts?

  4. 4

    How do I turn on sticky keys from the CLI?

  5. 5

    How do I turn on advanced telemetry in an AIR app?

  6. 6

    How do I install the latest TeX Live 2012?

  7. 7

    How do I set up a local SOCKS proxy that tunnels traffic through SSH?

  8. 8

    How to turn off the boot up beep of Ubuntu Live USB?

  9. 9

    How do I turn off bullet list formatting all of the lines to bullet lists in Word 2013?

  10. 10

    How do I turn on the Volume system icon without uninstalling my audio driver?

  11. 11

    My Toshiba Satellite C55-B5319 fans will not turn on; how do I make them work?

  12. 12

    How do I set up live audio streams to a DLNA compliant device?

  13. 13

    How do I get my USB back to its original settings after using as a live usb?

  14. 14

    Do I need to open a specific port on an OpenVPN server for torrent traffic

  15. 15

    Fiddler capturing traffic from a specific process stopped working in Chrome

  16. 16

    How can I capture the outgoing traffic from a Bridge?

  17. 17

    How do I turn "www.example.com/test.html" to "www.example.com/test" ? (.htaccess)

  18. 18

    How do I turn off the little CTRL-SHIFT bubble that pops up on Windows 7 around my cursor?

  19. 19

    How do I output a button and a text when I hover on an image? Do I need to use JQuery?

  20. 20

    How do I set the computer to suspend when battery is critically low?

  21. 21

    How do I continue even when a function errors?

  22. 22

    How do I ensure that the right ViewController is loaded when accepting a file?

  23. 23

    How do I change the default domain when browsing Windows shares?

  24. 24

    How do I get a CR/LF when setting textContent?

  25. 25

    How do I send values with POST when redirecting in Perl?

  26. 26

    How do I catch json parse error when using acceptWithActor?

  27. 27

    How do I enable a button when fields are filled in?

  28. 28

    How do I run function in vala asynchronously when a button is clicked

  29. 29

    How do I skip a listview row when saving into the Database?

뜨겁다태그

보관