[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-inetutils] Argpifying ping.
From: |
Debarshi 'Rishi' Ray |
Subject: |
Re: [bug-inetutils] Argpifying ping. |
Date: |
Fri, 30 Mar 2007 01:40:23 +0530 |
Here (http://glug-nith.org/~rishi/download/src/ping-argp.diff) is a
more complete patch to argpify ping:
diff -urNp ../inetutils/ping/ping.c ping/ping.c
--- ../inetutils/ping/ping.c 2007-03-29 23:28:43.000000000 +0530
+++ ping/ping.c 2007-03-30 01:36:42.000000000 +0530
@@ -46,234 +46,208 @@
#include <errno.h>
#include <limits.h>
+#include <argp.h>
#include <getopt.h>
#include <icmp.h>
#include <ping.h>
#include "ping_common.h"
#include "ping_impl.h"
-static char short_options[] = "VLhc:dfi:l:np:qRrs:t:v";
-static struct option long_options[] = {
- /* Help options */
- {"version", no_argument, NULL, 'V'},
- {"license", no_argument, NULL, 'L'},
- {"help", no_argument, NULL, 'h'},
- /* Common options */
- {"count", required_argument, NULL, 'c'},
- {"debug", no_argument, NULL, 'd'},
- {"ignore-routing", no_argument, NULL, 'r'},
- {"size", required_argument, NULL, 's'},
- {"interval", required_argument, NULL, 'i'},
- {"numeric", no_argument, NULL, 'n'},
- {"verbose", no_argument, NULL, 'v'},
- /* Packet types */
- {"type", required_argument, NULL, 't'},
- {"echo", no_argument, NULL, ICMP_ECHO},
- {"timestamp", no_argument, NULL, ICMP_TIMESTAMP},
- {"address", no_argument, NULL, ICMP_ADDRESS},
- {"router", no_argument, NULL, ICMP_ROUTERDISCOVERY},
- /* echo-specific options */
- {"flood", no_argument, NULL, 'f'},
- {"preload", required_argument, NULL, 'l'},
- {"pattern", required_argument, NULL, 'p'},
- {"quiet", no_argument, NULL, 'q'},
- {"route", no_argument, NULL, 'R'},
- {NULL, no_argument, NULL, 0}
-};
-
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);
PING *ping;
+bool is_root = false;
u_char *data_buffer;
+u_char *patptr;
+int pattern_len = 16;
+int socket_type;
+size_t count = DEFAULT_PING_COUNT;
+size_t interval;
size_t data_length = PING_DATALEN;
unsigned options;
unsigned long preload = 0;
int (*ping_type) (int argc, char **argv) = ping_echo;
-
-static void show_usage (void);
-static void decode_type (const char *optarg);
+/*static void decode_type (const char *optarg);*/
+int (*decode_type (const char *optarg)) (int argc, char **argv);
static int send_echo (PING * ping);
#define MIN_USER_INTERVAL (200000/PING_PRECISION)
-char *program_name;
+const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">";
+
+const char *argp_program_version = "ping (" PACKAGE_NAME ") " PACKAGE_VERSION
+"\nThis is free software. You may redistribute copies of it under
the terms of"
+"\nthe GNU General Public License <http://www.gnu.org/licenses/gpl.html>."
+"\nThere is NO WARRANTY, to the extent permitted by law."
+"\n"
+"\nWritten by Sergey Poznyakoff.";
+
+const char args_doc[] = "ADDRESS";
+const char doc[] = "Send ICMP ECHO_REQUEST packets to network hosts.";
+
+/* Define keys for long options that do not have short counterpart. */
+enum {
+ ARG_ECHO = 256,
+ ARG_ADDRESS,
+ ARG_TIMESTAMP,
+ ARG_ROUTERDISCOVERY
+};
+
+static struct argp_option argp_options[] = {
+#define GRP 0
+ {NULL, 0, NULL, 0, "Options controlling ICMP request types:", GRP},
+ {"echo", ARG_ECHO, NULL, 0, "Send ICMP_ECHO requests (default)", GRP+1},
+ {"address", ARG_ADDRESS, NULL, 0, "Send ICMP_ADDRESS packets", GRP+1},
+ {"timestamp", ARG_TIMESTAMP, NULL, 0, "Send ICMP_TIMESTAMP packets", GRP+1},
+ /* This option is not yet fully implemented, so mark it as hidden. */
+ {"router", ARG_ROUTERDISCOVERY, NULL, OPTION_HIDDEN, "Send "
+ "ICMP_ROUTERDISCOVERY packets", GRP+1},
+#undef GRP
+#define GRP 10
+ {NULL, 0, NULL, 0, "Options valid for all request types:", GRP},
+ {"count", 'c', "NUMBER", 0, "Stop after sending NUMBER packets", GRP+1},
+ {"debug", 'd', NULL, 0, "Set the SO_DEBUG option", GRP+1},
+ {"interval", 'i', "NUMBER", 0, "Wait NUMBER seconds between sending each "
+ "packet", GRP+1},
+ {"numeric", 'n', NULL, 0, "Do not resolve host addresses", GRP+1},
+ {"ignore-routing", 'r', NULL, 0, "Send directly to a host on an attached "
+ "network", GRP+1},
+ {"verbose", 'v', NULL, 0, "Verbose output", GRP+1},
+#undef GRP
+#define GRP 20
+ {NULL, 0, NULL, 0, "Options valid for --echo requests:", GRP},
+ {"flood", 'f', NULL, 0, "Flood ping", GRP+1},
+ {"preload", 'l', "NUMBER", 0, "Send NUMBER packets as fast as possible "
+ "before falling into normal mode of behavior", GRP+1},
+ {"pattern", 'p', "PAT", 0, "Fill ICMP packet with given pattern (hex)",
+ GRP+1},
+ {"quiet", 'q', NULL, 0, "Quiet output", GRP+1},
+ {"route", 'r', NULL, 0, "Record route", GRP+1},
+ {"size", 's', "NUMBER", 0, "Send NUMBER data octets", GRP+1},
+#undef GRP
+ {NULL}
+};
+
+static error_t
+parse_opt (int key, char *arg, struct argp_state *state)
+{
+ char *endptr;
+ u_char pattern[16];
+ double v;
+
+ switch (key)
+ {
+ case 'c':
+ count = ping_cvt_number (arg, 0, 1);
+ break;
+
+ case 'd':
+ socket_type = SO_DEBUG;
+ break;
+
+ case 'r':
+ socket_type = SO_DONTROUTE;
+ break;
+
+ case 'i':
+ v = strtod (arg, &endptr);
+ if (*endptr)
+ argp_error (state, "Invalid value (`%s' near `%s')\n", arg, endptr);
+ options |= OPT_INTERVAL;
+ interval = v * PING_PRECISION;
+ if (!is_root && interval < MIN_USER_INTERVAL)
+ argp_error (state, "Option value too small: %s\n", arg);
+ break;
+
+ case 'p':
+ decode_pattern (arg, &pattern_len, pattern);
+ patptr = pattern;
+ break;
+
+ case 's':
+ data_length = ping_cvt_number (arg, PING_MAX_DATALEN, 1);
+ break;
+
+ case 'n':
+ options |= OPT_NUMERIC;
+ break;
+
+ case 'q':
+ options |= OPT_QUIET;
+ break;
+
+ case 'R':
+ options |= OPT_RROUTE;
+ break;
+
+ case 'v':
+ options |= OPT_VERBOSE;
+ break;
+
+ case 'l':
+ preload = strtoul (arg, &endptr, 0);
+ if (*endptr || preload > INT_MAX)
+ argp_error (state, "Invalid preload value (%s)\n", arg);
+ break;
+
+ case 'f':
+ options |= OPT_FLOOD;
+ break;
+
+ case 't':
+ ping_type = decode_type (arg);
+ break;
+
+ case ARG_ECHO:
+ ping_type = decode_type ("echo");
+ break;
+
+ case ARG_TIMESTAMP:
+ ping_type = decode_type ("timestamp");
+ break;
+
+ case ARG_ADDRESS:
+ ping_type = decode_type ("address");
+ break;
+
+ case ARG_ROUTERDISCOVERY:
+ ping_type = decode_type ("router");
+ break;
+
+ case ARGP_KEY_NO_ARGS:
+ argp_usage (state);
+ break;
+
+ default:
+ return ARGP_ERR_UNKNOWN;
+ }
+
+ return 0;
+}
+
+static struct argp argp = {argp_options, parse_opt, args_doc, doc};
int
main (int argc, char **argv)
{
int c;
- char *p;
+ int index;
int one = 1;
- u_char pattern[16];
- int pattern_len = 16;
- u_char *patptr = NULL;
- bool is_root = false;
-
- size_t count = DEFAULT_PING_COUNT;
- int socket_type = 0;
- size_t interval = 0;
-
- program_name = argv[0];
+ char *p;
if (getuid () == 0)
is_root = true;
/* Parse command line */
- while ((c = getopt_long (argc, argv, short_options, long_options, NULL))
- != EOF)
- {
- switch (c)
- {
- case 'V':
- printf ("ping - %s %s\n", PACKAGE_NAME, PACKAGE_VERSION);
- printf ("Copyright (C) 2005 Free Software Foundation, Inc.\n");
- printf ("%s comes with ABSOLUTELY NO WARRANTY.\n", PACKAGE_NAME);
- printf ("You may redistribute copies of %s\n", PACKAGE_NAME);
- printf ("under the terms of the GNU General Public License.\n");
- printf ("For more information about these matters, ");
- printf ("see the files named COPYING.\n");
- exit (0);
- break;
-
- case 'L':
- show_license ();
- exit (0);
-
- case 'h':
- show_usage ();
- exit (0);
- break;
-
- case 'c':
- count = ping_cvt_number (optarg, 0, 1);
- break;
-
- case 'd':
- socket_type = SO_DEBUG;
- break;
-
- case 'r':
- socket_type = SO_DONTROUTE;
- break;
-
- case 'i':
- {
- double v;
-
- v = strtod (optarg, &p);
- if (*p)
- {
- fprintf (stderr, "Invalid value (`%s' near `%s')\n",
- optarg, p);
- exit (1);
- }
-
- options |= OPT_INTERVAL;
- interval = v * PING_PRECISION;
- if (!is_root && interval < MIN_USER_INTERVAL)
- {
- fprintf (stderr, "Option value too small: %s\n", optarg);
- exit (1);
- }
- }
- break;
-
- case 'p':
- decode_pattern (optarg, &pattern_len, pattern);
- patptr = pattern;
- break;
-
- case 's':
- data_length = ping_cvt_number (optarg, PING_MAX_DATALEN, 1);
- break;
-
- case 'n':
- options |= OPT_NUMERIC;
- break;
-
- case 'q':
- options |= OPT_QUIET;
- break;
-
- case 'R':
- options |= OPT_RROUTE;
- break;
-
- case 'v':
- options |= OPT_VERBOSE;
- break;
-
- case 'l':
- if (!is_root)
- {
- fprintf (stderr, "ping: option not allowed: --preload\n");
- exit (1);
- }
- preload = strtoul (optarg, &p, 0);
- if (*p || preload > INT_MAX)
- {
- fprintf (stderr, "ping: invalid preload value (%s)\n", optarg);
- exit (1);
- }
- break;
+ if (argp_parse (&argp, argc, argv, 0, &index, NULL))
+ exit(1);
- case 'f':
- if (is_root == false)
- {
- fprintf (stderr, "ping: option not allowed: --flood\n");
- exit (1);
- }
- options |= OPT_FLOOD;
- setbuf (stdout, (char *) NULL);
- break;
-
- case 't':
- decode_type (optarg);
- break;
-
- case ICMP_ECHO:
- decode_type ("echo");
- break;
-
- case ICMP_TIMESTAMP:
- decode_type ("timestamp");
- break;
-
- case ICMP_ADDRESS:
- if (!is_root)
- {
- fprintf (stderr, "ping: option not allowed: --address\n");
- exit (1);
- }
- decode_type ("address");
- break;
-
- case ICMP_ROUTERDISCOVERY:
- if (!is_root)
- {
- fprintf (stderr, "ping: option not allowed: --router\n");
- exit (1);
- }
- decode_type ("router");
- break;
-
- default:
- fprintf (stderr, "%c: not implemented\n", c);
- exit (1);
- }
- }
-
- argc -= optind;
- argv += optind;
- if (argc == 0)
- {
- show_usage ();
- exit (0);
- }
+ argv += index;
+ argc -= index;
ping = ping_init (ICMP_ECHO, getpid ());
if (ping == NULL)
@@ -297,14 +271,13 @@ main (int argc, char **argv)
init_data_buffer (patptr, pattern_len);
- return (*ping_type) (argc, argv);
+ return (*(ping_type)) (argc, argv);
}
-
-
-void
-decode_type (const char *optarg)
+int (*decode_type (const char *optarg)) (int argc, char **argv)
{
+ int (*ping_type) (int argc, char **argv);
+
if (strcasecmp (optarg, "echo") == 0)
ping_type = ping_echo;
else if (strcasecmp (optarg, "timestamp") == 0)
@@ -320,6 +293,8 @@ decode_type (const char *optarg)
fprintf (stderr, "unsupported packet type: %s\n", optarg);
exit (1);
}
+
+ return ping_type;
}
int volatile stop = 0;
@@ -467,40 +442,3 @@ ping_finish ()
printf ("\n");
return 0;
}
-
-void
-show_usage (void)
-{
- printf ("\
-Usage: ping [OPTION]... [ADDRESS]...\n\
-\n\
-Informational options:\n\
- -h, --help display this help and exit\n\
- -L, --license display license and exit\n\
- -V, --version output version information and exit\n\
-Options controlling ICMP request types:\n\
- --echo Send ICMP_ECHO requests (default)\n\
-* --address Send ICMP_ADDRESS packets\n\
- --timestamp Send ICMP_TIMESTAMP packets\n\
-* --router Send ICMP_ROUTERDISCOVERY packets\n\
-Options valid for all request types:\n\
- -c, --count N stop after sending N packets (default: %d)\n\
- -d, --debug set the SO_DEBUG option\n\
- -i, --interval N wait N seconds between sending each packet\n\
- -n, --numeric do not resolve host addresses\n\
- -r, --ignore-routing send directly to a host on an attached network\n\
- -v, --verbose verbose output\n\
-Options valid for --echo requests:\n\
-* -f, --flood flood ping \n\
-* -l, --preload N send N packets as fast as possible before falling into\n\
- normal mode of behavior\n\
- -p, --pattern PAT fill ICMP packet with given pattern (hex)\n\
- -q, --quiet quiet output\n\
- -R, --route record route\n\
- -s, --size N set number of data octets to send\n\
-\n\
-Options marked with an * are available only to super-user\n\
-\n\
-Report bugs to <" PACKAGE_BUGREPORT ">.\n\
-", DEFAULT_PING_COUNT);
-}
diff -urNp ../inetutils/ping/ping.c.~1.30.~ ping/ping.c.~1.30.~
--- ../inetutils/ping/ping.c.~1.30.~ 2006-11-17 19:27:29.000000000 +0530
+++ ping/ping.c.~1.30.~ 1970-01-01 05:30:00.000000000 +0530
@@ -1,506 +0,0 @@
-/* Copyright (C) 1998,2001, 2002, 2005, 2006 Free Software Foundation, Inc.
-
- This file is part of GNU Inetutils.
-
- GNU Inetutils is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- GNU Inetutils is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNU Inetutils; see the file COPYING. If not, write
- to the Free Software Foundation, Inc., 51 Franklin Street,
- Fifth Floor, Boston, MA 02110-1301 USA. */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/file.h>
-#include <sys/time.h>
-#include <signal.h>
-
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
-/*#include <netinet/ip_icmp.h> -- deliberately not including this */
-#ifdef HAVE_NETINET_IP_VAR_H
-# include <netinet/ip_var.h>
-#endif
-
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <string.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-
-#include <getopt.h>
-#include <icmp.h>
-#include <ping.h>
-#include "ping_common.h"
-#include "ping_impl.h"
-
-static char short_options[] = "VLhc:dfi:l:np:qRrs:t:v";
-static struct option long_options[] = {
- /* Help options */
- {"version", no_argument, NULL, 'V'},
- {"license", no_argument, NULL, 'L'},
- {"help", no_argument, NULL, 'h'},
- /* Common options */
- {"count", required_argument, NULL, 'c'},
- {"debug", no_argument, NULL, 'd'},
- {"ignore-routing", no_argument, NULL, 'r'},
- {"size", required_argument, NULL, 's'},
- {"interval", required_argument, NULL, 'i'},
- {"numeric", no_argument, NULL, 'n'},
- {"verbose", no_argument, NULL, 'v'},
- /* Packet types */
- {"type", required_argument, NULL, 't'},
- {"echo", no_argument, NULL, ICMP_ECHO},
- {"timestamp", no_argument, NULL, ICMP_TIMESTAMP},
- {"address", no_argument, NULL, ICMP_ADDRESS},
- {"router", no_argument, NULL, ICMP_ROUTERDISCOVERY},
- /* echo-specific options */
- {"flood", no_argument, NULL, 'f'},
- {"preload", required_argument, NULL, 'l'},
- {"pattern", required_argument, NULL, 'p'},
- {"quiet", no_argument, NULL, 'q'},
- {"route", no_argument, NULL, 'R'},
- {NULL, no_argument, NULL, 0}
-};
-
-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);
-
-PING *ping;
-u_char *data_buffer;
-size_t data_length = PING_DATALEN;
-unsigned options;
-unsigned long preload = 0;
-int (*ping_type) (int argc, char **argv) = ping_echo;
-
-
-static void show_usage (void);
-static void decode_type (const char *optarg);
-static int send_echo (PING * ping);
-
-#define MIN_USER_INTERVAL (200000/PING_PRECISION)
-
-char *program_name;
-
-int
-main (int argc, char **argv)
-{
- int c;
- char *p;
- int one = 1;
- u_char pattern[16];
- int pattern_len = 16;
- u_char *patptr = NULL;
- bool is_root = false;
-
- size_t count = DEFAULT_PING_COUNT;
- int socket_type = 0;
- size_t interval = 0;
-
- program_name = argv[0];
-
- if (getuid () == 0)
- is_root = true;
-
- /* Parse command line */
- while ((c = getopt_long (argc, argv, short_options, long_options, NULL))
- != EOF)
- {
- switch (c)
- {
- case 'V':
- printf ("ping - %s %s\n", PACKAGE_NAME, PACKAGE_VERSION);
- printf ("Copyright (C) 2005 Free Software Foundation, Inc.\n");
- printf ("%s comes with ABSOLUTELY NO WARRANTY.\n", PACKAGE_NAME);
- printf ("You may redistribute copies of %s\n", PACKAGE_NAME);
- printf ("under the terms of the GNU General Public License.\n");
- printf ("For more information about these matters, ");
- printf ("see the files named COPYING.\n");
- exit (0);
- break;
-
- case 'L':
- show_license ();
- exit (0);
-
- case 'h':
- show_usage ();
- exit (0);
- break;
-
- case 'c':
- count = ping_cvt_number (optarg, 0, 1);
- break;
-
- case 'd':
- socket_type = SO_DEBUG;
- break;
-
- case 'r':
- socket_type = SO_DONTROUTE;
- break;
-
- case 'i':
- {
- double v;
-
- v = strtod (optarg, &p);
- if (*p)
- {
- fprintf (stderr, "Invalid value (`%s' near `%s')\n",
- optarg, p);
- exit (1);
- }
-
- options |= OPT_INTERVAL;
- interval = v * PING_PRECISION;
- if (!is_root && interval < MIN_USER_INTERVAL)
- {
- fprintf (stderr, "Option value too small: %s\n", optarg);
- exit (1);
- }
- }
- break;
-
- case 'p':
- decode_pattern (optarg, &pattern_len, pattern);
- patptr = pattern;
- break;
-
- case 's':
- data_length = ping_cvt_number (optarg, PING_MAX_DATALEN, 1);
- break;
-
- case 'n':
- options |= OPT_NUMERIC;
- break;
-
- case 'q':
- options |= OPT_QUIET;
- break;
-
- case 'R':
- options |= OPT_RROUTE;
- break;
-
- case 'v':
- options |= OPT_VERBOSE;
- break;
-
- case 'l':
- if (!is_root)
- {
- fprintf (stderr, "ping: option not allowed: --preload\n");
- exit (1);
- }
- preload = strtoul (optarg, &p, 0);
- if (*p || preload > INT_MAX)
- {
- fprintf (stderr, "ping: invalid preload value (%s)\n", optarg);
- exit (1);
- }
- break;
-
- case 'f':
- if (is_root == false)
- {
- fprintf (stderr, "ping: option not allowed: --flood\n");
- exit (1);
- }
- options |= OPT_FLOOD;
- setbuf (stdout, (char *) NULL);
- break;
-
- case 't':
- decode_type (optarg);
- break;
-
- case ICMP_ECHO:
- decode_type ("echo");
- break;
-
- case ICMP_TIMESTAMP:
- decode_type ("timestamp");
- break;
-
- case ICMP_ADDRESS:
- if (!is_root)
- {
- fprintf (stderr, "ping: option not allowed: --address\n");
- exit (1);
- }
- decode_type ("address");
- break;
-
- case ICMP_ROUTERDISCOVERY:
- if (!is_root)
- {
- fprintf (stderr, "ping: option not allowed: --router\n");
- exit (1);
- }
- decode_type ("router");
- break;
-
- default:
- fprintf (stderr, "%c: not implemented\n", c);
- exit (1);
- }
- }
-
- argc -= optind;
- argv += optind;
- if (argc == 0)
- {
- show_usage ();
- exit (0);
- }
-
- ping = ping_init (ICMP_ECHO, getpid ());
- if (ping == NULL)
- {
- fprintf (stderr, "can't init ping: %s\n", strerror (errno));
- exit (1);
- }
- ping_set_sockopt (ping, SO_BROADCAST, (char *) &one, sizeof (one));
-
- /* Reset root privileges */
- setuid (getuid ());
-
- if (count != 0)
- ping_set_count (ping, count);
-
- if (socket_type != 0)
- ping_set_sockopt (ping, socket_type, &one, sizeof (one));
-
- if (options & OPT_INTERVAL)
- ping_set_interval (ping, interval);
-
- init_data_buffer (patptr, pattern_len);
-
- return (*ping_type) (argc, argv);
-}
-
-
-
-void
-decode_type (const char *optarg)
-{
- if (strcasecmp (optarg, "echo") == 0)
- ping_type = ping_echo;
- else if (strcasecmp (optarg, "timestamp") == 0)
- ping_type = ping_timestamp;
- else if (strcasecmp (optarg, "address") == 0)
- ping_type = ping_address;
-#if 0
- else if (strcasecmp (optarg, "router") == 0)
- ping_type = ping_router;
-#endif
- else
- {
- fprintf (stderr, "unsupported packet type: %s\n", optarg);
- exit (1);
- }
-}
-
-int volatile stop = 0;
-
-RETSIGTYPE
-sig_int (int signal)
-{
- stop = 1;
-}
-
-int
-ping_run (PING * ping, int (*finish) ())
-{
- fd_set fdset;
- int fdmax;
- struct timeval timeout;
- struct timeval last, intvl, now;
- struct timeval *t = NULL;
- int finishing = 0;
- int nresp = 0;
-
- signal (SIGINT, sig_int);
-
- fdmax = ping->ping_fd + 1;
-
- while (preload--)
- send_echo (ping);
-
- if (options & OPT_FLOOD)
- {
- intvl.tv_sec = 0;
- intvl.tv_usec = 10000;
- }
- else
- PING_SET_INTERVAL (intvl, ping->ping_interval);
-
- gettimeofday (&last, NULL);
- send_echo (ping);
-
- while (!stop)
- {
- int n;
-
- FD_ZERO (&fdset);
- FD_SET (ping->ping_fd, &fdset);
- gettimeofday (&now, NULL);
- timeout.tv_sec = last.tv_sec + intvl.tv_sec - now.tv_sec;
- timeout.tv_usec = last.tv_usec + intvl.tv_usec - now.tv_usec;
-
- while (timeout.tv_usec < 0)
- {
- timeout.tv_usec += 1000000;
- timeout.tv_sec--;
- }
- while (timeout.tv_usec >= 1000000)
- {
- timeout.tv_usec -= 1000000;
- timeout.tv_sec++;
- }
-
- if (timeout.tv_sec < 0)
- timeout.tv_sec = timeout.tv_usec = 0;
-
- n = select (fdmax, &fdset, NULL, NULL, &timeout);
- if (n < 0)
- {
- if (errno != EINTR)
- perror ("select");
- continue;
- }
- else if (n == 1)
- {
- if (ping_recv (ping) == 0)
- nresp++;
- if (t == 0)
- {
- gettimeofday (&now, NULL);
- t = &now;
- }
- if (ping->ping_count && nresp >= ping->ping_count)
- break;
- }
- else
- {
- if (!ping->ping_count || ping->ping_num_xmit < ping->ping_count)
- {
- send_echo (ping);
- if (!(options & OPT_QUIET) && options & OPT_FLOOD)
- putchar ('.');
- }
- else if (finishing)
- break;
- else
- {
- finishing = 1;
-
- intvl.tv_sec = MAXWAIT;
- }
- gettimeofday (&last, NULL);
- }
- }
- if (finish)
- return (*finish) ();
- return 0;
-}
-
-int
-send_echo (PING * ping)
-{
- int off = 0;
-
- if (PING_TIMING (data_length))
- {
- struct timeval tv;
- gettimeofday (&tv, NULL);
- ping_set_data (ping, &tv, 0, sizeof (tv));
- off += sizeof (tv);
- }
- if (data_buffer)
- ping_set_data (ping, data_buffer, off,
- data_length > PING_HEADER_LEN ?
- data_length - PING_HEADER_LEN : data_length);
- return ping_xmit (ping);
-}
-
-int
-ping_finish ()
-{
- fflush (stdout);
- printf ("--- %s ping statistics ---\n", ping->ping_hostname);
- printf ("%ld packets transmitted, ", ping->ping_num_xmit);
- printf ("%ld packets received, ", ping->ping_num_recv);
- if (ping->ping_num_rept)
- printf ("+%ld duplicates, ", ping->ping_num_rept);
- if (ping->ping_num_xmit)
- {
- if (ping->ping_num_recv > ping->ping_num_xmit)
- printf ("-- somebody's printing up packets!");
- else
- printf ("%d%% packet loss",
- (int) (((ping->ping_num_xmit - ping->ping_num_recv) * 100) /
- ping->ping_num_xmit));
-
- }
- printf ("\n");
- return 0;
-}
-
-void
-show_usage (void)
-{
- printf ("\
-Usage: ping [OPTION]... [ADDRESS]...\n\
-\n\
-Informational options:\n\
- -h, --help display this help and exit\n\
- -L, --license display license and exit\n\
- -V, --version output version information and exit\n\
-Options controlling ICMP request types:\n\
- --echo Send ICMP_ECHO requests (default)\n\
-* --address Send ICMP_ADDRESS packets\n\
- --timestamp Send ICMP_TIMESTAMP packets\n\
-* --router Send ICMP_ROUTERDISCOVERY packets\n\
-Options valid for all request types:\n\
- -c, --count N stop after sending N packets (default: %d)\n\
- -d, --debug set the SO_DEBUG option\n\
- -i, --interval N wait N seconds between sending each packet\n\
- -n, --numeric do not resolve host addresses\n\
- -r, --ignore-routing send directly to a host on an attached network\n\
- -v, --verbose verbose output\n\
-Options valid for --echo requests:\n\
-* -f, --flood flood ping \n\
-* -l, --preload N send N packets as fast as possible before falling into\n\
- normal mode of behavior\n\
- -p, --pattern PAT fill ICMP packet with given pattern (hex)\n\
- -q, --quiet quiet output\n\
- -R, --route record route\n\
- -s, --size N set number of data octets to send\n\
-\n\
-Options marked with an * are available only to super-user\n\
-\n\
-Report bugs to <" PACKAGE_BUGREPORT ">.\n\
-", DEFAULT_PING_COUNT);
-}
diff -urNp ../inetutils/ping/ping_impl.h ping/ping_impl.h
--- ../inetutils/ping/ping_impl.h 2006-10-21 20:54:20.000000000 +0530
+++ ping/ping_impl.h 2007-03-30 00:25:59.000000000 +0530
@@ -24,7 +24,7 @@ struct ping_stat
extern unsigned options;
extern PING *ping;
-extern int is_root;
+/*extern int is_root;*/
extern unsigned long preload;
extern u_char *data_buffer;
extern size_t data_length;
--
GPG key ID: 63D4A5A7
Key server: pgp.mit.edu
- [bug-inetutils] Argpifying ping., Debarshi 'Rishi' Ray, 2007/03/27
- Re: [bug-inetutils] Argpifying ping., Barry deFreese, 2007/03/27
- Re: [bug-inetutils] Argpifying ping., Sergey Poznyakoff, 2007/03/28
- Re: [bug-inetutils] Argpifying ping.,
Debarshi 'Rishi' Ray <=
- Re: [bug-inetutils] Argpifying ping., Alfred M. Szmidt, 2007/03/29
- Re: [bug-inetutils] Argpifying ping., Alfred M. Szmidt, 2007/03/29
- Re: [bug-inetutils] Argpifying ping., Sergey Poznyakoff, 2007/03/30
- Re: [bug-inetutils] Argpifying ping., Alfred M. Szmidt, 2007/03/30
- Re: [bug-inetutils] Argpifying ping., Sergey Poznyakoff, 2007/03/30
- Re: [bug-inetutils] Argpifying ping., Debarshi 'Rishi' Ray, 2007/03/30
- Re: [bug-inetutils] Argpifying ping., Sergey Poznyakoff, 2007/03/31
- Re: [bug-inetutils] Argpifying ping., Alfred M. Szmidt, 2007/03/31
- Re: [bug-inetutils] Argpifying ping., Debarshi 'Rishi' Ray, 2007/03/31
- Re: [bug-inetutils] Argpifying ping., Sergey Poznyakoff, 2007/03/31