aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-09-02 16:16:23 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-09-02 16:16:23 +0000
commitdb7f2e5881b9ae40896d7660cd2f2446f514c72d (patch)
tree302ceaf4aabb508dc8a772989fa1151f0406663b
parentcb6874cc66df69fe49c65338a67fec1206d02c4b (diff)
downloadbusybox-w32-db7f2e5881b9ae40896d7660cd2f2446f514c72d.tar.gz
busybox-w32-db7f2e5881b9ae40896d7660cd2f2446f514c72d.tar.bz2
busybox-w32-db7f2e5881b9ae40896d7660cd2f2446f514c72d.zip
ping6: resolve interface name to number early.
gcc is more efficient at truncating int to int16 via cast, use that instead of &.
-rw-r--r--networking/ping.c2
-rw-r--r--networking/ping6.c15
2 files changed, 9 insertions, 8 deletions
diff --git a/networking/ping.c b/networking/ping.c
index 8ccb7e0bf..967a3e378 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -416,7 +416,7 @@ int ping_main(int argc, char **argv)
416 if (argc < 1) 416 if (argc < 1)
417 bb_show_usage(); 417 bb_show_usage();
418 418
419 myid = getpid() & 0xFFFF; 419 myid = (int16_t) getpid();
420 ping(*argv); 420 ping(*argv);
421 return EXIT_SUCCESS; 421 return EXIT_SUCCESS;
422} 422}
diff --git a/networking/ping6.c b/networking/ping6.c
index fdcd4ec46..38d605c6d 100644
--- a/networking/ping6.c
+++ b/networking/ping6.c
@@ -146,7 +146,7 @@ int ping6_main(int argc, char **argv)
146static struct sockaddr_in6 pingaddr; 146static struct sockaddr_in6 pingaddr;
147static int pingsock = -1; 147static int pingsock = -1;
148static int datalen; /* intentionally uninitialized to work around gcc bug */ 148static int datalen; /* intentionally uninitialized to work around gcc bug */
149static char* ifname; 149static int if_index;
150 150
151static long ntransmitted, nreceived, nrepeats, pingcount; 151static long ntransmitted, nreceived, nrepeats, pingcount;
152static int myid, options; 152static int myid, options;
@@ -367,10 +367,8 @@ static void ping(const char *host)
367 setsockopt(pingsock, SOL_IPV6, IPV6_HOPLIMIT, (char *) &sockopt, 367 setsockopt(pingsock, SOL_IPV6, IPV6_HOPLIMIT, (char *) &sockopt,
368 sizeof(sockopt)); 368 sizeof(sockopt));
369 369
370 if (ifname) { 370 if (if_index)
371 if ((pingaddr.sin6_scope_id = if_nametoindex(ifname)) == 0) 371 pingaddr.sin6_scope_id = if_index;
372 bb_error_msg_and_die("%s: invalid interface name", ifname);
373 }
374 372
375 printf("PING %s (%s): %d data bytes\n", 373 printf("PING %s (%s): %d data bytes\n",
376 hostent->h_name, 374 hostent->h_name,
@@ -455,7 +453,10 @@ int ping6_main(int argc, char **argv)
455 if (--argc <= 0) 453 if (--argc <= 0)
456 bb_show_usage(); 454 bb_show_usage();
457 argv++; 455 argv++;
458 ifname = *argv; 456 if_index = if_nametoindex(*argv);
457 if (!if_index)
458 bb_error_msg_and_die(
459 "%s: invalid interface name", *argv);
459 break; 460 break;
460 default: 461 default:
461 bb_show_usage(); 462 bb_show_usage();
@@ -466,7 +467,7 @@ int ping6_main(int argc, char **argv)
466 if (argc < 1) 467 if (argc < 1)
467 bb_show_usage(); 468 bb_show_usage();
468 469
469 myid = getpid() & 0xFFFF; 470 myid = (int16_t) getpid();
470 ping(*argv); 471 ping(*argv);
471 return EXIT_SUCCESS; 472 return EXIT_SUCCESS;
472} 473}