[Openswan dev] ikeping reports wrong percentage of lost packets

Mark-Andre Hopf mhopf at innominate.com
Wed Apr 25 11:05:47 EDT 2007


Hello.

We just saw that 'ikeping' reports a wrong percentage of lost packets:

-----------------------------------------------------------------------------
Sending packet to 192.168.1.1/500
received 5() packet from 192.168.1.1/500 of len: 40
        rcookie=67c66973_51ff4aec icookie=29cdbaab_f2fbe346 msgid=00000000
        np=011  version=1.0    xchg=(5)
1 packets sent, 1 packets received. 100 packet loss
-----------------------------------------------------------------------------

The patch below will fix the calculation and appends a percent glyph after
the calculated number:

--- ikeping.c.orig      2007-04-25 16:37:03.000000000 +0200
+++ ikeping.c   2007-04-25 16:48:53.000000000 +0200
@@ -505,10 +505,10 @@
          }
   }
 
-  if(numReceived > 0) {
-    printf("%d packets sent, %d packets received. %d packet loss\n",
-          numSenders, numReceived, numSenders*100/numReceived);
-  }
+  printf("%d packets sent, %d packets received. %d%% packet loss\n",
+        numSenders, 
+        numReceived,
+   numSenders > 0 ? 100-numReceived*100/numSenders : 0);
   exit(0);
 }

-- 
mark-andre.hopf at innominate.com
senior software engineer           innominate security technologies AG
development                             protecting industrial networks
tel: +49.30.6392-3284  fax: -3307                http://innominate.com


More information about the Dev mailing list