diff options
-rw-r--r-- | networking/ping.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/networking/ping.c b/networking/ping.c index bf750d032..8f85d3ec2 100644 --- a/networking/ping.c +++ b/networking/ping.c | |||
@@ -380,7 +380,8 @@ struct globals { | |||
380 | uint8_t pattern; | 380 | uint8_t pattern; |
381 | unsigned tmin, tmax; /* in us */ | 381 | unsigned tmin, tmax; /* in us */ |
382 | unsigned long long tsum; /* in us, sum of all times */ | 382 | unsigned long long tsum; /* in us, sum of all times */ |
383 | unsigned deadline_ms; | 383 | unsigned cur_us; /* low word only, we don't need more */ |
384 | unsigned deadline_us; | ||
384 | unsigned timeout; | 385 | unsigned timeout; |
385 | unsigned sizeof_rcv_packet; | 386 | unsigned sizeof_rcv_packet; |
386 | char *rcv_packet; /* [datalen + MAXIPLEN + MAXICMPLEN] */ | 387 | char *rcv_packet; /* [datalen + MAXIPLEN + MAXICMPLEN] */ |
@@ -455,7 +456,7 @@ static void print_stats_and_exit(int junk UNUSED_PARAM) | |||
455 | tmax / 1000, tmax % 1000); | 456 | tmax / 1000, tmax % 1000); |
456 | } | 457 | } |
457 | /* if condition is true, exit with 1 -- 'failure' */ | 458 | /* if condition is true, exit with 1 -- 'failure' */ |
458 | exit(nrecv == 0 || (G.deadline_ms && nrecv < pingcount)); | 459 | exit(nrecv == 0 || (G.deadline_us && nrecv < pingcount)); |
459 | } | 460 | } |
460 | 461 | ||
461 | static void sendping_tail(void (*sp)(int), int size_pkt) | 462 | static void sendping_tail(void (*sp)(int), int size_pkt) |
@@ -467,8 +468,8 @@ static void sendping_tail(void (*sp)(int), int size_pkt) | |||
467 | 468 | ||
468 | size_pkt += datalen; | 469 | size_pkt += datalen; |
469 | 470 | ||
470 | if (G.deadline_ms) { | 471 | if (G.deadline_us) { |
471 | unsigned n = ((unsigned)monotonic_ms()) - G.deadline_ms; | 472 | unsigned n = G.cur_us - G.deadline_us; |
472 | if ((int)n >= 0) | 473 | if ((int)n >= 0) |
473 | print_stats_and_exit(0); | 474 | print_stats_and_exit(0); |
474 | } | 475 | } |
@@ -517,7 +518,7 @@ static void sendping4(int junk UNUSED_PARAM) | |||
517 | */ | 518 | */ |
518 | /*if (datalen >= 4)*/ | 519 | /*if (datalen >= 4)*/ |
519 | /* No hton: we'll read it back on the same machine */ | 520 | /* No hton: we'll read it back on the same machine */ |
520 | *(uint32_t*)&pkt->icmp_dun = monotonic_us(); | 521 | *(uint32_t*)&pkt->icmp_dun = G.cur_us = monotonic_us(); |
521 | 522 | ||
522 | pkt->icmp_cksum = inet_cksum((uint16_t *) pkt, datalen + ICMP_MINLEN); | 523 | pkt->icmp_cksum = inet_cksum((uint16_t *) pkt, datalen + ICMP_MINLEN); |
523 | 524 | ||
@@ -536,7 +537,7 @@ static void sendping6(int junk UNUSED_PARAM) | |||
536 | pkt->icmp6_id = myid; | 537 | pkt->icmp6_id = myid; |
537 | 538 | ||
538 | /*if (datalen >= 4)*/ | 539 | /*if (datalen >= 4)*/ |
539 | *(bb__aliased_uint32_t*)(&pkt->icmp6_data8[4]) = monotonic_us(); | 540 | *(bb__aliased_uint32_t*)(&pkt->icmp6_data8[4]) = G.cur_us = monotonic_us(); |
540 | 541 | ||
541 | //TODO? pkt->icmp_cksum = inet_cksum(...); | 542 | //TODO? pkt->icmp_cksum = inet_cksum(...); |
542 | 543 | ||
@@ -891,7 +892,7 @@ static int common_ping_main(int opt, char **argv) | |||
891 | OPT_STRING | 892 | OPT_STRING |
892 | /* exactly one arg; -v and -q don't mix */ | 893 | /* exactly one arg; -v and -q don't mix */ |
893 | "\0" "=1:q--v:v--q", | 894 | "\0" "=1:q--v:v--q", |
894 | &pingcount, &str_s, &opt_ttl, &G.deadline_ms, &timeout, &str_I, &str_p | 895 | &pingcount, &str_s, &opt_ttl, &G.deadline_us, &timeout, &str_I, &str_p |
895 | ); | 896 | ); |
896 | if (opt & OPT_s) | 897 | if (opt & OPT_s) |
897 | datalen = xatou16(str_s); // -s | 898 | datalen = xatou16(str_s); // -s |
@@ -905,9 +906,9 @@ static int common_ping_main(int opt, char **argv) | |||
905 | } | 906 | } |
906 | if (opt & OPT_p) | 907 | if (opt & OPT_p) |
907 | G.pattern = xstrtou_range(str_p, 16, 0, 255); | 908 | G.pattern = xstrtou_range(str_p, 16, 0, 255); |
908 | if (G.deadline_ms) { | 909 | if (G.deadline_us) { |
909 | unsigned d = G.deadline_ms < INT_MAX/1000 ? G.deadline_ms : INT_MAX/1000; | 910 | unsigned d = G.deadline_us < INT_MAX/1000000 ? G.deadline_us : INT_MAX/1000000; |
910 | G.deadline_ms = 1 | ((d * 1000) + monotonic_ms()); | 911 | G.deadline_us = 1 | ((d * 1000000) + monotonic_us()); |
911 | } | 912 | } |
912 | 913 | ||
913 | myid = (uint16_t) getpid(); | 914 | myid = (uint16_t) getpid(); |