#!/usr/bin/perl # $Id$ # view PKT contents # (c) Husky development team # This script reads PKT from stdin and prints it's contents in human-readabe form into stdout # options: # -v verbose # -s print SEEN-BY, PATH and PTH kludges # -r print RFC-* kludges # -p print PID and TID kludges # -h print usage information # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. sub usage{ my @Id = split(/ /,'$Id$'); my $programid="$Id[1] $Id[2]"; undef @Id; print < $destZone:$destNet/$destNode.$destPoint ]\n"; } $div="-----------------------------------------------------------------------------\n"; print $div; while(read(STDIN,$version,2)==2&&($pktver=unpack('S',$version))==2) { die "Broken packet - invalid message header" if(read(STDIN,$hdr,12)!=12); ($origNode,$destNode,$origNet,$destNet,$attr,$cost)=unpack('S6',$hdr); $/="\0"; $dateTime=; chop $dateTime; $ToName=; chop $ToName; $FromName=; chop $FromName; $Subj=; chop $Subj; $Text=; chop $Text; $/="\n"; if(length($dateTime)>19|| length($ToName)>35|| length($FromName)>35|| length($Subj)>71) { print "Warning: Bad field(s) length (too long)\n"; } $Text=~s/\r\n?/\n/gs; $Text.="\n" unless($Text=~/\n$/s); undef $area; if($Text=~/^AREA:\s*(\S+)\n/m) { undef $area if(($area=$1) eq 'NETMAIL'); substr($Text,length($`),length($&))='' unless ($verbose); } if($area) { undef $origAddr; undef $destAddr; } else { $origAddr="$origNet/$origNode"; $destAddr="$destNet/$destNode"; if($Text=~/^\x01INTL:?[ ]+(\d+:\d+\/\d+)[ ]+(\d+:\d+\/\d+)[ ]*\n/m) { $destAddr=$1; $origAddr=$2; substr($Text,length($`),length($&))='' unless ($verbose); } if($Text=~/^\x01FMPT:?[ ]+(\d+)[ ]*\n/m) { $origAddr.=".$1"; substr($Text,length($`),length($&))='' unless ($verbose); } if($Text=~/^\x01TOPT:?[ ]+(\d+)[ ]*\n/m) { $destAddr.=".$1"; substr($Text,length($`),length($&))='' unless ($verbose); } } if(!$origAddr && $Text=~/^ \* Origin:[^\(\n]*\([^0-9\n\)]*(\d+:\d+\/\d+(\.\d+)?)(\@[^\)\n]+)?\)\n/m) { # (\@[^\)\n])?\)\n/m) { $origAddr=$1; } undef $msgid_addr,$msgid_crc; if($Text=~/^\x01MSGID:[ ]*(\S+)[ ]+([0-9a-fA-F]{1,8})[ ]*\n/m) { $pos=length($`); $len=length($&); $msgid_addr=$1; $msgid_crc=hex("0x$2"); # print "Found MSGID:$1|$2|$&|\n"; if($msgid_addr=~m|^(\d+:)?\d+/\d+(\.\d+)?(\@.*$)?|) { $domain=$3; $ldomain=length($domain); substr($msgid_addr,-$ldomain,$ldomain)='' if($domain=~/^\@fidonet(\.org)?$/); } else { $msgid_addr.="($origAddr)" if($origAddr); } $origAddr=$msgid_addr; substr($Text,$pos,$len)='' unless($verbose); } if($noseenby) { $Text=~s/^SEEN-BY:[^\n]*\n//mg; $Text=~s/^\x01PATH:[^\n]*\n//mg; $Text=~s/^\x01PTH:[^\n]*\n//mg; } if($norfc) { $Text=~s/^\x01RFC-[^\n]*\n//mg; } if($nopid) { $Text=~s/^\x01PID:[^\n]*\n//mg; $Text=~s/^\x01TID:[^\n]*\n//mg; } $Text=~s/^\x01/\@/gm; print "From: $FromName, $origAddr\t$dateTime\n"; if($area) { print "To : $ToName\n"; } else { print "To : $ToName, $destAddr\n"; } print "Subj: $Subj\n"; if($verbose) { $attr_str=sprintf("0x%04x-",$attr); } else { $attr_str=''; } $attr_str.=join(' ',getattr($attr)); $div_attr=$div; substr($div_attr,2,length($attr_str))=$attr_str; substr($div_attr,-5-length($area),length($area)+2)="\[$area\]"; print $div_attr; print $Text; print $div; } if($pktversion==0) { print "-------========================Packet Done normally===================-------\n"; exit 0 if(eof(STDIN)); } else { print "-------===========================Broken packet=======================-------\n"; exit 1; } }; __END__