ping6: resolve interface name to number early.
gcc is more efficient at truncating int to int16 via cast, use that instead of &.
This commit is contained in:
parent
cb6874cc66
commit
db7f2e5881
@ -416,7 +416,7 @@ int ping_main(int argc, char **argv)
|
|||||||
if (argc < 1)
|
if (argc < 1)
|
||||||
bb_show_usage();
|
bb_show_usage();
|
||||||
|
|
||||||
myid = getpid() & 0xFFFF;
|
myid = (int16_t) getpid();
|
||||||
ping(*argv);
|
ping(*argv);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ int ping6_main(int argc, char **argv)
|
|||||||
static struct sockaddr_in6 pingaddr;
|
static struct sockaddr_in6 pingaddr;
|
||||||
static int pingsock = -1;
|
static int pingsock = -1;
|
||||||
static int datalen; /* intentionally uninitialized to work around gcc bug */
|
static int datalen; /* intentionally uninitialized to work around gcc bug */
|
||||||
static char* ifname;
|
static int if_index;
|
||||||
|
|
||||||
static long ntransmitted, nreceived, nrepeats, pingcount;
|
static long ntransmitted, nreceived, nrepeats, pingcount;
|
||||||
static int myid, options;
|
static int myid, options;
|
||||||
@ -367,10 +367,8 @@ static void ping(const char *host)
|
|||||||
setsockopt(pingsock, SOL_IPV6, IPV6_HOPLIMIT, (char *) &sockopt,
|
setsockopt(pingsock, SOL_IPV6, IPV6_HOPLIMIT, (char *) &sockopt,
|
||||||
sizeof(sockopt));
|
sizeof(sockopt));
|
||||||
|
|
||||||
if (ifname) {
|
if (if_index)
|
||||||
if ((pingaddr.sin6_scope_id = if_nametoindex(ifname)) == 0)
|
pingaddr.sin6_scope_id = if_index;
|
||||||
bb_error_msg_and_die("%s: invalid interface name", ifname);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("PING %s (%s): %d data bytes\n",
|
printf("PING %s (%s): %d data bytes\n",
|
||||||
hostent->h_name,
|
hostent->h_name,
|
||||||
@ -455,7 +453,10 @@ int ping6_main(int argc, char **argv)
|
|||||||
if (--argc <= 0)
|
if (--argc <= 0)
|
||||||
bb_show_usage();
|
bb_show_usage();
|
||||||
argv++;
|
argv++;
|
||||||
ifname = *argv;
|
if_index = if_nametoindex(*argv);
|
||||||
|
if (!if_index)
|
||||||
|
bb_error_msg_and_die(
|
||||||
|
"%s: invalid interface name", *argv);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
bb_show_usage();
|
bb_show_usage();
|
||||||
@ -466,7 +467,7 @@ int ping6_main(int argc, char **argv)
|
|||||||
if (argc < 1)
|
if (argc < 1)
|
||||||
bb_show_usage();
|
bb_show_usage();
|
||||||
|
|
||||||
myid = getpid() & 0xFFFF;
|
myid = (int16_t) getpid();
|
||||||
ping(*argv);
|
ping(*argv);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user