Hello,

I just discovered a small bug in ping. The macros for accessing the 
bitfields in ping.h and the way they are called results in only one bit 
stored per byte. I assume the desired behavior was to store 8 bits per 
byte. So I hope this patch fixes this small issue. It also removes a 
small piece of orphan code.

Currently I'm working on timestamps generated by hardware or software 
using the SO_TIMESTAMPING socket option introduced with linux 2.6.30.

Are you interested in patches for ping to use this feature? How do you 
think I should implement it?
My plan is to add a ping_tstamp[N] of timespecs to the ping_data 
structure in which I will store the transmit timestamps addressed by 
their sequence number modulo N.


Regards,

Christopher Zimmermann
diff -rup inetutils-1.6/ping/libping.c newinetutils/ping/libping.c
--- inetutils-1.6/ping/libping.c	2008-12-27 21:06:55.000000000 +0100
+++ newinetutils/ping/libping.c	2009-07-27 17:46:49.000000000 +0200
@@ -117,7 +117,7 @@ ping_xmit (PING * p)
   buflen = _ping_packetsize (p);
 
   /* Mark sequence number as sent */
-  _PING_CLR (p, p->ping_num_xmit % p->ping_cktab_size);
+  _PING_CLR (p, p->ping_num_xmit);
 
   /* Encode ICMP header */
   switch (p->ping_type)
@@ -208,7 +208,7 @@ ping_recv (PING * p)
 		 inet_ntoa (p->ping_from.ping_sockaddr.sin_addr));
 
       p->ping_num_recv++;
-      if (_PING_TST (p, icmp->icmp_seq % p->ping_cktab_size))
+      if (_PING_TST (p, icmp->icmp_seq))
 	{
 	  p->ping_num_rept++;
 	  p->ping_num_recv--;
@@ -216,7 +216,7 @@ ping_recv (PING * p)
 	}
       else
 	{
-	  _PING_SET (p, icmp->icmp_seq % p->ping_cktab_size);
+	  _PING_SET (p, icmp->icmp_seq);
 	  dupflag = 0;
 	}
 
diff -rup inetutils-1.6/ping/ping6.c newinetutils/ping/ping6.c
--- inetutils-1.6/ping/ping6.c	2008-12-27 21:07:03.000000000 +0100
+++ newinetutils/ping/ping6.c	2009-07-27 17:42:13.000000000 +0200
@@ -753,7 +753,7 @@ ping_xmit (PING * p)
   buflen = p->ping_datalen + sizeof (struct icmp6_hdr);
 
   /* Mark sequence number as sent */
-  _PING_CLR (p, p->ping_num_xmit % p->ping_cktab_size);
+  _PING_CLR (p, p->ping_num_xmit);
 
   icmp6 = (struct icmp6_hdr *) p->ping_buffer;
   icmp6->icmp6_type = ICMP6_ECHO_REQUEST;
@@ -832,7 +832,7 @@ ping_recv (PING * p)
       if (ntohs (icmp6->icmp6_id) != p->ping_ident)
 	return -1;		/* It's not a response to us.  */
 
-      if (_PING_TST (p, ntohs (icmp6->icmp6_seq) % p->ping_cktab_size))
+      if (_PING_TST (p, ntohs (icmp6->icmp6_seq)))
 	{
 	  /* We already got the reply for this echo request.  */
 	  p->ping_num_rept++;
@@ -840,7 +840,7 @@ ping_recv (PING * p)
 	}
       else
 	{
-	  _PING_SET (p, ntohs (icmp6->icmp6_seq) % p->ping_cktab_size);
+	  _PING_SET (p, ntohs (icmp6->icmp6_seq));
 	  p->ping_num_recv++;
 	  dupflag = 0;
 	}
diff -rup inetutils-1.6/ping/ping6.h newinetutils/ping/ping6.h
--- inetutils-1.6/ping/ping6.h	2008-10-14 21:25:31.000000000 +0200
+++ newinetutils/ping/ping6.h	2009-07-27 17:46:47.000000000 +0200
@@ -22,7 +22,8 @@
 #define PING_MAX_DATALEN (65535 - sizeof (struct icmp6_hdr))
 
 #define USE_IPV6 1
-#define _C_BIT(p,bit)    (p)->ping_cktab[(bit)>>3]	/* byte in ck array */
+
+#define _C_BIT(p,bit)    (p)->ping_cktab[((bit) >> 3) % p->ping_cktab_size]	/* byte in ck array */
 #define _C_MASK(bit)     (1 << ((bit) & 0x07))
 
 #define _PING_SET(p,bit) (_C_BIT (p,bit) |= _C_MASK (bit))
diff -rup inetutils-1.6/ping/ping.c newinetutils/ping/ping.c
--- inetutils-1.6/ping/ping.c	2008-12-27 22:11:02.000000000 +0100
+++ newinetutils/ping/ping.c	2009-07-27 17:47:06.000000000 +0200
@@ -309,7 +315,7 @@ ping_run (PING * ping, int (*finish) ())
   int fdmax;
   struct timeval timeout;
   struct timeval last, intvl, now;
-  struct timeval *t = NULL;
+  //struct timeval *t = NULL; who needs this ?!?
   int finishing = 0;
   int nresp = 0;
   int i;
@@ -367,11 +373,14 @@ ping_run (PING * ping, int (*finish) ())
 	{
 	  if (ping_recv (ping) == 0)
 	    nresp++;
+#if 0
+          strange... this is the only appearance of t
 	  if (t == 0)
 	    {
 	      gettimeofday (&now, NULL);
 	      t = &now;
 	    }
+#endif
 	  if (ping->ping_count && nresp >= ping->ping_count)
 	    break;
 	}
diff -rup inetutils-1.6/ping/ping_common.h newinetutils/ping/ping_common.h
--- inetutils-1.6/ping/ping_common.h	2008-12-27 21:07:12.000000000 +0100
+++ newinetutils/ping/ping_common.h	2009-07-23 14:49:36.000000000 +0200
@@ -35,6 +35,7 @@
 #define OPT_QUIET       0x008
 #define OPT_RROUTE      0x010
 #define OPT_VERBOSE     0x020
 
 struct ping_stat
 {
diff -rup inetutils-1.6/ping/ping.h newinetutils/ping/ping.h
--- inetutils-1.6/ping/ping.h	2008-10-14 21:25:31.000000000 +0200
+++ newinetutils/ping/ping.h	2009-07-27 17:46:48.000000000 +0200
@@ -21,7 +21,7 @@
 
 #define USE_IPV6 0
 
-#define _C_BIT(p,bit)    (p)->ping_cktab[(bit)>>3]	/* byte in ck array */
+#define _C_BIT(p,bit)    (p)->ping_cktab[((bit) >> 3) % p->ping_cktab_size]	/* byte in ck array */
 #define _C_MASK(bit)     (1 << ((bit) & 0x07))
 
 #define _PING_SET(p,bit) (_C_BIT (p,bit) |= _C_MASK (bit))

Attachment: signature.asc
Description: PGP signature

Reply via email to