ping: Avoid magic numbers

The sizeof(struct ip) is 20.
The sizeof(struct in_addr) is 4.

No functional change intended.

Reviewed by:	asomers, markj
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D39125
This commit is contained in:
Jose Luis Duran 2023-03-17 09:24:44 -04:00 committed by Mark Johnston
parent ff6d60946a
commit 491263d7a6

View file

@ -1670,7 +1670,7 @@ pr_iph(struct ip *ip)
int hlen;
hlen = ip->ip_hl << 2;
cp = (u_char *)ip + 20; /* point to options */
cp = (u_char *)ip + sizeof(struct ip); /* point to options */
(void)printf("Vr HL TOS Len ID Flg off TTL Pro cks Src Dst\n");
(void)printf(" %1x %1x %02x %04x %04x",
@ -1686,7 +1686,7 @@ pr_iph(struct ip *ip)
memcpy(&ina, &ip->ip_dst.s_addr, sizeof ina);
(void)printf(" %s ", inet_ntoa(ina));
/* dump any option bytes */
while (hlen-- > 20) {
while (hlen-- > (int)sizeof(struct ip)) {
(void)printf("%02x", *cp++);
}
(void)putchar('\n');
@ -1706,7 +1706,7 @@ pr_addr(struct in_addr ina)
if (options & F_NUMERIC)
return inet_ntoa(ina);
hp = cap_gethostbyaddr(capdns, (char *)&ina, 4, AF_INET);
hp = cap_gethostbyaddr(capdns, (char *)&ina, sizeof(ina), AF_INET);
if (hp == NULL)
return inet_ntoa(ina);