bug-inetutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-inetutils] ping/ping6 removing common code for review - 5


From: Rakesh Pandit
Subject: [bug-inetutils] ping/ping6 removing common code for review - 5
Date: Wed, 15 Oct 2008 00:12:34 +0530

Hello list,

Below is the latest patch which needs review.

I have committed 4 old already reviewed patch with fixed ChangeLog
messages and all suggested changes:
Fixed ChangeLogs where at:
http://lists.gnu.org/archive/html/bug-inetutils/2008-10/msg00007.html

Old Patches which where committed:
Last four ChangeLog entries are for patches in following mails:
http://lists.gnu.org/archive/html/bug-inetutils/2008-08/msg00060.html
http://lists.gnu.org/archive/html/bug-inetutils/2008-08/msg00058.html
http://lists.gnu.org/archive/html/bug-inetutils/2008-08/msg00057.html
http://lists.gnu.org/archive/html/bug-inetutils/2008-08/msg00052.html

Other then changelog remarks, changes to above patches:
1. Using USE_IPV6 in place of IS_PING6
2. Use ping_sockaddr in place of address

-- 
rakesh

Below is latest patch:

Index: ChangeLog
===================================================================
RCS file: /sources/inetutils/inetutils/ChangeLog,v
retrieving revision 1.335
diff -u -r1.335 ChangeLog
--- ChangeLog   14 Oct 2008 17:53:04 -0000      1.335
+++ ChangeLog   14 Oct 2008 18:36:45 -0000
@@ -1,5 +1,23 @@
 2008-10-14  Rakesh Pandit  <address@hidden>

+        * ping/ping_impl.h, ping/ping.h, ping/ping_common.h,
+       ping/ping6.h (ping_stat, PEV_RESPONSE, PEV_DUPLICATE, PEV_NOECHO,
+       PING_INTERVAL, PING_CKTABSIZE, MAXWAIT, OPT_FLOOD, OPT_INTERVAL,
+       OPT_NUMERIC, OPT_QUIET, OPT_RROUTE, OPT_VERBOSE, PING_TIMING,
+       PING_HEADER_LEN, PING_DATALEN): Moved all these common macros and
+       structures from ping_impl.h , ping6.h and ping_ping.h to
+       ping_common.h. Removed PING_INTERVAL.
+       * ping/ping6.c (ping_run): Used PING_SET_INTERVAL similar to
+       libping.c and used PING_DEFAULT_INTERVAL in place of PING_INTERVAL.
+       
+       * ping/libping.c (ping_set_datalen): Removed.
+       
+       * ping/libping.c, ping/ping_common.c (_ping_freebuf, ping_unset_data):
+       Moved _ping_freebuf, ping_unset_data from libping.c to ping_common.c
+       * ping/ping6.c (ping_run): Free memory with call to ping_unset_data.
+       
+2008-10-14  Rakesh Pandit  <address@hidden>
+
        * ping/libping.c, ping/ping_common.c, ping/ping_common.h
        (ping_set_count, ping_set_sockopt, ping_set_interval):
        Moved functions from libping.c to ping_common.c and made
Index: ping/libping.c
===================================================================
RCS file: /sources/inetutils/inetutils/ping/libping.c,v
retrieving revision 1.3
diff -u -r1.3 libping.c
--- ping/libping.c      14 Oct 2008 17:53:04 -0000      1.3
+++ ping/libping.c      14 Oct 2008 18:36:45 -0000
@@ -38,7 +38,6 @@

 #include "ping.h"

-static void _ping_freebuf (PING * p);
 static size_t _ping_packetsize (PING * p);

 size_t
@@ -107,34 +106,6 @@
   p->ping_type = type;
 }

-void
-ping_set_datalen (PING * p, size_t len)
-{
-  _ping_freebuf (p);
-  p->ping_datalen = len;
-}
-
-void
-_ping_freebuf (PING * p)
-{
-  if (p->ping_buffer)
-    {
-      free (p->ping_buffer);
-      p->ping_buffer = NULL;
-    }
-  if (p->ping_cktab)
-    {
-      free (p->ping_cktab);
-      p->ping_cktab = NULL;
-    }
-}
-
-void
-ping_unset_data (PING * p)
-{
-  _ping_freebuf (p);
-}
-
 int
 ping_xmit (PING * p)
 {
Index: ping/ping.h
===================================================================
RCS file: /sources/inetutils/inetutils/ping/ping.h,v
retrieving revision 1.3
diff -u -r1.3 ping.h
--- ping/ping.h 14 Oct 2008 17:53:05 -0000      1.3
+++ ping/ping.h 14 Oct 2008 18:36:45 -0000
@@ -19,19 +19,8 @@

 #include "ping_common.h"

-#define PEV_RESPONSE 0
-#define PEV_DUPLICATE 1
-#define PEV_NOECHO  2
 #define USE_IPV6 0

-#define PING_DEFAULT_INTERVAL 1000     /* Milliseconds */
-#define PING_PRECISION 1000    /* Millisecond precision */
-#define PING_CKTABSIZE 128
-#define PING_SET_INTERVAL(t,i) do {\
- (t).tv_sec = (i)/PING_PRECISION;\
- (t).tv_usec = ((i)%PING_PRECISION)*(1000000/PING_PRECISION) ;\
-} while (0)
-
 #define _C_BIT(p,bit)    (p)->ping_cktab[(bit)>>3]     /* byte in ck array */
 #define _C_MASK(bit)     (1 << ((bit) & 0x07))

