aboutsummaryrefslogtreecommitdiff
path: root/toys/net
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2018-10-21 21:36:51 -0500
committerRob Landley <rob@landley.net>2018-10-21 21:36:51 -0500
commit07a3b9192001369c7bf74cd4f096dc49703b24e9 (patch)
treecfb6f13f8a275f0ae21d6b577baa69d8a05f9ce7 /toys/net
parent3e0b077ec236aa26bfeb290f3cd7973ec3fbcb7d (diff)
downloadtoybox-07a3b9192001369c7bf74cd4f096dc49703b24e9.tar.gz
Add % to lib/args.c (long time in milliseconds), add xmillitime(), redo
xparsetime() not to need floating point, adjust callers.
Diffstat (limited to 'toys/net')
-rw-r--r--toys/net/ping.c23
1 files changed, 6 insertions, 17 deletions
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 <netinet/ip_icmp.h>
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;