aboutsummaryrefslogtreecommitdiff
path: root/networking/ping.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-10-19 21:39:25 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-10-19 21:39:25 +0000
commit1a7afb48daf054d8cc9d57e8a569a6ac90acdd7d (patch)
treefedb7857cb41b2d1bf6c5c0c1d0ae0a7da736749 /networking/ping.c
parentfcc569637b85626078c9c353d5552e7847b4ca0a (diff)
downloadbusybox-w32-1a7afb48daf054d8cc9d57e8a569a6ac90acdd7d.tar.gz
busybox-w32-1a7afb48daf054d8cc9d57e8a569a6ac90acdd7d.tar.bz2
busybox-w32-1a7afb48daf054d8cc9d57e8a569a6ac90acdd7d.zip
paing: make -I ethN work too (-I addr already worked)
Diffstat (limited to 'networking/ping.c')
-rw-r--r--networking/ping.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/networking/ping.c b/networking/ping.c
index 8b70d9a33..bd98a21e6 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -238,9 +238,10 @@ enum {
238 238
239struct globals { 239struct globals {
240 int pingsock; 240 int pingsock;
241 int if_index;
242 char *opt_I;
241 len_and_sockaddr *source_lsa; 243 len_and_sockaddr *source_lsa;
242 unsigned datalen; 244 unsigned datalen;
243 int if_index;
244 unsigned long ntransmitted, nreceived, nrepeats, pingcount; 245 unsigned long ntransmitted, nreceived, nrepeats, pingcount;
245 uint16_t myid; 246 uint16_t myid;
246 unsigned tmin, tmax; /* in us */ 247 unsigned tmin, tmax; /* in us */
@@ -258,9 +259,10 @@ struct globals {
258}; 259};
259#define G (*(struct globals*)&bb_common_bufsiz1) 260#define G (*(struct globals*)&bb_common_bufsiz1)
260#define pingsock (G.pingsock ) 261#define pingsock (G.pingsock )
262#define if_index (G.if_index )
261#define source_lsa (G.source_lsa ) 263#define source_lsa (G.source_lsa )
264#define opt_I (G.opt_I )
262#define datalen (G.datalen ) 265#define datalen (G.datalen )
263#define if_index (G.if_index )
264#define ntransmitted (G.ntransmitted) 266#define ntransmitted (G.ntransmitted)
265#define nreceived (G.nreceived ) 267#define nreceived (G.nreceived )
266#define nrepeats (G.nrepeats ) 268#define nrepeats (G.nrepeats )
@@ -537,6 +539,8 @@ static void ping4(len_and_sockaddr *lsa)
537 bb_error_msg_and_die("can't set multicast source interface"); 539 bb_error_msg_and_die("can't set multicast source interface");
538 xbind(pingsock, &source_lsa->sa, source_lsa->len); 540 xbind(pingsock, &source_lsa->sa, source_lsa->len);
539 } 541 }
542 if (opt_I)
543 setsockopt(pingsock, SOL_SOCKET, SO_BINDTODEVICE, device, strlen(opt_I) + 1);
540 544
541 /* enable broadcast pings */ 545 /* enable broadcast pings */
542 setsockopt_broadcast(pingsock); 546 setsockopt_broadcast(pingsock);
@@ -584,6 +588,8 @@ static void ping6(len_and_sockaddr *lsa)
584 /* untested whether "-I addr" really works for IPv6: */ 588 /* untested whether "-I addr" really works for IPv6: */
585 if (source_lsa) 589 if (source_lsa)
586 xbind(pingsock, &source_lsa->sa, source_lsa->len); 590 xbind(pingsock, &source_lsa->sa, source_lsa->len);
591 if (opt_I)
592 setsockopt(pingsock, SOL_SOCKET, SO_BINDTODEVICE, device, strlen(opt_I) + 1);
587 593
588#ifdef ICMP6_FILTER 594#ifdef ICMP6_FILTER
589 { 595 {
@@ -680,23 +686,26 @@ int ping_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
680int ping_main(int argc, char **argv) 686int ping_main(int argc, char **argv)
681{ 687{
682 len_and_sockaddr *lsa; 688 len_and_sockaddr *lsa;
683 char *opt_c, *opt_s, *opt_I; 689 char *opt_c, *opt_s;
684 USE_PING6(sa_family_t af = AF_UNSPEC;) 690 USE_PING6(sa_family_t af = AF_UNSPEC;)
685 691
686 INIT_G(); 692 INIT_G();
687 693
688 datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */ 694 datalen = DEFDATALEN;
689 695
690 /* exactly one argument needed, -v and -q don't mix */ 696 /* exactly one argument needed, -v and -q don't mix */
691 opt_complementary = "=1:q--v:v--q"; 697 opt_complementary = "=1:q--v:v--q";
692 getopt32(argv, OPT_STRING, &opt_c, &opt_s, &opt_I); 698 getopt32(argv, OPT_STRING, &opt_c, &opt_s, &opt_I);
693 if (option_mask32 & OPT_c) pingcount = xatoul(opt_c); // -c 699 if (option_mask32 & OPT_c)
694 if (option_mask32 & OPT_s) datalen = xatou16(opt_s); // -s 700 pingcount = xatoul(opt_c); // -c
701 if (option_mask32 & OPT_s)
702 datalen = xatou16(opt_s); // -s
695 if (option_mask32 & OPT_I) { // -I 703 if (option_mask32 & OPT_I) { // -I
696 if_index = if_nametoindex(opt_I); 704 if_index = if_nametoindex(opt_I);
697 if (!if_index) { 705 if (!if_index) {
698 /* TODO: I'm not sure it takes IPv6 unless in [XX:XX..] format */ 706 /* TODO: I'm not sure it takes IPv6 unless in [XX:XX..] format */
699 source_lsa = xdotted2sockaddr(opt_I, 0); 707 source_lsa = xdotted2sockaddr(opt_I, 0);
708 opt_I = NULL; /* don't try to bind to device later */
700 } 709 }
701 } 710 }
702 myid = (uint16_t) getpid(); 711 myid = (uint16_t) getpid();