21 my @opt = <<'=back' =~ /B<--(\S+)>/g;
37 use lib
"$FindBin::Bin/../lib";
43 use File
::Basename
qw(dirname);
44 use File
::Path
qw(mkpath);
49 use Hash
::Util
qw(lock_keys);
52 lock_keys
%Opt, map { /([^=|!]+)/ } @opt;
64 my $file = shift @ARGV or die "Usage:...";
65 my $dumper = new Dumpvalue tick
=> "\"";
69 $pc = Net
::Pcap
::open_offline
($file,\
$err);
76 my $open_connections = 0;
86 my(%reverse_portcolor, %open_connections, %startpack);
89 use Time
::HiRes
qw(gettimeofday); { our($cached_t, $cached_ts);sub itms
{ my($t)=shift||[gettimeofday
]; my $ts; if ($cached_ts && $cached_t == $t->[0]){ $ts = $cached_ts; } else { $cached_t = $t->[0]; $cached_ts = $ts = sub { sprintf q{%04d-%02d-%02dT%02d:%02d:%02d}, $_[5]+1900, $_[4] +1,@_[3, 2, 1, 0];}->(localtime $t->[0]); } return sprintf "%s.%06d", $ts, $t->[1];}}
91 my $npe = Net::Pcap::Easy->new
94 packets_per_loop => -1,
96 my ($npe, $ether, $ip, $udp, $header, $packet) = @_;
101 # printf "%8d %-15s %-15s %5d %5d %d\n", $cnt, $ip->{src_ip}, $ip->{dest_ip}, $udp->{src_port}, $udp->{dest_port}, $udp->{data} ? length($udp->{data}) : 0;
104 unless ( $udp->{src_port}==$Opt{port} || $udp->{dest_port}==$Opt{port} ) {
111 my(@dbmdfields) = qw(vers seq type status namelen keylen datalen data);
112 @dbmd{@dbmdfields} = unpack "(N)7 A*", $udp->{data
}; # typedef struct _dbmrsp from rz/lib/rdbm/dbmproto.h
113 $dbmd{data
} = "" if $dbmd{datalen
} == 0 and $dbmd{namelen
} == 0 and $dbmd{keylen
}==0;
115 my $color_on = color
"on_white";
116 if ( ! grep { $udp->{src_port
} == $_ } 201, 203 ) {
117 $color_on = color
"black on_white";
118 } elsif ( $ip->{src_ip
} eq "192.168.96.210") { # effrafax
119 $color_on = color
"black on_magenta";
120 } elsif ( $ip->{src_ip
} eq "192.168.98.210") { # bartlett
121 $color_on = color
"black on_green";
122 } elsif ( $ip->{src_ip
} eq "192.168.96.253") { # greebo
123 $color_on = color
"black on_yellow";
124 } elsif ( $ip->{src_ip
} eq "192.168.100.223") { # deepthought
125 $color_on = color
"bold red on_magenta";
126 } elsif ( $ip->{src_ip
} eq "192.168.100.224") { # eddie
127 $color_on = color
"bold red on_yellow";
128 } elsif ( $ip->{src_ip
} eq "192.168.100.228") { # marvin
129 $color_on = color
"bold red on_green";
131 my $color_off = color
"reset";
132 my @record = map {defined $dbmd{$_} ?
sprintf("%s%-7s %s%s\n", $color_on, $_, $color_off, $dbmd{$_}) : ()} @dbmdfields;
133 my $record = join("", @record);
136 "%sUDP %5d %s %s:%s->%s:%s%s\n%s",
139 itms
([$header->{tv_sec
}, $header->{tv_usec
}]),
150 my ($user_data, $header, $packet) = @_;
151 my $ether = NetPacket
::Ethernet
->decode($packet);
154 return $npe->_ipv4( $ether, NetPacket
::IP
-> decode
($ether->{data
}), $header, $packet);
163 # cperl-indent-level: 4
168 # cperl-indent-level: 4