[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-inetutils] ping
From: |
Debarshi Ray |
Subject: |
Re: [bug-inetutils] ping |
Date: |
Thu, 5 Jun 2008 02:58:25 +0530 |
Here (http://rishi.fedorapeople.org/gnu/ping-multiple.diff or below)
is the final version of the patch after some minor clean-ups.
diff -urNp inetutils/ping/ping.c inetutils-build/ping/ping.c
--- inetutils/ping/ping.c 2007-12-10 21:17:19.000000000 +0530
+++ inetutils-build/ping/ping.c 2008-06-05 02:43:57.000000000 +0530
@@ -54,10 +54,10 @@
#include "ping_impl.h"
#include "libinetutils.h"
-extern int ping_echo (int argc, char **argv);
-extern int ping_timestamp (int argc, char **argv);
-extern int ping_address (int argc, char **argv);
-extern int ping_router (int argc, char **argv);
+extern int ping_echo (char *hostname);
+extern int ping_timestamp (char *hostname);
+extern int ping_address (char *hostname);
+extern int ping_router (char *hostname);
PING *ping;
bool is_root = false;
@@ -70,9 +70,9 @@ size_t interval;
size_t data_length = PING_DATALEN;
unsigned options;
unsigned long preload = 0;
-int (*ping_type) (int argc, char **argv) = ping_echo;
+int (*ping_type) (char *hostname) = ping_echo;
-int (*decode_type (const char *arg)) (int argc, char **argv);
+int (*decode_type (const char *arg)) (char *hostname);
static int send_echo (PING * ping);
#define MIN_USER_INTERVAL (200000/PING_PRECISION)
@@ -264,15 +264,20 @@ main (int argc, char **argv)
init_data_buffer (patptr, pattern_len);
- status = (*(ping_type)) (argc, argv);
+ while (argc--)
+ {
+ status = (*(ping_type)) (*argv++);
+ ping_reset (ping);
+ }
+
free (ping);
free (data_buffer);
return status;
}
-int (*decode_type (const char *arg)) (int argc, char **argv)
+int (*decode_type (const char *arg)) (char *hostname)
{
- int (*ping_type) (int argc, char **argv);
+ int (*ping_type) (char *hostname);
if (strcasecmp (arg, "echo") == 0)
ping_type = ping_echo;
@@ -308,12 +313,13 @@ ping_run (PING * ping, int (*finish) ())
struct timeval *t = NULL;
int finishing = 0;
int nresp = 0;
+ int i;
signal (SIGINT, sig_int);
fdmax = ping->ping_fd + 1;
- while (preload--)
+ for (i = 0; i < preload; i++)
send_echo (ping);
if (options & OPT_FLOOD)
@@ -390,8 +396,7 @@ ping_run (PING * ping, int (*finish) ())
}
}
- free (ping->ping_buffer);
- free (ping->ping_cktab);
+ ping_unset_data (ping);
if (finish)
return (*finish) ();
diff -urNp inetutils/ping/ping_address.c inetutils-build/ping/ping_address.c
--- inetutils/ping/ping_address.c 2007-12-10 21:17:19.000000000 +0530
+++ inetutils-build/ping/ping_address.c 2008-06-05 01:27:45.000000000 +0530
@@ -63,14 +63,14 @@ static void print_address (int dupflag,
static int address_finish ();
int
-ping_address (int argc, char **argv)
+ping_address (char *hostname)
{
ping_set_type (ping, ICMP_ADDRESS);
ping_set_event_handler (ping, recv_address, NULL);
ping_set_packetsize (ping, 12); /* FIXME: constant */
ping_set_count (ping, 1);
- if (ping_set_dest (ping, *argv))
+ if (ping_set_dest (ping, hostname))
error (EXIT_FAILURE, 0, "unknown host");
printf ("PING %s (%s): sending address mask request\n",
diff -urNp inetutils/ping/ping_echo.c inetutils-build/ping/ping_echo.c
--- inetutils/ping/ping_echo.c 2007-12-10 21:17:19.000000000 +0530
+++ inetutils-build/ping/ping_echo.c 2008-06-05 01:27:07.000000000 +0530
@@ -70,7 +70,7 @@ void print_icmp_header (struct sockaddr_
static void print_ip_opt (struct ip *ip, int hlen);
int
-ping_echo (int argc, char **argv)
+ping_echo (char *hostname)
{
#ifdef IP_OPTIONS
char rspace[3 + 4 * NROUTES + 1]; /* record route space */
@@ -88,7 +88,7 @@ ping_echo (int argc, char **argv)
ping_set_packetsize (ping, data_length);
ping_set_event_handler (ping, handler, &ping_stat);
- if (ping_set_dest (ping, *argv))
+ if (ping_set_dest (ping, hostname))
error (EXIT_FAILURE, 0, "unknown host");
if (options & OPT_RROUTE)
diff -urNp inetutils/ping/ping_router.c inetutils-build/ping/ping_router.c
--- inetutils/ping/ping_router.c 2007-12-10 21:17:19.000000000 +0530
+++ inetutils-build/ping/ping_router.c 2008-06-05 01:28:22.000000000 +0530
@@ -49,7 +49,7 @@
#include <ping_impl.h>
int
-ping_router (int argc, char **argv)
+ping_router (char *hostname)
{
return 0;
}
diff -urNp inetutils/ping/ping_timestamp.c inetutils-build/ping/ping_timestamp.c
--- inetutils/ping/ping_timestamp.c 2007-12-10 21:17:19.000000000 +0530
+++ inetutils-build/ping/ping_timestamp.c 2008-06-05 01:28:11.000000000
+0530
@@ -60,13 +60,13 @@ static void print_timestamp (int dupflag
static int timestamp_finish ();
int
-ping_timestamp (int argc, char **argv)
+ping_timestamp (char *hostname)
{
ping_set_type (ping, ICMP_TIMESTAMP);
ping_set_event_handler (ping, recv_timestamp, NULL);
ping_set_packetsize (ping, 20);
- if (ping_set_dest (ping, *argv))
+ if (ping_set_dest (ping, hostname))
error (EXIT_FAILURE, 0, "unknown host");
printf ("PING %s (%s): sending timestamp requests\n",
diff -urNp inetutils/libicmp/libping.c inetutils-build/libicmp/libping.c
--- inetutils/libicmp/libping.c 2007-12-10 21:17:18.000000000 +0530
+++ inetutils-build/libicmp/libping.c 2008-06-05 00:10:27.000000000 +0530
@@ -99,6 +99,14 @@ ping_init (int type, int ident)
}
void
+ping_reset (PING * p)
+{
+ p->ping_num_xmit = 0;
+ p->ping_num_recv = 0;
+ p->ping_num_rept = 0;
+}
+
+void
ping_set_type (PING * p, int type)
{
p->ping_type = type;
@@ -119,6 +127,11 @@ _ping_freebuf (PING * p)
free (p->ping_buffer);
p->ping_buffer = NULL;
}
+ if (p->ping_cktab)
+ {
+ free (p->ping_cktab);
+ p->ping_cktab = NULL;
+ }
}
int
@@ -154,6 +167,12 @@ ping_set_data (PING * p, void *data, siz
return 0;
}
+void
+ping_unset_data (PING * p)
+{
+ _ping_freebuf (p);
+}
+
int
ping_xmit (PING * p)
{
diff -urNp inetutils/libicmp/ping.h inetutils-build/libicmp/ping.h
--- inetutils/libicmp/ping.h 2007-12-10 21:17:18.000000000 +0530
+++ inetutils-build/libicmp/ping.h 2008-06-05 00:10:27.000000000 +0530
@@ -72,6 +72,7 @@ struct ping_data
#define _PING_TST(p,bit) (_C_BIT (p,bit) & _C_MASK (bit))
PING *ping_init (int type, int ident);
+void ping_reset (PING * p);
void ping_set_type (PING * p, int type);
void ping_set_count (PING * ping, size_t count);
void ping_set_sockopt (PING * ping, int opt, void *val, int valsize);
@@ -82,5 +83,6 @@ int ping_set_pattern (PING * p, int len,
void ping_set_event_handler (PING * ping, ping_efp fp, void *closure);
int ping_set_data (PING * p, void *data, size_t off, size_t len);
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);
diff -urNp inetutils/ChangeLog inetutils-build/ChangeLog
--- inetutils/ChangeLog 2008-06-03 23:52:38.000000000 +0530
+++ inetutils-build/ChangeLog 2008-06-05 02:46:25.000000000 +0530
@@ -1,3 +1,29 @@
+2008-06-05 Debarshi Ray <address@hidden>
+
+ * libicmp/libping.c (ping_reset): New function.
+ (_ping_freebuf): Free PING->ping_cktab.
+ (ping_unset_data): New function.
+
+ * libicmp/ping.h (ping_reset): New function.
+ (ping_unset_data): New function.
+
+ * ping/ping.c (ping_type): Changed type to `int (*ping_type) (char
+ *hostname)'. All users changed accordingly.
+ (decode_type): Likewise.
+ (main): Multiple host support implemented.
+ (ping_run): Added new variable I. Replaced `while' with `for' to
+ avoid decrementing PRELOAD. Replaced free with ping_unset_data.
+
+ * ping/ping_address.c (ping_address): Changed type to
+ `int ping_address (char *hostname)'. All callers and extern
+ declarations changed accordingly.
+
+ * ping/ping_echo.c (ping_echo): Likewise.
+
+ * ping/ping_router.c (ping_router): Likewise.
+
+ * ping/ping_timestamp.c (ping_timestamp): Likewise.
+
I could not find any regressions introduced by this change. What do you think?
Happy hacking.
Debarshi