parse_tcpdump_log.pl: Allow calling it via a pipe
authorMauro Carvalho Chehab <mchehab@redhat.com>
Tue, 15 Mar 2011 13:52:47 +0000 (10:52 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Wed, 16 Mar 2011 14:38:20 +0000 (11:38 -0300)
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
contrib/parse_tcpdump_log.pl

index 7f8f56c..5901747 100755 (executable)
@@ -46,7 +46,7 @@ pod2usage(-exitstatus => 0, -verbose => 2) if $man;
 my $filename;
 
 # FIXME: use shift of die, after finishing the tests
-$filename = shift or die "Please specify a file name";
+$filename = shift;
 
 #
 # tcpdump code imported from Tcpdumplog.pm
@@ -510,7 +510,12 @@ sub parse_file($)
 # Main program, reading from a file. A small change is needed to allow it to
 # accept a pipe
 
-open my $fh, "<$filename" || die "ERROR: Can't read log $filename: $!\n";
+my $fh;
+if (!$filename) {
+       $fh = *STDIN;
+} else {
+       open $fh, "<$filename" || die "ERROR: Can't read log $filename: $!\n";
+}
 binmode $fh;
 parse_file $fh;
 #parse_file $fh;
@@ -562,7 +567,11 @@ A typical usage is to call tcpdump with:
 
 after finishing data collection, parse it with:
 
-       $ B<parse_tcpdump_log.pl> usb_device.tcpdump
+       $ parse_tcpdump_log.pl usb_device.tcpdump
+
+it is also possible to use it via pipe, like:
+
+       $ cat usb_device.tcpdump | parse_tcpdump_log.pl
 
 =head1 BUGS