Time stamp sources of packet capture software using libpcap, such as tcpdump

Source: Internet
Author: User

Tcpdump: Get time-stamp from libpcap, and libpcap get time stamp from OS Kernel

When is a packet time-stamped? How accurate are the time stamps?

Q: When is a packet time-stamped? How accurate are the time stamps?

Tcpdump gets time stamps from libpcap, and libpcap gets them from the OS
Kernel,


So tcpdump-and any other program using libpcap, such
Ethereal or snoop-is at the mercy of the time stamping code in the OS
For time stamps.

In most OSes on which tcpdump and libpcap run, the packet is time
Stamped as part of the process of the network interface's device driver,
Or the networking stack, handling it. This means that the packet is not
Time stamped at the instant that it arrives at the network interface;
After the packet arrives at the network interface, there will be a delay
Until an interrupt is delivered or the network interface is polled
(I. e., the network interface might not interrupt the host immediately-
The driver may be set up to poll the interface if network traffic is
Heavy, to reduce the number of interrupts and process more packets per
Interrupt), and there will be a further delay between the point at which
The interrupt starts being processed and the time stamp is generated.

On Some OSes, such as HP-UX, the OS Kernel does not time stamp
Packet at all; instead, it's time stamped by libpcap at the time it
Reads the packet from the OS kernel, which means that there will be
Even greater delay between the time the packet arrives and the time that
It's time-stamped.

Thus, the packet time stamp is not necessarily a very accurate
Indication of the time it arrived at the machine that captured
Packet.

Why do my time stamps on Linux have only 100 ms resolution?
The timestamp resolution is only Ms instead of 1us.

Q: I'm running tcpdump on Linux; why do my time stamps have
Only 100 ms resolution, rather than 1us resolution?

At least on x86-based machines, Linux can get high-resolution time
Stamps on newer processors with the time stamp counter (TSC) Register;
For example, intel X86 processors, starting with the Pentium Pro, and
Including all x86 processors since then, have had a TSC, and other
Vendors probably added the TSC at some point to their families of x86
Processors.

The Linux kernel must be configured with the config_x86_tsc Option
Enabled in order to use the TSC. Make sure this option is enabled in
Your kernel.

In addition, some Linux distributions may have bugs in their versions
The kernel that cause packets not to be given high-resolution time
Stamps even if the TSC is enabled. See, for example, bug 61111 for red
Hat Linux 7.2. If your distribution has a bug such as this, you may
Have to run a standard kernel from kernel.org in order to get
High-resolution time stamps.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.