@@ -46,7 +35,5 @@
 int ping_set_dest (PING * ping, char *host);
 int ping_set_pattern (PING * p, int len, u_char * pat);
 void ping_set_event_handler (PING * ping, ping_efp fp, void *closure);
-void ping_set_datalen (PING * p, size_t len);
-void ping_unset_data (PING * p);
 int ping_recv (PING * p);
 int ping_xmit (PING * p);
Index: ping/ping6.c
===================================================================
RCS file: /sources/inetutils/inetutils/ping/ping6.c,v
retrieving revision 1.14
diff -u -r1.14 ping6.c
--- ping/ping6.c        14 Oct 2008 17:53:05 -0000      1.14
+++ ping/ping6.c        14 Oct 2008 18:36:45 -0000
@@ -281,10 +281,7 @@
       intvl.tv_usec = 10000;
     }
   else
-    {
-      intvl.tv_sec = ping->ping_interval;
-      intvl.tv_usec = 0;
-    }
+    PING_SET_INTERVAL (intvl, ping->ping_interval);

   gettimeofday (&last, NULL);
   send_echo (ping);
@@ -353,6 +350,9 @@
          gettimeofday (&last, NULL);
        }
     }
+
+  ping_unset_data (ping);
+
   if (finish)
     return (*finish) ();
   return 0;
@@ -731,7 +731,7 @@

   p->ping_fd = fd;
   p->ping_count = DEFAULT_PING_COUNT;
-  p->ping_interval = PING_INTERVAL;
+  p->ping_interval = PING_DEFAULT_INTERVAL;
   p->ping_datalen = sizeof (struct icmp6_hdr);
   /* Make sure we use only 16 bits in this field, id for icmp is a u_short.  */
   p->ping_ident = ident & 0xFFFF;
Index: ping/ping6.h
===================================================================
RCS file: /sources/inetutils/inetutils/ping/ping6.h,v
retrieving revision 1.5
diff -u -r1.5 ping6.h
--- ping/ping6.h        14 Oct 2008 17:40:29 -0000      1.5
+++ ping/ping6.h        14 Oct 2008 18:36:45 -0000
@@ -19,33 +19,6 @@

 #include "ping_common.h"

-struct ping_stat
-{
-  double tmin;                 /* minimum round trip time */
-  double tmax;                 /* maximum round trip time */
-  double tsum;                 /* sum of all times, for doing average */
-  double tsumsq;               /* sum of all times squared, for std. dev. */
-};
-
-#define PEV_RESPONSE 0
-#define PEV_DUPLICATE 1
-#define PEV_NOECHO  2
-
-#define PING_INTERVAL 1
-#define PING_CKTABSIZE 128
-
-#define MAXWAIT                10      /* max seconds to wait for response */
-
-#define OPT_FLOOD      0x001
-#define OPT_INTERVAL   0x002
-#define OPT_NUMERIC    0x004
-#define OPT_QUIET      0x008
-#define OPT_RROUTE     0x010
-#define OPT_VERBOSE    0x020
-
-#define PING_TIMING(s) (s >= PING_HEADER_LEN)
-#define PING_HEADER_LEN        sizeof (struct timeval)
-#define PING_DATALEN   (64 - PING_HEADER_LEN)  /* default data length */
 #define PING_MAX_DATALEN (65535 - sizeof (struct icmp6_hdr))

 #define USE_IPV6 1
Index: ping/ping_common.c
===================================================================
RCS file: /sources/inetutils/inetutils/ping/ping_common.c,v
retrieving revision 1.9
diff -u -r1.9 ping_common.c
--- ping/ping_common.c  14 Oct 2008 17:53:05 -0000      1.9
+++ ping/ping_common.c  14 Oct 2008 18:36:45 -0000
@@ -33,6 +33,8 @@
 extern unsigned char *data_buffer;
 extern size_t data_length;

