diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-29 18:03:54 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-29 18:03:54 +0000 |
commit | e935602ff5d5a45be56585b8bad44194c3e837a3 (patch) | |
tree | d132adcb0f5e165f96cc85ac0baef036e38812b0 /networking/ping.c | |
parent | 86811803e304b63b71d3ddac91ad4e1cd741344f (diff) | |
download | busybox-w32-e935602ff5d5a45be56585b8bad44194c3e837a3.tar.gz busybox-w32-e935602ff5d5a45be56585b8bad44194c3e837a3.tar.bz2 busybox-w32-e935602ff5d5a45be56585b8bad44194c3e837a3.zip |
taskset: fix incorrect rage spec and allow 0xXXX input
ping: shave off 60 bytes
Diffstat (limited to 'networking/ping.c')
-rw-r--r-- | networking/ping.c | 67 |
1 files changed, 30 insertions, 37 deletions
diff --git a/networking/ping.c b/networking/ping.c index d8a3b772f..52e48867e 100644 --- a/networking/ping.c +++ b/networking/ping.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <net/if.h> | 28 | #include <net/if.h> |
29 | #include <netinet/ip_icmp.h> | 29 | #include <netinet/ip_icmp.h> |
30 | #include "busybox.h" | 30 | #include "busybox.h" |
31 | |||
31 | #if ENABLE_PING6 | 32 | #if ENABLE_PING6 |
32 | #include <netinet/icmp6.h> | 33 | #include <netinet/icmp6.h> |
33 | /* I see RENUMBERED constants in bits/in.h - !!? | 34 | /* I see RENUMBERED constants in bits/in.h - !!? |
@@ -85,7 +86,7 @@ static void noresp(int ign ATTRIBUTE_UNUSED) | |||
85 | exit(EXIT_FAILURE); | 86 | exit(EXIT_FAILURE); |
86 | } | 87 | } |
87 | 88 | ||
88 | static void ping(len_and_sockaddr *lsa) | 89 | static void ping4(len_and_sockaddr *lsa) |
89 | { | 90 | { |
90 | struct sockaddr_in pingaddr; | 91 | struct sockaddr_in pingaddr; |
91 | struct icmp *pkt; | 92 | struct icmp *pkt; |
@@ -222,7 +223,7 @@ int ping_main(int argc, char **argv) | |||
222 | ping6(lsa); | 223 | ping6(lsa); |
223 | else | 224 | else |
224 | #endif | 225 | #endif |
225 | ping(lsa); | 226 | ping4(lsa); |
226 | printf("%s is alive!\n", hostname); | 227 | printf("%s is alive!\n", hostname); |
227 | return EXIT_SUCCESS; | 228 | return EXIT_SUCCESS; |
228 | } | 229 | } |
@@ -300,7 +301,25 @@ static void pingstats(int junk ATTRIBUTE_UNUSED) | |||
300 | exit(status); | 301 | exit(status); |
301 | } | 302 | } |
302 | 303 | ||
303 | static void sendping(int junk ATTRIBUTE_UNUSED) | 304 | static void sendping_tail(void (*sp)(int), int sz, int sizeof_packet) |
305 | { | ||
306 | if (sz < 0) | ||
307 | bb_perror_msg_and_die("sendto"); | ||
308 | if (sz != sizeof_packet) | ||
309 | bb_error_msg_and_die("ping wrote %d chars; %d expected", sz, | ||
310 | sizeof_packet); | ||
311 | |||
312 | signal(SIGALRM, sp); | ||
313 | if (pingcount == 0 || ntransmitted < pingcount) { /* schedule next in 1s */ | ||
314 | alarm(PINGINTERVAL); | ||
315 | } else { /* done, wait for the last ping to come back */ | ||
316 | /* todo, don't necessarily need to wait so long... */ | ||
317 | signal(SIGALRM, pingstats); | ||
318 | alarm(MAXWAIT); | ||
319 | } | ||
320 | } | ||
321 | |||
322 | static void sendping4(int junk ATTRIBUTE_UNUSED) | ||
304 | { | 323 | { |
305 | struct icmp *pkt; | 324 | struct icmp *pkt; |
306 | int i; | 325 | int i; |
@@ -322,20 +341,7 @@ static void sendping(int junk ATTRIBUTE_UNUSED) | |||
322 | i = sendto(pingsock, packet, sizeof(packet), 0, | 341 | i = sendto(pingsock, packet, sizeof(packet), 0, |
323 | &pingaddr.sa, sizeof(pingaddr.sin)); | 342 | &pingaddr.sa, sizeof(pingaddr.sin)); |
324 | 343 | ||
325 | if (i < 0) | 344 | sendping_tail(sendping4, i, sizeof(packet)); |
326 | bb_perror_msg_and_die("sendto"); | ||
327 | if ((size_t)i != sizeof(packet)) | ||
328 | bb_error_msg_and_die("ping wrote %d chars; %d expected", i, | ||
329 | (int)sizeof(packet)); | ||
330 | |||
331 | signal(SIGALRM, sendping); | ||
332 | if (pingcount == 0 || ntransmitted < pingcount) { /* schedule next in 1s */ | ||
333 | alarm(PINGINTERVAL); | ||
334 | } else { /* done, wait for the last ping to come back */ | ||
335 | /* todo, don't necessarily need to wait so long... */ | ||
336 | signal(SIGALRM, pingstats); | ||
337 | alarm(MAXWAIT); | ||
338 | } | ||
339 | } | 345 | } |
340 | #if ENABLE_PING6 | 346 | #if ENABLE_PING6 |
341 | static void sendping6(int junk ATTRIBUTE_UNUSED) | 347 | static void sendping6(int junk ATTRIBUTE_UNUSED) |
@@ -359,20 +365,7 @@ static void sendping6(int junk ATTRIBUTE_UNUSED) | |||
359 | i = sendto(pingsock, packet, sizeof(packet), 0, | 365 | i = sendto(pingsock, packet, sizeof(packet), 0, |
360 | &pingaddr.sa, sizeof(pingaddr.sin6)); | 366 | &pingaddr.sa, sizeof(pingaddr.sin6)); |
361 | 367 | ||
362 | if (i < 0) | 368 | sendping_tail(sendping6, i, sizeof(packet)); |
363 | bb_perror_msg_and_die("sendto"); | ||
364 | if ((size_t)i != sizeof(packet)) | ||
365 | bb_error_msg_and_die("ping wrote %d chars; %d expected", i, | ||
366 | (int)sizeof(packet)); | ||
367 | |||
368 | signal(SIGALRM, sendping6); | ||
369 | if (pingcount == 0 || ntransmitted < pingcount) { /* schedule next in 1s */ | ||
370 | alarm(PINGINTERVAL); | ||
371 | } else { /* done, wait for the last ping to come back */ | ||
372 | /* todo, don't necessarily need to wait so long... */ | ||
373 | signal(SIGALRM, pingstats); | ||
374 | alarm(MAXWAIT); | ||
375 | } | ||
376 | } | 369 | } |
377 | #endif | 370 | #endif |
378 | 371 | ||
@@ -424,7 +417,7 @@ static char *icmp6_type_name(int id) | |||
424 | } | 417 | } |
425 | #endif | 418 | #endif |
426 | 419 | ||
427 | static void unpack(char *buf, int sz, struct sockaddr_in *from) | 420 | static void unpack4(char *buf, int sz, struct sockaddr_in *from) |
428 | { | 421 | { |
429 | struct icmp *icmppkt; | 422 | struct icmp *icmppkt; |
430 | struct iphdr *iphdr; | 423 | struct iphdr *iphdr; |
@@ -560,7 +553,7 @@ static void unpack6(char *packet, int sz, struct sockaddr_in6 *from, int hoplimi | |||
560 | } | 553 | } |
561 | #endif | 554 | #endif |
562 | 555 | ||
563 | static void ping(len_and_sockaddr *lsa) | 556 | static void ping4(len_and_sockaddr *lsa) |
564 | { | 557 | { |
565 | char packet[datalen + MAXIPLEN + MAXICMPLEN]; | 558 | char packet[datalen + MAXIPLEN + MAXICMPLEN]; |
566 | int sockopt; | 559 | int sockopt; |
@@ -588,7 +581,7 @@ static void ping(len_and_sockaddr *lsa) | |||
588 | signal(SIGINT, pingstats); | 581 | signal(SIGINT, pingstats); |
589 | 582 | ||
590 | /* start the ping's going ... */ | 583 | /* start the ping's going ... */ |
591 | sendping(0); | 584 | sendping4(0); |
592 | 585 | ||
593 | /* listen for replies */ | 586 | /* listen for replies */ |
594 | while (1) { | 587 | while (1) { |
@@ -603,7 +596,7 @@ static void ping(len_and_sockaddr *lsa) | |||
603 | bb_perror_msg("recvfrom"); | 596 | bb_perror_msg("recvfrom"); |
604 | continue; | 597 | continue; |
605 | } | 598 | } |
606 | unpack(packet, c, &from); | 599 | unpack4(packet, c, &from); |
607 | if (pingcount > 0 && nreceived >= pingcount) | 600 | if (pingcount > 0 && nreceived >= pingcount) |
608 | break; | 601 | break; |
609 | } | 602 | } |
@@ -730,7 +723,7 @@ int ping_main(int argc, char **argv) | |||
730 | 723 | ||
731 | datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */ | 724 | datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */ |
732 | 725 | ||
733 | /* exactly one argument needed, -v and -q don't mix. So do 4, 6 */ | 726 | /* exactly one argument needed, -v and -q don't mix */ |
734 | opt_complementary = "=1:q--v:v--q"; | 727 | opt_complementary = "=1:q--v:v--q"; |
735 | getopt32(argc, argv, OPT_STRING, &opt_c, &opt_s, &opt_I); | 728 | getopt32(argc, argv, OPT_STRING, &opt_c, &opt_s, &opt_I); |
736 | if (option_mask32 & OPT_c) pingcount = xatoul(opt_c); // -c | 729 | if (option_mask32 & OPT_c) pingcount = xatoul(opt_c); // -c |
@@ -758,7 +751,7 @@ int ping_main(int argc, char **argv) | |||
758 | ping6(lsa); | 751 | ping6(lsa); |
759 | else | 752 | else |
760 | #endif | 753 | #endif |
761 | ping(lsa); | 754 | ping4(lsa); |
762 | pingstats(0); | 755 | pingstats(0); |
763 | return EXIT_SUCCESS; | 756 | return EXIT_SUCCESS; |
764 | } | 757 | } |