Your example on my system also produced similar results. But, using "alarm" function in my packet count program as shown below, had similar random results.

#!/usr/bin/perl -w use strict; use English; use Net::Pcap; use Time::HiRes qw (alarm time ); my($dev, $pcap_t, $err); $dev = Net::Pcap::lookupdev(\$err); $pcap_t = Net::Pcap::open_live($dev, 1500, 1, 0, \$err); my $count = 0; sub process_pkt { my ( $user_data, $hdr, $pkt ) = @_; $count++; $SIG{ALRM} = sub { printf ("%16.5f %d\n", time, $count); $count = +0 }; # setitimer(ITIMER_REAL, 0.5, 0.5); alarm(0.5); } Net::Pcap::loop( $pcap_t, 0, \&process_pkt, "argument"); Net::Pcap::close($pcap_t);


1069653942.70856 6
1069653948.50819 69
1069653949.46479 2
1069653952.55703 4
1069654021.47634 6
1069654026.47576 4
1069654147.79127 2
1069654173.53735 6
1069654174.43908 2

probably, both packet capturing and alarming are too much for perl, to do it precisely the way we want.

Can you please elaborate on "printing packets/second". Net::Pcap doesn't seem to have any function that would capture packets in regular intervals of time. Any help about how I can get "no of packets/second" will be very helpful.

Thanks,
prakash.


In reply to Re: Re: IP Packet count at regular intervals of time by prakashrj
in thread IP Packet count at regular intervals of time by prakashrj

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.