The Timestamp is in the packet header - here is a code snippet that I use as a callback to Net::Pcap::loop - this should help to get you started, including obtaining the timestamp:
sub process_pkt {
my($user, $hdr, $pkt) = @_;
my $currentmac = 0; # Client mac unidentified.(init)
warn ("Bad user data\n"), if ($user ne "abc");
warn("Bad pkthdr\n"), if (!defined($hdr));
warn("Bad pkt data\n"), if (!defined($pkt));
my ($sec,$min,$hour) =localtime($hdr->{tv_sec});
my $len= $hdr->{len};
my $buf;
my $eth_obj = NetPacket::Ethernet->decode($pkt);
#print("$eth_obj->{src_mac}:$eth_obj->{dest_mac} " .
# "$Ethernet_Type_Name{$eth_obj->{type}} \n");
$buf = sprintf("%02d:%02d:%02d.%03d[%4d] ",
$hour,$min,$sec, $hdr->{tv_usec} / 1000,$hdr->{len});
return unless $eth_obj->{type} == ETH_TYPE_IP; # Only Handle IP4
Decode_IP( $eth_obj,\$buf, $hdr);
$count++;
}
"For every complex problem, there is a simple answer ... and it is wrong." --H.L. Mencken
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.