diff options
author | Florian Fainelli <f.fainelli@gmail.com> | 2014-08-27 16:01:25 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2014-08-27 16:01:25 +0200 |
commit | 6ff055115798166e172039284448be758b04e195 (patch) | |
tree | 513eea525513dbaf06c9515a6e579d5b88f3270b | |
parent | 962c4e822012a6d4c83b869eb47506881b4abc57 (diff) | |
download | busybox-w32-6ff055115798166e172039284448be758b04e195.tar.gz busybox-w32-6ff055115798166e172039284448be758b04e195.tar.bz2 busybox-w32-6ff055115798166e172039284448be758b04e195.zip |
ping: add -p to specify data pattern
function old new delta
common_ping_main 1788 1831 +43
sendping6 56 82 +26
sendping4 82 108 +26
packed_usage 29959 29938 -21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 95/-21) Total: 74 bytes
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/ping.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/networking/ping.c b/networking/ping.c index 5e4771f5a..c475395e7 100644 --- a/networking/ping.c +++ b/networking/ping.c | |||
@@ -100,8 +100,9 @@ | |||
100 | //usage: "\n (after all -c CNT packets are sent)" | 100 | //usage: "\n (after all -c CNT packets are sent)" |
101 | //usage: "\n -w SEC Seconds until ping exits (default:infinite)" | 101 | //usage: "\n -w SEC Seconds until ping exits (default:infinite)" |
102 | //usage: "\n (can exit earlier with -c CNT)" | 102 | //usage: "\n (can exit earlier with -c CNT)" |
103 | //usage: "\n -q Quiet, only displays output at start" | 103 | //usage: "\n -q Quiet, only display output at start" |
104 | //usage: "\n and when finished" | 104 | //usage: "\n and when finished" |
105 | //usage: "\n -p Pattern to use for payload" | ||
105 | //usage: | 106 | //usage: |
106 | //usage:# define ping6_trivial_usage | 107 | //usage:# define ping6_trivial_usage |
107 | //usage: "[OPTIONS] HOST" | 108 | //usage: "[OPTIONS] HOST" |
@@ -110,8 +111,9 @@ | |||
110 | //usage: "\n -c CNT Send only CNT pings" | 111 | //usage: "\n -c CNT Send only CNT pings" |
111 | //usage: "\n -s SIZE Send SIZE data bytes in packets (default:56)" | 112 | //usage: "\n -s SIZE Send SIZE data bytes in packets (default:56)" |
112 | //usage: "\n -I IFACE/IP Use interface or IP address as source" | 113 | //usage: "\n -I IFACE/IP Use interface or IP address as source" |
113 | //usage: "\n -q Quiet, only displays output at start" | 114 | //usage: "\n -q Quiet, only display output at start" |
114 | //usage: "\n and when finished" | 115 | //usage: "\n and when finished" |
116 | //usage: "\n -p Pattern to use for payload" | ||
115 | //usage: | 117 | //usage: |
116 | //usage:#endif | 118 | //usage:#endif |
117 | //usage: | 119 | //usage: |
@@ -330,7 +332,7 @@ static int common_ping_main(sa_family_t af, char **argv) | |||
330 | 332 | ||
331 | /* Full(er) version */ | 333 | /* Full(er) version */ |
332 | 334 | ||
333 | #define OPT_STRING ("qvc:s:t:w:W:I:n4" IF_PING6("6")) | 335 | #define OPT_STRING ("qvc:s:t:w:W:I:np:4" IF_PING6("6")) |
334 | enum { | 336 | enum { |
335 | OPT_QUIET = 1 << 0, | 337 | OPT_QUIET = 1 << 0, |
336 | OPT_VERBOSE = 1 << 1, | 338 | OPT_VERBOSE = 1 << 1, |
@@ -341,8 +343,9 @@ enum { | |||
341 | OPT_W = 1 << 6, | 343 | OPT_W = 1 << 6, |
342 | OPT_I = 1 << 7, | 344 | OPT_I = 1 << 7, |
343 | /*OPT_n = 1 << 8, - ignored */ | 345 | /*OPT_n = 1 << 8, - ignored */ |
344 | OPT_IPV4 = 1 << 9, | 346 | OPT_p = 1 << 9, |
345 | OPT_IPV6 = (1 << 10) * ENABLE_PING6, | 347 | OPT_IPV4 = 1 << 10, |
348 | OPT_IPV6 = (1 << 11) * ENABLE_PING6, | ||
346 | }; | 349 | }; |
347 | 350 | ||
348 | 351 | ||
@@ -355,6 +358,7 @@ struct globals { | |||
355 | unsigned opt_ttl; | 358 | unsigned opt_ttl; |
356 | unsigned long ntransmitted, nreceived, nrepeats; | 359 | unsigned long ntransmitted, nreceived, nrepeats; |
357 | uint16_t myid; | 360 | uint16_t myid; |
361 | uint8_t pattern; | ||
358 | unsigned tmin, tmax; /* in us */ | 362 | unsigned tmin, tmax; /* in us */ |
359 | unsigned long long tsum; /* in us, sum of all times */ | 363 | unsigned long long tsum; /* in us, sum of all times */ |
360 | unsigned deadline; | 364 | unsigned deadline; |
@@ -485,7 +489,7 @@ static void sendping4(int junk UNUSED_PARAM) | |||
485 | { | 489 | { |
486 | struct icmp *pkt = G.snd_packet; | 490 | struct icmp *pkt = G.snd_packet; |
487 | 491 | ||
488 | //memset(pkt, 0, datalen + ICMP_MINLEN + 4); - G.snd_packet was xzalloced | 492 | memset(pkt, G.pattern, datalen + ICMP_MINLEN + 4); |
489 | pkt->icmp_type = ICMP_ECHO; | 493 | pkt->icmp_type = ICMP_ECHO; |
490 | /*pkt->icmp_code = 0;*/ | 494 | /*pkt->icmp_code = 0;*/ |
491 | pkt->icmp_cksum = 0; /* cksum is calculated with this field set to 0 */ | 495 | pkt->icmp_cksum = 0; /* cksum is calculated with this field set to 0 */ |
@@ -508,7 +512,7 @@ static void sendping6(int junk UNUSED_PARAM) | |||
508 | { | 512 | { |
509 | struct icmp6_hdr *pkt = G.snd_packet; | 513 | struct icmp6_hdr *pkt = G.snd_packet; |
510 | 514 | ||
511 | //memset(pkt, 0, datalen + sizeof(struct icmp6_hdr) + 4); | 515 | memset(pkt, G.pattern, datalen + sizeof(struct icmp6_hdr) + 4); |
512 | pkt->icmp6_type = ICMP6_ECHO_REQUEST; | 516 | pkt->icmp6_type = ICMP6_ECHO_REQUEST; |
513 | /*pkt->icmp6_code = 0;*/ | 517 | /*pkt->icmp6_code = 0;*/ |
514 | /*pkt->icmp6_cksum = 0;*/ | 518 | /*pkt->icmp6_cksum = 0;*/ |
@@ -850,13 +854,13 @@ static void ping(len_and_sockaddr *lsa) | |||
850 | static int common_ping_main(int opt, char **argv) | 854 | static int common_ping_main(int opt, char **argv) |
851 | { | 855 | { |
852 | len_and_sockaddr *lsa; | 856 | len_and_sockaddr *lsa; |
853 | char *str_s; | 857 | char *str_s, *str_p; |
854 | 858 | ||
855 | INIT_G(); | 859 | INIT_G(); |
856 | 860 | ||
857 | /* exactly one argument needed; -v and -q don't mix; -c NUM, -t NUM, -w NUM, -W NUM */ | 861 | /* exactly one argument needed; -v and -q don't mix; -c NUM, -t NUM, -w NUM, -W NUM */ |
858 | opt_complementary = "=1:q--v:v--q:c+:t+:w+:W+"; | 862 | opt_complementary = "=1:q--v:v--q:c+:t+:w+:W+"; |
859 | opt |= getopt32(argv, OPT_STRING, &pingcount, &str_s, &opt_ttl, &deadline, &timeout, &str_I); | 863 | opt |= getopt32(argv, OPT_STRING, &pingcount, &str_s, &opt_ttl, &deadline, &timeout, &str_I, &str_p); |
860 | if (opt & OPT_s) | 864 | if (opt & OPT_s) |
861 | datalen = xatou16(str_s); // -s | 865 | datalen = xatou16(str_s); // -s |
862 | if (opt & OPT_I) { // -I | 866 | if (opt & OPT_I) { // -I |
@@ -867,6 +871,9 @@ static int common_ping_main(int opt, char **argv) | |||
867 | str_I = NULL; /* don't try to bind to device later */ | 871 | str_I = NULL; /* don't try to bind to device later */ |
868 | } | 872 | } |
869 | } | 873 | } |
874 | if (opt & OPT_p) | ||
875 | G.pattern = xstrtou_range(str_p, 16, 0, 255); | ||
876 | |||
870 | myid = (uint16_t) getpid(); | 877 | myid = (uint16_t) getpid(); |
871 | hostname = argv[optind]; | 878 | hostname = argv[optind]; |
872 | #if ENABLE_PING6 | 879 | #if ENABLE_PING6 |