[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: |
Wed, 4 Jun 2008 03:28:05 +0530 |
Could be possible without adding the --multiple switch. Here is a
possible approach:
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-04 03:17:01.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 **argv);
+extern int ping_timestamp (char **argv);
+extern int ping_address (char **argv);
+extern int ping_router (char **argv);
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 **argv) = ping_echo;
-int (*decode_type (const char *arg)) (int argc, char **argv);
+int (*decode_type (const char *arg)) (char **argv);
static int send_echo (PING * ping);
#define MIN_USER_INTERVAL (200000/PING_PRECISION)
@@ -230,6 +230,7 @@ static struct argp argp = {argp_options,
int
main (int argc, char **argv)
{
+ int i;
int index;
int one = 1;
int status;
@@ -264,15 +265,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 **argv)
{
- int (*ping_type) (int argc, char **argv);
+ int (*ping_type) (char **argv);
if (strcasecmp (arg, "echo") == 0)
ping_type = ping_echo;
@@ -308,12 +314,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 +397,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-04 03:12:51.000000000 +0530
@@ -63,7 +63,7 @@ static void print_address (int dupflag,
static int address_finish ();
int
-ping_address (int argc, char **argv)
+ping_address (char **argv)
{
ping_set_type (ping, ICMP_ADDRESS);
ping_set_event_handler (ping, recv_address, NULL);
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-04 03:11:44.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 **argv)
{
#ifdef IP_OPTIONS
char rspace[3 + 4 * NROUTES + 1]; /* record route space */
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-04 03:13:13.000000000 +0530
@@ -49,7 +49,7 @@
#include <ping_impl.h>
int
-ping_router (int argc, char **argv)
+ping_router (char **argv)
{
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-04 03:11:58.000000000
+0530
@@ -60,7 +60,7 @@ static void print_timestamp (int dupflag
static int timestamp_finish ();
int
-ping_timestamp (int argc, char **argv)
+ping_timestamp (char **argv)
{
ping_set_type (ping, ICMP_TIMESTAMP);
ping_set_event_handler (ping, recv_timestamp, NULL);
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-04 03:08:25.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-04 03:09:08.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);
It still needs more testing and improvement. What do you think?
Regards,
Debarshi
- Re: [bug-inetutils] ping,
Debarshi Ray <=