aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-08-03 18:50:50 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-08-03 18:50:50 +0200
commit36d198ec6dc8f214a1e9122b993581613e6d7f12 (patch)
treebb87e126285bca6e994c449ab7157687703c11b4
parentc9720a761e88e83265b4d75808533cdfbc66075b (diff)
downloadbusybox-w32-36d198ec6dc8f214a1e9122b993581613e6d7f12.tar.gz
busybox-w32-36d198ec6dc8f214a1e9122b993581613e6d7f12.tar.bz2
busybox-w32-36d198ec6dc8f214a1e9122b993581613e6d7f12.zip
ping: implement -i SEC
function old new delta common_ping_main 1862 1968 +106 ualarm - 79 +79 packed_usage 32858 32897 +39 sendping_tail 204 218 +14 ------------------------------------------------------------------------------ (add/remove: 5/0 grow/shrink: 3/0 up/down: 320/0) Total: 320 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/ping.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/networking/ping.c b/networking/ping.c
index 8f85d3ec2..a579ea4ae 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -74,6 +74,7 @@
74//usage: ) 74//usage: )
75//usage: "\n -c CNT Send only CNT pings" 75//usage: "\n -c CNT Send only CNT pings"
76//usage: "\n -s SIZE Send SIZE data bytes in packets (default 56)" 76//usage: "\n -s SIZE Send SIZE data bytes in packets (default 56)"
77//usage: "\n -i SECS Interval"
77//usage: "\n -A Ping as soon as reply is recevied" 78//usage: "\n -A Ping as soon as reply is recevied"
78//usage: "\n -t TTL Set TTL" 79//usage: "\n -t TTL Set TTL"
79//usage: "\n -I IFACE/IP Source interface or IP address" 80//usage: "\n -I IFACE/IP Source interface or IP address"
@@ -91,6 +92,7 @@
91//usage: "Send ICMP ECHO_REQUEST packets to network hosts\n" 92//usage: "Send ICMP ECHO_REQUEST packets to network hosts\n"
92//usage: "\n -c CNT Send only CNT pings" 93//usage: "\n -c CNT Send only CNT pings"
93//usage: "\n -s SIZE Send SIZE data bytes in packets (default 56)" 94//usage: "\n -s SIZE Send SIZE data bytes in packets (default 56)"
95//usage: "\n -i SECS Interval"
94//usage: "\n -A Ping as soon as reply is recevied" 96//usage: "\n -A Ping as soon as reply is recevied"
95//usage: "\n -I IFACE/IP Source interface or IP address" 97//usage: "\n -I IFACE/IP Source interface or IP address"
96//usage: "\n -q Quiet, only display output at start" 98//usage: "\n -q Quiet, only display output at start"
@@ -350,7 +352,7 @@ static int common_ping_main(sa_family_t af, char **argv)
350/* Full(er) version */ 352/* Full(er) version */
351 353
352/* -c NUM, -t NUM, -w NUM, -W NUM */ 354/* -c NUM, -t NUM, -w NUM, -W NUM */
353#define OPT_STRING "qvAc:+s:t:+w:+W:+I:np:4"IF_PING6("6") 355#define OPT_STRING "qvAc:+s:t:+w:+W:+I:np:i:4"IF_PING6("6")
354enum { 356enum {
355 OPT_QUIET = 1 << 0, 357 OPT_QUIET = 1 << 0,
356 OPT_VERBOSE = 1 << 1, 358 OPT_VERBOSE = 1 << 1,
@@ -363,8 +365,9 @@ enum {
363 OPT_I = 1 << 8, 365 OPT_I = 1 << 8,
364 /*OPT_n = 1 << 9, - ignored */ 366 /*OPT_n = 1 << 9, - ignored */
365 OPT_p = 1 << 10, 367 OPT_p = 1 << 10,
366 OPT_IPV4 = 1 << 11, 368 OPT_i = 1 << 11,
367 OPT_IPV6 = (1 << 12) * ENABLE_PING6, 369 OPT_IPV4 = 1 << 12,
370 OPT_IPV6 = (1 << 13) * ENABLE_PING6,
368}; 371};
369 372
370 373
@@ -382,6 +385,7 @@ struct globals {
382 unsigned long long tsum; /* in us, sum of all times */ 385 unsigned long long tsum; /* in us, sum of all times */
383 unsigned cur_us; /* low word only, we don't need more */ 386 unsigned cur_us; /* low word only, we don't need more */
384 unsigned deadline_us; 387 unsigned deadline_us;
388 unsigned interval_us;
385 unsigned timeout; 389 unsigned timeout;
386 unsigned sizeof_rcv_packet; 390 unsigned sizeof_rcv_packet;
387 char *rcv_packet; /* [datalen + MAXIPLEN + MAXICMPLEN] */ 391 char *rcv_packet; /* [datalen + MAXIPLEN + MAXICMPLEN] */
@@ -483,7 +487,7 @@ static void sendping_tail(void (*sp)(int), int size_pkt)
483 if (pingcount == 0 || G.ntransmitted < pingcount) { 487 if (pingcount == 0 || G.ntransmitted < pingcount) {
484 /* Didn't send all pings yet - schedule next in 1s */ 488 /* Didn't send all pings yet - schedule next in 1s */
485 signal(SIGALRM, sp); 489 signal(SIGALRM, sp);
486 alarm(PINGINTERVAL); 490 ualarm(G.interval_us, 0);
487 } else { /* -c NN, and all NN are sent */ 491 } else { /* -c NN, and all NN are sent */
488 /* Wait for the last ping to come back. 492 /* Wait for the last ping to come back.
489 * -W timeout: wait for a response in seconds. 493 * -W timeout: wait for a response in seconds.
@@ -885,6 +889,8 @@ static int common_ping_main(int opt, char **argv)
885{ 889{
886 len_and_sockaddr *lsa; 890 len_and_sockaddr *lsa;
887 char *str_s, *str_p; 891 char *str_s, *str_p;
892 char *str_i = (char*)"1";
893 duration_t interval;
888 894
889 INIT_G(); 895 INIT_G();
890 896
@@ -892,7 +898,7 @@ static int common_ping_main(int opt, char **argv)
892 OPT_STRING 898 OPT_STRING
893 /* exactly one arg; -v and -q don't mix */ 899 /* exactly one arg; -v and -q don't mix */
894 "\0" "=1:q--v:v--q", 900 "\0" "=1:q--v:v--q",
895 &pingcount, &str_s, &opt_ttl, &G.deadline_us, &timeout, &str_I, &str_p 901 &pingcount, &str_s, &opt_ttl, &G.deadline_us, &timeout, &str_I, &str_p, &str_i
896 ); 902 );
897 if (opt & OPT_s) 903 if (opt & OPT_s)
898 datalen = xatou16(str_s); // -s 904 datalen = xatou16(str_s); // -s
@@ -910,6 +916,10 @@ static int common_ping_main(int opt, char **argv)
910 unsigned d = G.deadline_us < INT_MAX/1000000 ? G.deadline_us : INT_MAX/1000000; 916 unsigned d = G.deadline_us < INT_MAX/1000000 ? G.deadline_us : INT_MAX/1000000;
911 G.deadline_us = 1 | ((d * 1000000) + monotonic_us()); 917 G.deadline_us = 1 | ((d * 1000000) + monotonic_us());
912 } 918 }
919 interval = parse_duration_str(str_i);
920 if (interval > INT_MAX/1000000)
921 interval = INT_MAX/1000000;
922 G.interval_us = interval * 1000000;
913 923
914 myid = (uint16_t) getpid(); 924 myid = (uint16_t) getpid();
915 hostname = argv[optind]; 925 hostname = argv[optind];