From 08a68030300687149e757957ea1d8ca23861284e Mon Sep 17 00:00:00 2001 From: hjp Date: Tue, 22 Jan 2002 15:24:09 +0000 Subject: [PATCH] Write both hex and char representation side by side. Replace non-printing chars by ".". use strict; use locale; in short: Almost completely new :-) --- tcpdump_tools/tcpdump2ascii | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tcpdump_tools/tcpdump2ascii b/tcpdump_tools/tcpdump2ascii index da750ad..3161997 100755 --- a/tcpdump_tools/tcpdump2ascii +++ b/tcpdump_tools/tcpdump2ascii @@ -1,15 +1,22 @@ -#!/usr/bin/perl +#!/usr/bin/perl -w +use strict; +use POSIX; +use locale; + +$| = 1; while(<>) { if (/^\t\t\t( [0-9a-f]{2,4})+$/) { - @hex = split; - foreach $i (@hex) { - @c = pack("H4", $i); - foreach $j (@c) { - print "$j"; + chomp; + my @hex = split; + my $line = "$_ "; + foreach my $i (@hex) { + my @c = pack("H4", $i); + foreach my $j (split(//, "@c")) { + $line .= isprint($j) ? "$j" : "."; } } - print "\n"; + print "$line\n"; } else { print }