Article Figure 1 Figure 2 Listing 1 Listing 2
Listing 3 Listing 4 Listing 5 Listing 6 Listing 7
Listing 8 sep2006.tar

Listing 4 Sample Perl script that uses Net::Pcap

#!/usr/bin/perl

use Net::Pcap;

my $err        = '';
my $total      = 0;

my $pcap = Net::Pcap::open_offline('/tmp/http.pcap', \$err) or die \
  "Can't read '$dump': $err\n";
Net::Pcap::loop($pcap, -1, \&process_packet, "just for the demo");
Net::Pcap::close($pcap);

print "Total = $total\n";

sub process_packet {


       my( $user_data, $header, $packet )    = @_;

       my $len = length( $packet );
       $total  = $total + $len;

       my $i=0;
       do {

        my $lg = substr $packet, $i, 16;
        printf "%.8X : ", $i;
        $i+=16;
        print unpack ('H2'x16, $lg), '  'x(16-length $lg);
        $lg =~ s/[\x00-\x1F\xFF]/./g;
        print " $lg\n";

       } until $i>=$len;
       print "\n";

}