#!/usr/bin/perl

system("/usr/sbin/tcpdump -r capture.dat > capture.txt");
open(IN, "capture.txt");
$i=0;
$j=0;
while (<IN>) {
   
   if (/icmp: echo request/) {
      $time=getTime($_);
      $depart[$i]=$time*1000000;
      $i++;
   } 
   if (/icmp: echo reply/) {
      $time=getTime($_);
      $arrive[$j]=$time*1000000;  
      $j++;
   } 
}
for ($j=0; $j<$i; $j++) {
   print "departTime[$j]=$depart[$j]  arriveTime[$j]=$arrive[$j]\n";
}
print "\n";
for ($j=0; $j<$i-1; $j++) {
   $departTimeGap[$j] = $depart[$j+1]-$depart[$j];
   $arriveTimeGap[$j] = $arrive[$j+1]-$arrive[$j];
   print "departTimeGap[$j]=$departTimeGap[$j] arriveTimeGap[$j]=$arriveTimeGap[$j]\n";
}
print "\n";
for ($j=0; $j<$i; $j++) {
   $processTimeGap[$j] = $arrive[$j]-$depart[$j];
   print "processTimeGap[$j]=$processTimeGap[$j]\n";
}
print "\n";
for ($j=0; $j<$i-1; $j++) {
   $timeGapChange[$j] = $departTimeGap[$j] - $arriveTimeGap[$j];
   print "timeGapChange[$j]=$timeGapChange[$j]\n";
}



sub getTime() {
   my ($line) = @_;
   print "line=$line\n";
   @fields=split(/ /, $line);
   @tfields=split(/:/, $fields[0]);
   print "seconds=$tfields[2]\n";
   return $tfields[2];
}
