Index: ping.c =================================================================== RCS file: /var/cvs/busybox/networking/ping.c,v retrieving revision 1.56 diff -u -b -B -w -p -r1.56 ping.c --- a/ping.c 15 Mar 2004 08:28:48 -0000 1.56 +++ b/ping.c 9 Jun 2004 15:32:17 -0000 @@ -57,8 +57,8 @@ static const int MAXIPLEN = 60; static const int MAXICMPLEN = 76; static const int MAXPACKET = 65468; #define MAX_DUP_CHK (8 * 128) -static const int MAXWAIT = 10; static const int PINGINTERVAL = 1; /* second */ +static int MAXWAIT = 10; #define O_QUIET (1 << 0) @@ -393,44 +393,40 @@ static void ping(const char *host) extern int ping_main(int argc, char **argv) { - char *thisarg; + int opt; + if (argc < 1) { + bb_show_usage(); + return EXIT_FAILURE; + } datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */ + /* eh what gcc bug was this? what year? I call it bloat! */ - argc--; - argv++; options = 0; /* Parse any options */ - while (argc >= 1 && **argv == '-') { - thisarg = *argv; - thisarg++; - switch (*thisarg) { + while ((opt = (int) getopt(argc, argv, "qc:s:w:")) != EOF) { + printf("DEBUG: getopt() = %c; argc=%d optind=%d\n", opt, argc, optind); + switch (opt) { case 'q': options |= O_QUIET; break; case 'c': - if (--argc <= 0) - bb_show_usage(); - argv++; - pingcount = atoi(*argv); + pingcount = bb_xgetlarg(optarg, 10, 10, 10000);; break; case 's': - if (--argc <= 0) - bb_show_usage(); - argv++; - datalen = atoi(*argv); + datalen = bb_xgetlarg(optarg, 10, 10, 10000); + break; + case 'w': + MAXWAIT = bb_xgetlarg(optarg, 10, 10, 10000); break; default: + printf("DEBUG: default getopt() = %c\n", opt); bb_show_usage(); + break; } - argc--; - argv++; } - if (argc < 1) - bb_show_usage(); - myid = getpid() & 0xFFFF; - ping(*argv); + ping(argv[optind]); return EXIT_SUCCESS; } #endif /* ! CONFIG_FEATURE_FANCY_PING */