[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-inetutils] [PATCH] Ping: add "ability to ping multiple host in one
From: |
Kim Max |
Subject: |
[bug-inetutils] [PATCH] Ping: add "ability to ping multiple host in one go". |
Date: |
Tue, 10 Aug 2010 02:16:58 +0400 |
User-agent: |
Mutt/1.4.2.3i |
Hello.
I'm not sure it's acceptable way, so I'm waiting for comments.
---
ping/ping.c | 29 +++++++++++++++++++++++++----
1 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/ping/ping.c b/ping/ping.c
index b65053e..3cf1571 100644
--- a/ping/ping.c
+++ b/ping/ping.c
@@ -34,6 +34,9 @@
# include <netinet/ip_var.h>
#endif
+#include <sys/types.h>
+#include <sys/wait.h>
+
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
@@ -236,7 +239,7 @@ main (int argc, char **argv)
{
int index;
int one = 1;
- int status = 0;
+ int status = 0, rstatus;
set_program_name (argv[0]);
@@ -247,6 +250,25 @@ main (int argc, char **argv)
iu_argp_init ("ping", program_authors);
argp_parse (&argp, argc, argv, 0, &index, NULL);
+ argv += index;
+ argc -= index;
+
+ while (argc > 1) /* Don't fork if there is only host to ping. */
+ {
+ pid_t pid = fork();
+ if (pid == -1)
+ break;
+ else if (pid > 0)
+ {
+ argc = 1;
+ }
+ else
+ {
+ ++argv;
+ --argc;
+ }
+ }
+
ping = ping_init (ICMP_ECHO, getpid ());
if (ping == NULL)
/* ping_init() prints our error message. */
@@ -257,9 +279,6 @@ main (int argc, char **argv)
/* Reset root privileges */
setuid (getuid ());
- argv += index;
- argc -= index;
-
if (count != 0)
ping_set_count (ping, count);
@@ -276,6 +295,8 @@ main (int argc, char **argv)
status |= (*(ping_type)) (*argv++);
ping_reset (ping);
}
+ while (wait(&rstatus) != -1)
+ status |= WIFEXITED(rstatus);
free (ping);
free (data_buffer);
--
1.6.0.3
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [bug-inetutils] [PATCH] Ping: add "ability to ping multiple host in one go".,
Kim Max <=