+static void _ping_freebuf (PING * p);
+
 size_t
 ping_cvt_number (const char *optarg, size_t maxval, int allow_zero)
 {
@@ -193,3 +195,24 @@
   ping->ping_interval = interval;
 }

+void
+_ping_freebuf (PING * p)
+{
+  if (p->ping_buffer)
+    {
+      free (p->ping_buffer);
+      p->ping_buffer = NULL;
+    }
+  if (p->ping_cktab)
+    {
+      free (p->ping_cktab);
+      p->ping_cktab = NULL;
+    }
+}
+
+void
+ping_unset_data (PING * p)
+{
+  _ping_freebuf (p);
+}
+
Index: ping/ping_common.h
===================================================================
RCS file: /sources/inetutils/inetutils/ping/ping_common.h,v
retrieving revision 1.10
diff -u -r1.10 ping_common.h
--- ping/ping_common.h  14 Oct 2008 17:53:05 -0000      1.10
+++ ping/ping_common.h  14 Oct 2008 18:36:45 -0000
@@ -25,8 +25,43 @@

 #include <stdbool.h>

+#define MAXWAIT         10      /* max seconds to wait for response */
+
+#define OPT_FLOOD       0x001
+#define OPT_INTERVAL    0x002
+#define OPT_NUMERIC     0x004
+#define OPT_QUIET       0x008
+#define OPT_RROUTE      0x010
+#define OPT_VERBOSE     0x020
+
+struct ping_stat
+{
+  double tmin;                  /* minimum round trip time */
+  double tmax;                  /* maximum round trip time */
+  double tsum;                  /* sum of all times, for doing average */
+  double tsumsq;                /* sum of all times squared, for std. dev. */
+};
+
+#define PEV_RESPONSE 0
+#define PEV_DUPLICATE 1
+#define PEV_NOECHO  2
+
+#define PING_CKTABSIZE 128
+
 #define DEFAULT_PING_COUNT 4

+#define PING_TIMING(s) (s >= PING_HEADER_LEN)
+#define PING_HEADER_LEN sizeof (struct timeval)
+#define PING_DATALEN    (64 - PING_HEADER_LEN)  /* default data length */
+
+#define PING_DEFAULT_INTERVAL 1000      /* Milliseconds */
+#define PING_PRECISION 1000     /* Millisecond precision */
+
+#define PING_SET_INTERVAL(t,i) do {\
+  (t).tv_sec = (i)/PING_PRECISION;\
+  (t).tv_usec = ((i)%PING_PRECISION)*(1000000/PING_PRECISION) ;\
+} while (0)
+
 /* Not sure about this step*/
 #define _PING_BUFLEN(p, USE_IPV6) ((USE_IPV6)? ((p)->ping_datalen +
sizeof (struct icmp6_hdr)) : \
                                   ((p)->ping_datalen + sizeof (icmphdr_t)))
@@ -92,4 +127,5 @@
 void ping_set_count (PING * ping, size_t count);
 void ping_set_sockopt (PING * ping, int opt, void *val, int valsize);
 void ping_set_interval (PING * ping, size_t interval);
+void ping_unset_data (PING * p);

Index: ping/ping_impl.h
===================================================================
RCS file: /sources/inetutils/inetutils/ping/ping_impl.h,v
retrieving revision 1.7
diff -u -r1.7 ping_impl.h
--- ping/ping_impl.h    28 May 2007 20:26:01 -0000      1.7
+++ ping/ping_impl.h    14 Oct 2008 18:36:45 -0000
@@ -1,27 +1,5 @@
-#define MAXWAIT                10      /* max seconds to wait for response */
-
-#define OPT_FLOOD      0x001
-#define OPT_INTERVAL   0x002
-#define OPT_NUMERIC    0x004
-#define OPT_QUIET      0x008
-#define OPT_RROUTE     0x010
-#define OPT_VERBOSE    0x020
-
-#define PING_TIMING(s) (s >= PING_HEADER_LEN)
-#define PING_HEADER_LEN        sizeof (struct timeval)
-#define PING_DATALEN   (64 - PING_HEADER_LEN)  /* default data length */
 #define PING_MAX_DATALEN (65535 - MAXIPLEN - MAXICMPLEN)

-struct ping_stat
-{
-  double tmin;                 /* minimum round trip time */
-  double tmax;                 /* maximum round trip time */
-  double tsum;                 /* sum of all times, for doing average */
-  double tsumsq;               /* sum of all times squared, for std. dev. */
-};
-
-
-
 extern unsigned options;
 extern PING *ping;
 extern u_char *data_buffer;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]