Fellow Monks
I have a script that parses a pcap dump file using net::pcap.
while (1) {
my $hdr;
my $len = read $handle, $hdr, $PKT_HDR_LEN;
die "read failed: $!\n" if not defined $len;
return undef if $len == 0;
$TotalPkts++;
my @vals = unpack "LLLL", $hdr;
$pkt{secs} = $vals[0];
$pkt{usecs} = $vals[1];
$pkt{stamp} = ($vals[0] * 1.0) + ($vals[1] / 1000000);
$pkt{len} = $vals[3];
$len = read $handle, $data, $vals[2];
die "read failed: $!\n" if not defined $len;
die "file truncated: $!\n" if $len < $vals[2];
my $ipdata = eth_strip($data);
$ip = NetPacket::IP->decode($ipdata);
if ($$ip{proto} == 47) {
$is_ce = ($$ip{tos} & 3 == 3);
$ipdata = NetPacket::IP::strip($ipdata);
$ipdata = substr $ipdata, 4;
my $gre = NetPacket::IP->decode($ipdata);
next if $$gre{src_ip} ne $ip1 && $$gre{src_ip} ne $ip2;
$ip = $gre;
}
This seems to take quite a long time to complete. I was wondering if anyone else had seen this problem, and found a more efficient solution
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.