viper has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I am implementing the logging function in my sniffer program and I need to log the packets along with the time in epoch seconds. The time function only provides whole seconds, I need more precision; I need to have the milliseconds as well. Thanks for any help you can give me.

Replies are listed 'Best First'.
Re: Time
by lhoward (Vicar) on Aug 19, 2000 at 22:29 UTC
    Since you're writing a sniffer, aparently in Perl, you're almost certainly using Net::Pcap to implement the packet capturing. Why not use the second and microsecond timestamps that Net::Pcap give you with each packet it returns?

    Excerpt from the Net::Pcap docs

    The header information is a reference to a hash containing the following fields. ...
    • tv_sec - Seconds value of the packet timestamp.
    • tv_usec - Microseconds value of the packet timestamp.
    Those should be the packet timestamps from the NIC or your OSes kernel; which should be slightly more accurate than an timestamp generated inside your application.
      Thanks.
Re: Time
by nardo (Friar) on Aug 19, 2000 at 21:41 UTC
RE: Time (CPAN search results)
by ybiC (Prior) on Aug 19, 2000 at 21:53 UTC
    I've not worked with any of these myself, but a quick CPAN search for "time" turns up DateTime::Precise, and Event::timer and Time::HiRes, plus a whole slew of other modules.

    The last one (Time::HiRes) looks most promising.

    Update: Looks like nardo beat me to the punch.   But then, he's right outside the window, so what do you expect? (grin)
        cheers,
        ybiC