--- busybox-1.21.0/networking/ping.c	2013-01-14 01:22:36.000000000 +0100
+++ src/networking/ping.c	2013-09-27 14:01:14.317324484 +0200
@@ -92,6 +92,7 @@
 //usage:     "\n	-4,-6		Force IP or IPv6 name resolution"
 //usage:     "\n	-c CNT		Send only CNT pings"
 //usage:     "\n	-s SIZE		Send SIZE data bytes in packets (default:56)"
+//usage:     "\n	-Q tos		set TOS on outgoing packets"
 //usage:     "\n	-t TTL		Set TTL"
 //usage:     "\n	-I IFACE/IP	Use interface or IP address as source"
 //usage:     "\n	-W SEC		Seconds to wait for the first response (default:10)"
@@ -299,7 +300,7 @@
 
 /* Full(er) version */
 
-#define OPT_STRING ("qvc:s:t:w:W:I:4" IF_PING6("6"))
+#define OPT_STRING ("qvc:s:t:w:W:I:Q:4" IF_PING6("6"))
 enum {
 	OPT_QUIET = 1 << 0,
 	OPT_VERBOSE = 1 << 1,
@@ -309,8 +310,9 @@
 	OPT_w = 1 << 5,
 	OPT_W = 1 << 6,
 	OPT_I = 1 << 7,
-	OPT_IPV4 = 1 << 8,
-	OPT_IPV6 = (1 << 9) * ENABLE_PING6,
+	OPT_Q = 1 << 8,
+	OPT_IPV4 = 1 << 9,
+	OPT_IPV6 = (1 << 10) * ENABLE_PING6,
 };
 
 
@@ -644,11 +646,15 @@
 }
 #endif
 
-static void ping4(len_and_sockaddr *lsa)
+static void ping4(len_and_sockaddr *lsa, int tos)
 {
 	int sockopt;
 
 	pingsock = create_icmp_socket();
+	if (tos && setsockopt(pingsock, IPPROTO_IP, IP_TOS,
+			      (char *)&tos, sizeof (int)) < 0)
+		bb_error_msg_and_die("error setting TOS");
+
 	pingaddr.sin = lsa->u.sin;
 	if (source_lsa) {
 		if (setsockopt(pingsock, IPPROTO_IP, IP_MULTICAST_IF,
@@ -790,7 +796,7 @@
 }
 #endif
 
-static void ping(len_and_sockaddr *lsa)
+static void ping(len_and_sockaddr *lsa, int tos)
 {
 	printf("PING %s (%s)", hostname, dotted);
 	if (source_lsa) {
@@ -811,22 +817,42 @@
 #endif
 	{
 		G.snd_packet = xzalloc(datalen + ICMP_MINLEN + 4);
-		ping4(lsa);
+		ping4(lsa, tos);
 	}
 }
 
+#define TOS_MAX        255
+
+static int parsetos(const char *str)
+{
+	int tos;
+	char *ep;
+
+	tos = (int)strtoul(str, &ep, 0);
+	if (*ep)
+		bb_error_msg_and_die("bad value for TOS");
+
+	if (tos > TOS_MAX)
+		bb_error_msg_and_die("TOS too high");
+
+        return tos;
+}
+
 static int common_ping_main(int opt, char **argv)
 {
 	len_and_sockaddr *lsa;
-	char *str_s;
+	char *str_s, *str_Q;
+	int tos = 0;
 
 	INIT_G();
 
 	/* exactly one argument needed; -v and -q don't mix; -c NUM, -t NUM, -w NUM, -W NUM */
 	opt_complementary = "=1:q--v:v--q:c+:t+:w+:W+";
-	opt |= getopt32(argv, OPT_STRING, &pingcount, &str_s, &opt_ttl, &deadline, &timeout, &str_I);
+	opt |= getopt32(argv, OPT_STRING, &pingcount, &str_s, &opt_ttl, &deadline, &timeout, &str_I, &str_Q);
 	if (opt & OPT_s)
 		datalen = xatou16(str_s); // -s
+	if (opt & OPT_Q)
+		tos = parsetos(str_Q);
 	if (opt & OPT_I) { // -I
 		if_index = if_nametoindex(str_I);
 		if (!if_index) {
@@ -855,7 +881,7 @@
 		source_lsa = NULL;
 
 	dotted = xmalloc_sockaddr2dotted_noport(&lsa->u.sa);
-	ping(lsa);
+	ping(lsa, tos);
 	print_stats_and_exit(EXIT_SUCCESS);
 	/*return EXIT_SUCCESS;*/
 }
