git: 3c7ef29e8998 - stable/13 - ping: Avoid magic numbers
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 24 Mar 2023 16:58:30 UTC
The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=3c7ef29e89982ff243b18fce2bac4355028da879 commit 3c7ef29e89982ff243b18fce2bac4355028da879 Author: Jose Luis Duran <jlduran@gmail.com> AuthorDate: 2023-03-17 13:24:44 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2023-03-24 16:58:01 +0000 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 (cherry picked from commit 491263d7a640a85a6be40fd0c0a9397d072f0847) --- sbin/ping/ping.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c index 2fc876e50776..796f29438a70 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -1674,7 +1674,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", @@ -1690,7 +1690,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'); @@ -1710,7 +1710,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);