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