30 |
#include "libbb.h" |
#include "libbb.h" |
31 |
|
|
32 |
#if ENABLE_PING6 |
#if ENABLE_PING6 |
33 |
#include <netinet/icmp6.h> |
# include <netinet/icmp6.h> |
34 |
/* I see RENUMBERED constants in bits/in.h - !!? |
/* I see RENUMBERED constants in bits/in.h - !!? |
35 |
* What a fuck is going on with libc? Is it a glibc joke? */ |
* What a fuck is going on with libc? Is it a glibc joke? */ |
36 |
#ifdef IPV6_2292HOPLIMIT |
# ifdef IPV6_2292HOPLIMIT |
37 |
#undef IPV6_HOPLIMIT |
# undef IPV6_HOPLIMIT |
38 |
#define IPV6_HOPLIMIT IPV6_2292HOPLIMIT |
# define IPV6_HOPLIMIT IPV6_2292HOPLIMIT |
39 |
#endif |
# endif |
40 |
#endif |
#endif |
41 |
|
|
42 |
enum { |
enum { |
162 |
bb_perror_msg("recvfrom"); |
bb_perror_msg("recvfrom"); |
163 |
continue; |
continue; |
164 |
} |
} |
165 |
if (c >= 8) { /* icmp6_hdr */ |
if (c >= ICMP_MINLEN) { /* icmp6_hdr */ |
166 |
pkt = (struct icmp6_hdr *) packet; |
pkt = (struct icmp6_hdr *) packet; |
167 |
if (pkt->icmp6_type == ICMP6_ECHO_REPLY) |
if (pkt->icmp6_type == ICMP6_ECHO_REPLY) |
168 |
break; |
break; |
173 |
} |
} |
174 |
#endif |
#endif |
175 |
|
|
176 |
int ping_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
#if !ENABLE_PING6 |
177 |
int ping_main(int argc UNUSED_PARAM, char **argv) |
# define common_ping_main(af, argv) common_ping_main(argv) |
178 |
|
#endif |
179 |
|
static int common_ping_main(sa_family_t af, char **argv) |
180 |
{ |
{ |
181 |
len_and_sockaddr *lsa; |
len_and_sockaddr *lsa; |
|
#if ENABLE_PING6 |
|
|
sa_family_t af = AF_UNSPEC; |
|
182 |
|
|
183 |
|
#if ENABLE_PING6 |
184 |
while ((++argv)[0] && argv[0][0] == '-') { |
while ((++argv)[0] && argv[0][0] == '-') { |
185 |
if (argv[0][1] == '4') { |
if (argv[0][1] == '4') { |
186 |
af = AF_INET; |
af = AF_INET; |
225 |
|
|
226 |
/* full(er) version */ |
/* full(er) version */ |
227 |
|
|
228 |
#define OPT_STRING ("qvc:s:w:W:I:4" USE_PING6("6")) |
#define OPT_STRING ("qvc:s:w:W:I:4" IF_PING6("6")) |
229 |
enum { |
enum { |
230 |
OPT_QUIET = 1 << 0, |
OPT_QUIET = 1 << 0, |
231 |
OPT_VERBOSE = 1 << 1, |
OPT_VERBOSE = 1 << 1, |
492 |
if (tp) |
if (tp) |
493 |
printf(" time=%u.%03u ms", triptime / 1000, triptime % 1000); |
printf(" time=%u.%03u ms", triptime / 1000, triptime % 1000); |
494 |
puts(dupmsg); |
puts(dupmsg); |
495 |
fflush(stdout); |
fflush_all(); |
496 |
} |
} |
497 |
static void unpack4(char *buf, int sz, struct sockaddr_in *from) |
static void unpack4(char *buf, int sz, struct sockaddr_in *from) |
498 |
{ |
{ |
690 |
/* don't check len - we trust the kernel: */ |
/* don't check len - we trust the kernel: */ |
691 |
/* && mp->cmsg_len >= CMSG_LEN(sizeof(int)) */ |
/* && mp->cmsg_len >= CMSG_LEN(sizeof(int)) */ |
692 |
) { |
) { |
693 |
hoplimit = *(int*)CMSG_DATA(mp); |
/*hoplimit = *(int*)CMSG_DATA(mp); - unaligned access */ |
694 |
|
move_from_unaligned_int(hoplimit, CMSG_DATA(mp)); |
695 |
} |
} |
696 |
} |
} |
697 |
unpack6(packet, c, /*&from,*/ hoplimit); |
unpack6(packet, c, /*&from,*/ hoplimit); |
718 |
ping4(lsa); |
ping4(lsa); |
719 |
} |
} |
720 |
|
|
721 |
int ping_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
static int common_ping_main(int opt, char **argv) |
|
int ping_main(int argc UNUSED_PARAM, char **argv) |
|
722 |
{ |
{ |
723 |
len_and_sockaddr *lsa; |
len_and_sockaddr *lsa; |
724 |
char *str_s; |
char *str_s; |
|
int opt; |
|
725 |
|
|
726 |
INIT_G(); |
INIT_G(); |
727 |
|
|
728 |
/* exactly one argument needed; -v and -q don't mix; -c NUM, -w NUM, -W NUM */ |
/* exactly one argument needed; -v and -q don't mix; -c NUM, -w NUM, -W NUM */ |
729 |
opt_complementary = "=1:q--v:v--q:c+:w+:W+"; |
opt_complementary = "=1:q--v:v--q:c+:w+:W+"; |
730 |
opt = getopt32(argv, OPT_STRING, &pingcount, &str_s, &deadline, &timeout, &str_I); |
opt |= getopt32(argv, OPT_STRING, &pingcount, &str_s, &deadline, &timeout, &str_I); |
731 |
if (opt & OPT_s) |
if (opt & OPT_s) |
732 |
datalen = xatou16(str_s); // -s |
datalen = xatou16(str_s); // -s |
733 |
if (opt & OPT_I) { // -I |
if (opt & OPT_I) { // -I |
765 |
#endif /* FEATURE_FANCY_PING */ |
#endif /* FEATURE_FANCY_PING */ |
766 |
|
|
767 |
|
|
768 |
|
int ping_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
769 |
|
int ping_main(int argc UNUSED_PARAM, char **argv) |
770 |
|
{ |
771 |
|
#if !ENABLE_FEATURE_FANCY_PING |
772 |
|
return common_ping_main(AF_UNSPEC, argv); |
773 |
|
#else |
774 |
|
return common_ping_main(0, argv); |
775 |
|
#endif |
776 |
|
} |
777 |
|
|
778 |
#if ENABLE_PING6 |
#if ENABLE_PING6 |
779 |
int ping6_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
int ping6_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
780 |
int ping6_main(int argc UNUSED_PARAM, char **argv) |
int ping6_main(int argc UNUSED_PARAM, char **argv) |
781 |
{ |
{ |
782 |
argv[0] = (char*)"-6"; |
# if !ENABLE_FEATURE_FANCY_PING |
783 |
return ping_main(0 /* argc+1 - but it's unused anyway */, |
return common_ping_main(AF_INET6, argv); |
784 |
argv - 1); |
# else |
785 |
|
return common_ping_main(OPT_IPV6, argv); |
786 |
|
# endif |
787 |
} |
} |
788 |
#endif |
#endif |
789 |
|
|