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;
pkt->icmp6_type = ICMP6_ECHO_REQUEST;
pkt->icmp6_code = 0;
pkt->icmp6_cksum = 0;
- pkt->icmp6_seq = SWAP_BE16(ntransmitted++);
+ pkt->icmp6_seq = htons(ntransmitted++);
pkt->icmp6_id = myid;
CLR(pkt->icmp6_seq % MAX_DUP_CHK);
#ifndef MLD_LISTENER_REDUCTION
# define MLD_LISTENER_REDUCTION ICMP6_MEMBERSHIP_REDUCTION
#endif
-static char *icmp6_type_name (int id)
+static char *icmp6_type_name(int id)
{
switch (id) {
case ICMP6_DST_UNREACH: return "Destination Unreachable";
return;
icmppkt = (struct icmp6_hdr *) packet;
-
if (icmppkt->icmp6_id != myid)
return; /* not our ping */
} else
if (icmppkt->icmp6_type != ICMP6_ECHO_REQUEST)
bb_error_msg("Warning: Got ICMP %d (%s)",
- icmppkt->icmp6_type, icmp6_type_name (icmppkt->icmp6_type));
+ icmppkt->icmp6_type, icmp6_type_name(icmppkt->icmp6_type));
}
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,
+ hostent->h_name,
inet_ntop(AF_INET6, &pingaddr.sin6_addr,
buf, sizeof(buf)),
datalen);
argc--;
argv++;
- options = 0;
/* Parse any options */
while (argc >= 1 && **argv == '-') {
thisarg = *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();
if (argc < 1)
bb_show_usage();
- myid = getpid() & 0xFFFF;
+ myid = (int16_t) getpid();
ping(*argv);
return EXIT_SUCCESS;
}