apps/system/ping and ping6: Send ID and seqno in network byte order.
This commit is contained in:
parent
32182421a9
commit
604885cbef
@ -202,7 +202,7 @@ static void icmp_ping(FAR struct ping_info_s *info)
|
||||
|
||||
memset(&outhdr, 0, sizeof(struct icmp_hdr_s));
|
||||
outhdr.type = ICMP_ECHO_REQUEST;
|
||||
outhdr.id = ping_newid();
|
||||
outhdr.id = htons(ping_newid());
|
||||
outhdr.seqno = 0;
|
||||
|
||||
printf("PING %u.%u.%u.%u %d bytes of data\n",
|
||||
@ -240,7 +240,7 @@ static void icmp_ping(FAR struct ping_info_s *info)
|
||||
if (nsent < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: sendto failed at seqno %u: %d\n",
|
||||
outhdr.seqno, errno);
|
||||
ntohs(outhdr.seqno), errno);
|
||||
return;
|
||||
}
|
||||
else if (nsent != outsize)
|
||||
@ -276,7 +276,7 @@ static void icmp_ping(FAR struct ping_info_s *info)
|
||||
(info->dest.s_addr >> 8 ) & 0xff,
|
||||
(info->dest.s_addr >> 16) & 0xff,
|
||||
(info->dest.s_addr >> 24) & 0xff,
|
||||
outhdr.seqno, info->delay);
|
||||
ntohs(outhdr.seqno), info->delay);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -307,15 +307,15 @@ static void icmp_ping(FAR struct ping_info_s *info)
|
||||
fprintf(stderr,
|
||||
"WARNING: Ignoring ICMP reply with ID %u. "
|
||||
"Expected %u\n",
|
||||
inhdr->id, outhdr.id);
|
||||
ntohs(inhdr->id), ntohs(outhdr.id));
|
||||
retry = true;
|
||||
}
|
||||
else if (inhdr->seqno > outhdr.seqno)
|
||||
else if (ntohs(inhdr->seqno) > ntohs(outhdr.seqno))
|
||||
{
|
||||
fprintf(stderr,
|
||||
"WARNING: Ignoring ICMP reply to sequence %u. "
|
||||
"Expected <= &u\n",
|
||||
inhdr->seqno, outhdr.seqno);
|
||||
ntohs(inhdr->seqno), ntohs(outhdr.seqno));
|
||||
retry = true;
|
||||
}
|
||||
else
|
||||
@ -323,7 +323,7 @@ static void icmp_ping(FAR struct ping_info_s *info)
|
||||
bool verified = true;
|
||||
int32_t pktdelay = elapsed;
|
||||
|
||||
if (inhdr->seqno < outhdr.seqno)
|
||||
if (ntohs(inhdr->seqno) < ntohs(outhdr.seqno))
|
||||
{
|
||||
fprintf(stderr, "WARNING: Received after timeout\n");
|
||||
pktdelay += info->delay;
|
||||
@ -336,7 +336,7 @@ static void icmp_ping(FAR struct ping_info_s *info)
|
||||
(info->dest.s_addr >> 8 ) & 0xff,
|
||||
(info->dest.s_addr >> 16) & 0xff,
|
||||
(info->dest.s_addr >> 24) & 0xff,
|
||||
inhdr->seqno, pktdelay);
|
||||
ntohs(inhdr->seqno), pktdelay);
|
||||
|
||||
/* Verify the payload data */
|
||||
|
||||
@ -407,7 +407,7 @@ static void icmp_ping(FAR struct ping_info_s *info)
|
||||
(void)nanosleep(&rqt, NULL);
|
||||
}
|
||||
|
||||
outhdr.seqno++;
|
||||
outhdr.seqno = htons(ntohs(outhdr.seqno) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -422,8 +422,8 @@ static void show_usage(FAR const char *progname, int exitcode)
|
||||
printf("\nUsage: %s [-c <count>] [-i <interval>] <hostname>\n", progname);
|
||||
printf(" %s -h\n", progname);
|
||||
printf("\nWhere:\n");
|
||||
printf(" <hostname> is either an IPv6 address or the name of the remote host\n");
|
||||
printf(" that is requested the ICMPv6 ECHO reply.\n");
|
||||
printf(" <hostname> is either an IPv4 address or the name of the remote host\n");
|
||||
printf(" that is requested the ICMPv4 ECHO reply.\n");
|
||||
#else
|
||||
printf("\nUsage: %s [-c <count>] [-i <interval>] <ip-address>\n", progname);
|
||||
printf(" %s -h\n", progname);
|
||||
|
@ -208,7 +208,7 @@ static void icmpv6_ping(FAR struct ping6_info_s *info)
|
||||
|
||||
memset(&outhdr, 0, SIZEOF_ICMPV6_ECHO_REQUEST_S(0));
|
||||
outhdr.type = ICMPv6_ECHO_REQUEST;
|
||||
outhdr.id = ping6_newid();
|
||||
outhdr.id = htons(ping6_newid());
|
||||
outhdr.seqno = 0;
|
||||
|
||||
(void)inet_ntop(AF_INET6, info->dest.s6_addr16, info->strbuffer,
|
||||
@ -244,7 +244,7 @@ static void icmpv6_ping(FAR struct ping6_info_s *info)
|
||||
if (nsent < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: sendto failed at seqno %u: %d\n",
|
||||
outhdr.seqno, errno);
|
||||
ntohs(outhdr.seqno), errno);
|
||||
return;
|
||||
}
|
||||
else if (nsent != outsize)
|
||||
@ -278,7 +278,7 @@ static void icmpv6_ping(FAR struct ping6_info_s *info)
|
||||
(void)inet_ntop(AF_INET6, info->dest.s6_addr16,
|
||||
info->strbuffer, INET6_ADDRSTRLEN);
|
||||
printf("No response from %s: icmp_seq=%u time=%u ms\n",
|
||||
info->strbuffer, outhdr.seqno, info->delay);
|
||||
info->strbuffer, ntohs(outhdr.seqno), info->delay);
|
||||
|
||||
continue;
|
||||
}
|
||||
@ -310,15 +310,15 @@ static void icmpv6_ping(FAR struct ping6_info_s *info)
|
||||
fprintf(stderr,
|
||||
"WARNING: Ignoring ICMP reply with ID %u. "
|
||||
"Expected %u\n",
|
||||
inhdr->id, outhdr.id);
|
||||
ntohs(inhdr->id), ntohs(outhdr.id));
|
||||
retry = true;
|
||||
}
|
||||
else if (inhdr->seqno > outhdr.seqno)
|
||||
else if (ntohs(inhdr->seqno) > ntohs(outhdr.seqno))
|
||||
{
|
||||
fprintf(stderr,
|
||||
"WARNING: Ignoring ICMP reply to sequence %u. "
|
||||
"Expected <= &u\n",
|
||||
inhdr->seqno, outhdr.seqno);
|
||||
ntohs(inhdr->seqno), ntohs(outhdr.seqno));
|
||||
retry = true;
|
||||
}
|
||||
else
|
||||
@ -326,7 +326,7 @@ static void icmpv6_ping(FAR struct ping6_info_s *info)
|
||||
bool verified = true;
|
||||
int32_t pktdelay = elapsed;
|
||||
|
||||
if (inhdr->seqno < outhdr.seqno)
|
||||
if (ntohs(inhdr->seqno) < ntohs(outhdr.seqno))
|
||||
{
|
||||
fprintf(stderr, "WARNING: Received after timeout\n");
|
||||
pktdelay += info->delay;
|
||||
@ -337,7 +337,7 @@ static void icmpv6_ping(FAR struct ping6_info_s *info)
|
||||
info->strbuffer, INET6_ADDRSTRLEN);
|
||||
printf("%ld bytes from %s icmp_seq=%u time=%u ms\n",
|
||||
nrecvd - SIZEOF_ICMPV6_ECHO_REPLY_S(0),
|
||||
info->strbuffer, inhdr->seqno, pktdelay);
|
||||
info->strbuffer, ntohs(inhdr->seqno), pktdelay);
|
||||
|
||||
/* Verify the payload data */
|
||||
|
||||
@ -408,7 +408,7 @@ static void icmpv6_ping(FAR struct ping6_info_s *info)
|
||||
(void)nanosleep(&rqt, NULL);
|
||||
}
|
||||
|
||||
outhdr.seqno++;
|
||||
outhdr.seqno = htons(ntohs(outhdr.seqno) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user