2007/10/19, Bob Keyes <[EMAIL PROTECTED]>:
> I am new here, not sure of the
> regular way I am supposed to make contributions, but whoever is in charge
> of accepting patches please take a look at
> https://dev.openwrt.org/ticket/2522 which will explain the rational for
> the feature and includes the patch for it.

    I took the liberty to make the patch against current svn.

       Loïc Grenié
Index: networking/ping.c
===================================================================
--- networking/ping.c	(révision 20295)
+++ networking/ping.c	(copie de travail)
@@ -224,7 +224,7 @@
 
 /* full(er) version */
 
-#define OPT_STRING ("qvc:s:I:4" USE_PING6("6"))
+#define OPT_STRING ("qvc:s:I:4" USE_PING6("6") "n:")
 enum {
 	OPT_QUIET = 1 << 0,
 	OPT_VERBOSE = 1 << 1,
@@ -233,6 +233,7 @@
 	OPT_I = 1 << 4,
 	OPT_IPV4 = 1 << 5,
 	OPT_IPV6 = (1 << 6) * ENABLE_PING6,
+	OPT_OUTDEV = 1 << 7,
 };
 
 
@@ -524,7 +525,7 @@
 }
 #endif
 
-static void ping4(len_and_sockaddr *lsa)
+static void ping4(len_and_sockaddr *lsa, char *device)
 {
 	char packet[datalen + MAXIPLEN + MAXICMPLEN];
 	int sockopt;
@@ -537,6 +538,8 @@
 			bb_error_msg_and_die("can't set multicast source interface");
 		xbind(pingsock, &source_lsa->sa, source_lsa->len);
 	}
+	if (device)
+		setsockopt(pingsock, SOL_SOCKET, SO_BINDTODEVICE, device, IFNAMSIZ+1);
 
 	/* enable broadcast pings */
 	setsockopt_broadcast(pingsock);
@@ -570,7 +573,7 @@
 }
 #if ENABLE_PING6
 extern int BUG_bad_offsetof_icmp6_cksum(void);
-static void ping6(len_and_sockaddr *lsa)
+static void ping6(len_and_sockaddr *lsa, char *device)
 {
 	char packet[datalen + MAXIPLEN + MAXICMPLEN];
 	int sockopt;
@@ -584,6 +587,8 @@
 	/* untested whether "-I addr" really works for IPv6: */
 	if (source_lsa)
 		xbind(pingsock, &source_lsa->sa, source_lsa->len);
+	if (device)
+		setsockopt(pingsock, SOL_SOCKET, SO_BINDTODEVICE, device, IFNAMSIZ+1);
 
 #ifdef ICMP6_FILTER
 	{
@@ -659,7 +664,7 @@
 }
 #endif
 
-static void ping(len_and_sockaddr *lsa)
+static void ping(len_and_sockaddr *lsa, char *device)
 {
 	printf("PING %s (%s)", hostname, dotted);
 	if (source_lsa) {
@@ -670,17 +675,17 @@
 
 #if ENABLE_PING6
 	if (lsa->sa.sa_family == AF_INET6)
-		ping6(lsa);
+		ping6(lsa, device);
 	else
 #endif
-		ping4(lsa);
+		ping4(lsa, device);
 }
 
 int ping_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int ping_main(int argc, char **argv)
 {
 	len_and_sockaddr *lsa;
-	char *opt_c, *opt_s, *opt_I;
+	char *opt_c, *opt_s, *opt_I, *device = NULL;
 	USE_PING6(sa_family_t af = AF_UNSPEC;)
 
 	INIT_G();
@@ -689,7 +694,7 @@
 
 	/* exactly one argument needed, -v and -q don't mix */
 	opt_complementary = "=1:q--v:v--q";
-	getopt32(argv, OPT_STRING, &opt_c, &opt_s, &opt_I);
+	getopt32(argv, OPT_STRING, &opt_c, &opt_s, &opt_I, &device);
 	if (option_mask32 & OPT_c) pingcount = xatoul(opt_c); // -c
 	if (option_mask32 & OPT_s) datalen = xatou16(opt_s); // -s
 	if (option_mask32 & OPT_I) { // -I
@@ -716,7 +721,7 @@
 		source_lsa = NULL;
 
 	dotted = xmalloc_sockaddr2dotted_noport(&lsa->sa);
-	ping(lsa);
+	ping(lsa, device);
 	pingstats(0);
 	return EXIT_SUCCESS;
 }
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to