2 # (C)2002 by IBM Corporation, published under terms of the GPL V2
3 # Author: Holger Smolinski <smolinsk@de.ibm.com>
4 # this file is a wrapper around tcpdump, which provides the capability
5 # for debugging qeth and/or HiperSocket(TM) network interfaces under
6 # Linux for S/390 and zSeries. tcpdump Syntax is preserved.
7 # Bugs: When the input pipe ends the process is not stopped.
13 getopts ("adeflnNOpqRStuvxXc:C:F:i:m:r:s:T:w:E:",\%options);
15 # Check which options to replace for the reader process
16 if ( defined($options{'r'}) ) {
17 $incmd = "cat $options{'r'}";
20 $incmd = "tcpdump -l -w -";
22 if ( defined($options{'i'}) ) {
23 $incmd .= " -i ".$options{'i'};
24 delete $options{'i'}; # remove -i option from option list
26 foreach $key (@ARGV) {
31 $outcmd = "tcpdump -r -";
32 # Rebuild arglist for the writer process
33 delete $options{'r'}; # remove -r option from option list
34 foreach $key (keys %options) {
35 if ((index "adeflnNOpqRStuvxX",$key) >= 0 ) {
38 $outcmd .= " -$key $options{$key}";
40 if ( $filter_out == 1 ) {
41 foreach $key (@ARGV) {
47 open READER,"$incmd|" or die "Cannot spawn reader command $incmd";
48 open WRITER,"|$outcmd" or die "Cannot spawn writer command $outcmd";
50 sysread READER,$filehdr,24 or die "Cannot read file header";
51 ($magic,$version_major,$version_minor,$thiszone,$sigfigs,$snaplen,$linktype) =
52 unpack("ISSIIII",$filehdr);
54 $filehdr = pack ("ISSIIII",($magic,$version_major,$version_minor,$thiszone,$sigfigs,$snaplen,$linktype));
55 syswrite WRITER,$filehdr,24;
57 $etherheaderip6 = pack ("IIIS",(0,0,0,0x8dd));
58 $etherheaderip4 = pack ("IIIS",(0,0,0,0x800));
62 do {$hdrd += sysread READER, $pkthdr, 16-$hdrd, $hdrd; } while ($hdrd < 16);
63 ($seconds,$usecs,$caplen,$len) = unpack ("IIII",$pkthdr);
65 do {$hdrd += sysread READER, $packet,$caplen-$hdrd, $hdrd; } while ($hdrd < $caplen);
66 $paktype = unpack("C",$packet);
67 if ( $paktype & 0xf0 == 0x60 ) {
70 $header = $etehrheaderip6;
71 } elsif ($paktype >= 0x45 && $paktype <= 0x4f ) {
74 $header = $etherheaderip4;
78 $pkthdr = pack ("IIII",($seconds,$usecs,$caplen,$len));
79 syswrite WRITER,"$pkthdr$header$packet",16+$caplen;