aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoachim Nilsson <joachim.nilsson@vmlinux.org>2010-11-28 23:01:18 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-11-28 23:01:18 +0100
commit714e2b7e6ab9cef6cb853c52b6c128d390964a25 (patch)
tree9286fc497e4e710c2670e815e3e96a0fb45f189c
parent713d241852ec726ad07920476fa18d0f9d455246 (diff)
downloadbusybox-w32-714e2b7e6ab9cef6cb853c52b6c128d390964a25.tar.gz
busybox-w32-714e2b7e6ab9cef6cb853c52b6c128d390964a25.tar.bz2
busybox-w32-714e2b7e6ab9cef6cb853c52b6c128d390964a25.zip
ping: add -t TTL option
function old new delta common_ping_main 1755 1796 +41 packed_usage 27954 27971 +17 bbconfig_config_bz2 4965 4966 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 59/0) Total: 59 bytes Signed-off-by: Joachim Nilsson <joachim.nilsson@vmlinux.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/applets.src.h2
-rw-r--r--include/usage.src.h55
-rw-r--r--networking/Config.src23
-rw-r--r--networking/Kbuild.src2
-rw-r--r--networking/ping.c111
5 files changed, 102 insertions, 91 deletions
diff --git a/include/applets.src.h b/include/applets.src.h
index 06b4fff35..131fca504 100644
--- a/include/applets.src.h
+++ b/include/applets.src.h
@@ -263,8 +263,6 @@ IF_OPENVT(APPLET(openvt, _BB_DIR_USR_BIN, _BB_SUID_DROP))
263IF_PASSWD(APPLET(passwd, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE)) 263IF_PASSWD(APPLET(passwd, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE))
264IF_PGREP(APPLET(pgrep, _BB_DIR_USR_BIN, _BB_SUID_DROP)) 264IF_PGREP(APPLET(pgrep, _BB_DIR_USR_BIN, _BB_SUID_DROP))
265IF_PIDOF(APPLET(pidof, _BB_DIR_BIN, _BB_SUID_DROP)) 265IF_PIDOF(APPLET(pidof, _BB_DIR_BIN, _BB_SUID_DROP))
266IF_PING(APPLET(ping, _BB_DIR_BIN, _BB_SUID_MAYBE))
267IF_PING6(APPLET(ping6, _BB_DIR_BIN, _BB_SUID_MAYBE))
268IF_PIPE_PROGRESS(APPLET(pipe_progress, _BB_DIR_BIN, _BB_SUID_DROP)) 266IF_PIPE_PROGRESS(APPLET(pipe_progress, _BB_DIR_BIN, _BB_SUID_DROP))
269IF_PIVOT_ROOT(APPLET(pivot_root, _BB_DIR_SBIN, _BB_SUID_DROP)) 267IF_PIVOT_ROOT(APPLET(pivot_root, _BB_DIR_SBIN, _BB_SUID_DROP))
270IF_PKILL(APPLET_ODDNAME(pkill, pgrep, _BB_DIR_USR_BIN, _BB_SUID_DROP, pkill)) 268IF_PKILL(APPLET_ODDNAME(pkill, pgrep, _BB_DIR_USR_BIN, _BB_SUID_DROP, pkill))
diff --git a/include/usage.src.h b/include/usage.src.h
index 30fef2440..7de2c6928 100644
--- a/include/usage.src.h
+++ b/include/usage.src.h
@@ -2859,61 +2859,6 @@ INSERT
2859 IF_FEATURE_PIDOF_OMIT( \ 2859 IF_FEATURE_PIDOF_OMIT( \
2860 "$ pidof /bin/sh -o %PPID\n20351 5950") 2860 "$ pidof /bin/sh -o %PPID\n20351 5950")
2861 2861
2862#if !ENABLE_FEATURE_FANCY_PING
2863#define ping_trivial_usage \
2864 "host"
2865#define ping_full_usage "\n\n" \
2866 "Send ICMP ECHO_REQUEST packets to network hosts"
2867#define ping6_trivial_usage \
2868 "host"
2869#define ping6_full_usage "\n\n" \
2870 "Send ICMP ECHO_REQUEST packets to network hosts"
2871#else
2872#define ping_trivial_usage \
2873 "[OPTIONS] HOST"
2874#define ping_full_usage "\n\n" \
2875 "Send ICMP ECHO_REQUEST packets to network hosts\n" \
2876 "\nOptions:" \
2877 "\n -4,-6 Force IP or IPv6 name resolution" \
2878 "\n -c CNT Send only CNT pings" \
2879 "\n -s SIZE Send SIZE data bytes in packets (default:56)" \
2880 "\n -I IFACE/IP Use interface or IP address as source" \
2881 "\n -W SEC Seconds to wait for the first response (default:10)" \
2882 "\n (after all -c CNT packets are sent)" \
2883 "\n -w SEC Seconds until ping exits (default:infinite)" \
2884 "\n (can exit earlier with -c CNT)" \
2885 "\n -q Quiet, only displays output at start" \
2886 "\n and when finished" \
2887
2888#define ping6_trivial_usage \
2889 "[OPTIONS] HOST"
2890#define ping6_full_usage "\n\n" \
2891 "Send ICMP ECHO_REQUEST packets to network hosts\n" \
2892 "\nOptions:" \
2893 "\n -c CNT Send only CNT pings" \
2894 "\n -s SIZE Send SIZE data bytes in packets (default:56)" \
2895 "\n -I IFACE/IP Use interface or IP address as source" \
2896 "\n -q Quiet, only displays output at start" \
2897 "\n and when finished" \
2898
2899#endif
2900#define ping_example_usage \
2901 "$ ping localhost\n" \
2902 "PING slag (127.0.0.1): 56 data bytes\n" \
2903 "64 bytes from 127.0.0.1: icmp_seq=0 ttl=255 time=20.1 ms\n" \
2904 "\n" \
2905 "--- debian ping statistics ---\n" \
2906 "1 packets transmitted, 1 packets received, 0% packet loss\n" \
2907 "round-trip min/avg/max = 20.1/20.1/20.1 ms\n"
2908#define ping6_example_usage \
2909 "$ ping6 ip6-localhost\n" \
2910 "PING ip6-localhost (::1): 56 data bytes\n" \
2911 "64 bytes from ::1: icmp6_seq=0 ttl=64 time=20.1 ms\n" \
2912 "\n" \
2913 "--- ip6-localhost ping statistics ---\n" \
2914 "1 packets transmitted, 1 packets received, 0% packet loss\n" \
2915 "round-trip min/avg/max = 20.1/20.1/20.1 ms\n"
2916
2917#define pipe_progress_trivial_usage NOUSAGE_STR 2862#define pipe_progress_trivial_usage NOUSAGE_STR
2918#define pipe_progress_full_usage "" 2863#define pipe_progress_full_usage ""
2919 2864
diff --git a/networking/Config.src b/networking/Config.src
index 6dd7df754..274fcae3a 100644
--- a/networking/Config.src
+++ b/networking/Config.src
@@ -684,29 +684,6 @@ config FEATURE_NTPD_SERVER
684 Make ntpd usable as a NTP server. If you disable this option 684 Make ntpd usable as a NTP server. If you disable this option
685 ntpd will be usable only as a NTP client. 685 ntpd will be usable only as a NTP client.
686 686
687config PING
688 bool "ping"
689 default y
690 depends on PLATFORM_LINUX
691 help
692 ping uses the ICMP protocol's mandatory ECHO_REQUEST datagram to
693 elicit an ICMP ECHO_RESPONSE from a host or gateway.
694
695config PING6
696 bool "ping6"
697 default y
698 depends on FEATURE_IPV6 && PING
699 help
700 This will give you a ping that can talk IPv6.
701
702config FEATURE_FANCY_PING
703 bool "Enable fancy ping output"
704 default y
705 depends on PING
706 help
707 Make the output from the ping applet include statistics, and at the
708 same time provide full support for ICMP packets.
709
710config PSCAN 687config PSCAN
711 bool "pscan" 688 bool "pscan"
712 default y 689 default y
diff --git a/networking/Kbuild.src b/networking/Kbuild.src
index f41a2df70..944f27be1 100644
--- a/networking/Kbuild.src
+++ b/networking/Kbuild.src
@@ -30,8 +30,6 @@ lib-$(CONFIG_NC) += nc.o
30lib-$(CONFIG_NETSTAT) += netstat.o 30lib-$(CONFIG_NETSTAT) += netstat.o
31lib-$(CONFIG_NSLOOKUP) += nslookup.o 31lib-$(CONFIG_NSLOOKUP) += nslookup.o
32lib-$(CONFIG_NTPD) += ntpd.o 32lib-$(CONFIG_NTPD) += ntpd.o
33lib-$(CONFIG_PING) += ping.o
34lib-$(CONFIG_PING6) += ping.o
35lib-$(CONFIG_PSCAN) += pscan.o 33lib-$(CONFIG_PSCAN) += pscan.o
36lib-$(CONFIG_ROUTE) += route.o 34lib-$(CONFIG_ROUTE) += route.o
37lib-$(CONFIG_SLATTACH) += slattach.o 35lib-$(CONFIG_SLATTACH) += slattach.o
diff --git a/networking/ping.c b/networking/ping.c
index 3aba4906e..8571d179b 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -29,6 +29,92 @@
29#include <netinet/ip_icmp.h> 29#include <netinet/ip_icmp.h>
30#include "libbb.h" 30#include "libbb.h"
31 31
32//config:config PING
33//config: bool "ping"
34//config: default y
35//config: depends on PLATFORM_LINUX
36//config: help
37//config: ping uses the ICMP protocol's mandatory ECHO_REQUEST datagram to
38//config: elicit an ICMP ECHO_RESPONSE from a host or gateway.
39//config:
40//config:config PING6
41//config: bool "ping6"
42//config: default y
43//config: depends on FEATURE_IPV6 && PING
44//config: help
45//config: This will give you a ping that can talk IPv6.
46//config:
47//config:config FEATURE_FANCY_PING
48//config: bool "Enable fancy ping output"
49//config: default y
50//config: depends on PING
51//config: help
52//config: Make the output from the ping applet include statistics, and at the
53//config: same time provide full support for ICMP packets.
54
55//applet:IF_PING(APPLET(ping, _BB_DIR_BIN, _BB_SUID_MAYBE))
56//applet:IF_PING6(APPLET(ping6, _BB_DIR_BIN, _BB_SUID_MAYBE))
57
58//kbuild:lib-$(CONFIG_PING) += ping.o
59//kbuild:lib-$(CONFIG_PING6) += ping.o
60
61//usage:#if !ENABLE_FEATURE_FANCY_PING
62//usage:# define ping_trivial_usage
63//usage: "HOST"
64//usage:# define ping_full_usage "\n\n"
65//usage: "Send ICMP ECHO_REQUEST packets to network hosts"
66//usage:# define ping6_trivial_usage
67//usage: "HOST"
68//usage:# define ping6_full_usage "\n\n"
69//usage: "Send ICMP ECHO_REQUEST packets to network hosts"
70//usage:#else
71//usage:# define ping_trivial_usage
72//usage: "[OPTIONS] HOST"
73//usage:# define ping_full_usage "\n\n"
74//usage: "Send ICMP ECHO_REQUEST packets to network hosts\n"
75//usage: "\nOptions:"
76//usage: "\n -4,-6 Force IP or IPv6 name resolution"
77//usage: "\n -c CNT Send only CNT pings"
78//usage: "\n -s SIZE Send SIZE data bytes in packets (default:56)"
79//usage: "\n -t TTL Set TTL"
80//usage: "\n -I IFACE/IP Use interface or IP address as source"
81//usage: "\n -W SEC Seconds to wait for the first response (default:10)"
82//usage: "\n (after all -c CNT packets are sent)"
83//usage: "\n -w SEC Seconds until ping exits (default:infinite)"
84//usage: "\n (can exit earlier with -c CNT)"
85//usage: "\n -q Quiet, only displays output at start"
86//usage: "\n and when finished"
87//usage:
88//usage:# define ping6_trivial_usage
89//usage: "[OPTIONS] HOST"
90//usage:# define ping6_full_usage "\n\n"
91//usage: "Send ICMP ECHO_REQUEST packets to network hosts\n"
92//usage: "\nOptions:"
93//usage: "\n -c CNT Send only CNT pings"
94//usage: "\n -s SIZE Send SIZE data bytes in packets (default:56)"
95//usage: "\n -I IFACE/IP Use interface or IP address as source"
96//usage: "\n -q Quiet, only displays output at start"
97//usage: "\n and when finished"
98//usage:
99//usage:#endif
100//usage:
101//usage:#define ping_example_usage
102//usage: "$ ping localhost\n"
103//usage: "PING slag (127.0.0.1): 56 data bytes\n"
104//usage: "64 bytes from 127.0.0.1: icmp_seq=0 ttl=255 time=20.1 ms\n"
105//usage: "\n"
106//usage: "--- debian ping statistics ---\n"
107//usage: "1 packets transmitted, 1 packets received, 0% packet loss\n"
108//usage: "round-trip min/avg/max = 20.1/20.1/20.1 ms\n"
109//usage:#define ping6_example_usage
110//usage: "$ ping6 ip6-localhost\n"
111//usage: "PING ip6-localhost (::1): 56 data bytes\n"
112//usage: "64 bytes from ::1: icmp6_seq=0 ttl=64 time=20.1 ms\n"
113//usage: "\n"
114//usage: "--- ip6-localhost ping statistics ---\n"
115//usage: "1 packets transmitted, 1 packets received, 0% packet loss\n"
116//usage: "round-trip min/avg/max = 20.1/20.1/20.1 ms\n"
117
32#if ENABLE_PING6 118#if ENABLE_PING6
33# include <netinet/icmp6.h> 119# include <netinet/icmp6.h>
34/* I see RENUMBERED constants in bits/in.h - !!? 120/* I see RENUMBERED constants in bits/in.h - !!?
@@ -223,17 +309,18 @@ static int common_ping_main(sa_family_t af, char **argv)
223 309
224/* Full(er) version */ 310/* Full(er) version */
225 311
226#define OPT_STRING ("qvc:s:w:W:I:4" IF_PING6("6")) 312#define OPT_STRING ("qvc:s:t:w:W:I:4" IF_PING6("6"))
227enum { 313enum {
228 OPT_QUIET = 1 << 0, 314 OPT_QUIET = 1 << 0,
229 OPT_VERBOSE = 1 << 1, 315 OPT_VERBOSE = 1 << 1,
230 OPT_c = 1 << 2, 316 OPT_c = 1 << 2,
231 OPT_s = 1 << 3, 317 OPT_s = 1 << 3,
232 OPT_w = 1 << 4, 318 OPT_t = 1 << 4,
233 OPT_W = 1 << 5, 319 OPT_w = 1 << 5,
234 OPT_I = 1 << 6, 320 OPT_W = 1 << 6,
235 OPT_IPV4 = 1 << 7, 321 OPT_I = 1 << 7,
236 OPT_IPV6 = (1 << 8) * ENABLE_PING6, 322 OPT_IPV4 = 1 << 8,
323 OPT_IPV6 = (1 << 9) * ENABLE_PING6,
237}; 324};
238 325
239 326
@@ -244,6 +331,7 @@ struct globals {
244 len_and_sockaddr *source_lsa; 331 len_and_sockaddr *source_lsa;
245 unsigned datalen; 332 unsigned datalen;
246 unsigned pingcount; /* must be int-sized */ 333 unsigned pingcount; /* must be int-sized */
334 unsigned opt_ttl;
247 unsigned long ntransmitted, nreceived, nrepeats; 335 unsigned long ntransmitted, nreceived, nrepeats;
248 uint16_t myid; 336 uint16_t myid;
249 unsigned tmin, tmax; /* in us */ 337 unsigned tmin, tmax; /* in us */
@@ -275,6 +363,7 @@ struct globals {
275#define nreceived (G.nreceived ) 363#define nreceived (G.nreceived )
276#define nrepeats (G.nrepeats ) 364#define nrepeats (G.nrepeats )
277#define pingcount (G.pingcount ) 365#define pingcount (G.pingcount )
366#define opt_ttl (G.opt_ttl )
278#define myid (G.myid ) 367#define myid (G.myid )
279#define tmin (G.tmin ) 368#define tmin (G.tmin )
280#define tmax (G.tmax ) 369#define tmax (G.tmax )
@@ -586,6 +675,10 @@ static void ping4(len_and_sockaddr *lsa)
586 sockopt = (datalen * 2) + 7 * 1024; /* giving it a bit of extra room */ 675 sockopt = (datalen * 2) + 7 * 1024; /* giving it a bit of extra room */
587 setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, &sockopt, sizeof(sockopt)); 676 setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, &sockopt, sizeof(sockopt));
588 677
678 if (opt_ttl != 0)
679 //setsockopt(pingsock, IPPROTO_IP, IP_MULTICAST_TTL, &opt_ttl, sizeof(opt_ttl));
680 setsockopt(pingsock, IPPROTO_IP, IP_TTL, &opt_ttl, sizeof(opt_ttl));
681
589 signal(SIGINT, print_stats_and_exit); 682 signal(SIGINT, print_stats_and_exit);
590 683
591 /* start the ping's going ... */ 684 /* start the ping's going ... */
@@ -735,9 +828,9 @@ static int common_ping_main(int opt, char **argv)
735 828
736 INIT_G(); 829 INIT_G();
737 830
738 /* exactly one argument needed; -v and -q don't mix; -c NUM, -w NUM, -W NUM */ 831 /* exactly one argument needed; -v and -q don't mix; -c NUM, -t NUM, -w NUM, -W NUM */
739 opt_complementary = "=1:q--v:v--q:c+:w+:W+"; 832 opt_complementary = "=1:q--v:v--q:c+:t+:w+:W+";
740 opt |= getopt32(argv, OPT_STRING, &pingcount, &str_s, &deadline, &timeout, &str_I); 833 opt |= getopt32(argv, OPT_STRING, &pingcount, &str_s, &opt_ttl, &deadline, &timeout, &str_I);
741 if (opt & OPT_s) 834 if (opt & OPT_s)
742 datalen = xatou16(str_s); // -s 835 datalen = xatou16(str_s); // -s
743 if (opt & OPT_I) { // -I 836 if (opt & OPT_I) { // -I