#!/bin/sh
# creates tabular listing of sequence numbers sent, alongwith time
# usage: tcptmseq.sh <file.pcap> <srcport> <dstport>
# creates two files src.txt and dst.txt in pwd
# creates src.data, dst.data as <time><TAB><seqno>
# (can be used directly as gnuplot data file)

FILE=$1
SRCPORT=$2
DSTPORT=$3

TMPDATA=/tmp/data.txt
TMPTIME=/tmp/time.txt
TMPSEQ=/tmp/seqnum.txt

tcpdump -Sr $FILE | awk \
	'{ if ( $7 !~ /ack/ ) { print $1, "\t", $3, "\t", $7 } }' \
	 > $TMPDATA
cat $TMPDATA | grep $SRCPORT > src.txt
cat $TMPDATA | grep $DSTPORT > dst.txt
for file in src.txt dst.txt ; do
	name=`basename $file .txt`
	echo $name
	cat $file | cut -f1 | cut -d":" -f3 > $TMPTIME
	cat $file | cut -f3 | cut -d":" -f1 | tr -d ' ' > $TMPSEQ
	paste $TMPTIME $TMPSEQ | tee ${name}.data
	echo
done

