From 07a3b9192001369c7bf74cd4f096dc49703b24e9 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 21 Oct 2018 21:36:51 -0500 Subject: Add % to lib/args.c (long time in milliseconds), add xmillitime(), redo xparsetime() not to need floating point, adjust callers. --- toys/net/ping.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) (limited to 'toys/net') diff --git a/toys/net/ping.c b/toys/net/ping.c index 752879a2..ad7679fd 100644 --- a/toys/net/ping.c +++ b/toys/net/ping.c @@ -11,7 +11,7 @@ * Yes, I wimped out and capped -s at sizeof(toybuf), waiting for a complaint... // -s > 4088 = sizeof(toybuf)-sizeof(struct icmphdr), then kernel adds 20 bytes -USE_PING(NEWTOY(ping, "<1>1m#t#<0>255=64c#<0=3s#<0>4088=56I:i:W#<0=3w#<0qf46[-46]", TOYFLAG_USR|TOYFLAG_BIN)) +USE_PING(NEWTOY(ping, "<1>1m#t#<0>255=64c#<0=3s#<0>4088=56I:i%W#<0=3w#<0qf46[-46]", TOYFLAG_USR|TOYFLAG_BIN)) USE_PING(OLDTOY(ping6, ping, TOYFLAG_USR|TOYFLAG_BIN)) config PING @@ -47,18 +47,12 @@ config PING #include GLOBALS( - long w; - long W; - char *i; + long w, W, i; char *I; - long s; - long c; - long t; - long m; + long s, c, t, m; struct sockaddr *sa; int sock; - long i_ms; unsigned long sent, recv, fugit, min, max; ) @@ -115,13 +109,8 @@ void ping_main(void) struct icmphdr *ih = (void *)toybuf; // Interval - if (TT.i) { - long frac; - - TT.i_ms = xparsetime(TT.i, 1000, &frac) * 1000; - TT.i_ms += frac; - if (TT.i_ms<200 && getuid()) error_exit("need root for -i <200"); - } else TT.i_ms = (toys.optflags&FLAG_f) ? 200 : 1000; + if (!(toys.optflags&FLAG_i)) TT.i = (toys.optflags&FLAG_f) ? 200 : 1000; + else if (TT.i<200 && getuid()) error_exit("need root for -i <200"); if (!(toys.optflags&FLAG_s)) TT.s = 56; // 64-PHDR_LEN if ((toys.optflags&(FLAG_f|FLAG_c)) == FLAG_f) TT.c = 15; @@ -230,7 +219,7 @@ void ping_main(void) // Time to send the next packet? if (!tW && tnext-tnow <= 0) { - tnext += TT.i_ms; + tnext += TT.i; memset(ih, 0, sizeof(*ih)); ih->type = (ai->ai_family == AF_INET) ? 8 : 128; -- cgit v1.2.3