summaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenis Vlasenko2006-09-02 16:16:23 +0000
committerDenis Vlasenko2006-09-02 16:16:23 +0000
commitdb7f2e5881b9ae40896d7660cd2f2446f514c72d (patch)
tree302ceaf4aabb508dc8a772989fa1151f0406663b /networking
parentcb6874cc66df69fe49c65338a67fec1206d02c4b (diff)
downloadbusybox-db7f2e5881b9ae40896d7660cd2f2446f514c72d.zip
busybox-db7f2e5881b9ae40896d7660cd2f2446f514c72d.tar.gz
ping6: resolve interface name to number early.
gcc is more efficient at truncating int to int16 via cast, use that instead of &.
Diffstat (limited to 'networking')
-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 8ccb7e0..967a3e3 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -416,7 +416,7 @@ int ping_main(int argc, char **argv)
if (argc < 1)
bb_show_usage();
- myid = getpid() & 0xFFFF;
+ myid = (int16_t) getpid();
ping(*argv);
return EXIT_SUCCESS;
}
diff --git a/networking/ping6.c b/networking/ping6.c
index fdcd4ec..38d605c 100644
--- a/networking/ping6.c
+++ b/networking/ping6.c
@@ -146,7 +146,7 @@ int ping6_main(int argc, char **argv)
static struct sockaddr_in6 pingaddr;
static int pingsock = -1;
static int datalen; /* intentionally uninitialized to work around gcc bug */
-static char* ifname;
+static int if_index;
static long ntransmitted, nreceived, nrepeats, pingcount;
static int myid, options;
@@ -367,10 +367,8 @@ static void ping(const char *host)
setsockopt(pingsock, SOL_IPV6, IPV6_HOPLIMIT, (char *) &sockopt,
sizeof(sockopt));
- if (ifname) {
- if ((pingaddr.sin6_scope_id = if_nametoindex(ifname)) == 0)
- bb_error_msg_and_die("%s: invalid interface name", ifname);
- }
+ if (if_index)
+ pingaddr.sin6_scope_id = if_index;
printf("PING %s (%s): %d data bytes\n",
hostent->h_name,
@@ -455,7 +453,10 @@ int ping6_main(int argc, char **argv)
if (--argc <= 0)
bb_show_usage();
argv++;
- ifname = *argv;
+ if_index = if_nametoindex(*argv);
+ if (!if_index)
+ bb_error_msg_and_die(
+ "%s: invalid interface name", *argv);
break;
default:
bb_show_usage();
@@ -466,7 +467,7 @@ int ping6_main(int argc, char **argv)
if (argc < 1)
bb_show_usage();
- myid = getpid() & 0xFFFF;
+ myid = (int16_t) getpid();
ping(*argv);
return EXIT_SUCCESS;
}