ping: Fix the display of Flags/Fragment Offset

In the IP header, Flags + Fragment Offset is a 16-bit field.

Use ntohs() instead of ntohl(), otherwise the Flags/Fragment Offset
values may not display correctly.

Before (DF set)

    Vr HL TOS  Len   ID Flg  off TTL Pro  cks      Src      Dst
     4  5  00 0054 0001   0 0000  40  01 b6a4 192.0.2.1  192.0.2.2

After (DF set)

    Vr HL TOS  Len   ID Flg  off TTL Pro  cks      Src      Dst
     4  5  00 0054 0001   2 0000  40  01 b6a4 192.0.2.1  192.0.2.2

Reviewed by:	markj
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D38479
This commit is contained in:
Jose Luis Duran 2023-03-14 11:09:27 -04:00 committed by Mark Johnston
parent f32d6f745d
commit 9185854d19
2 changed files with 3 additions and 4 deletions

View File

@ -1680,9 +1680,9 @@ pr_iph(struct ip *ip)
(void)printf(" %1x %1x %02x %04x %04x",
ip->ip_v, ip->ip_hl, ip->ip_tos, ntohs(ip->ip_len),
ntohs(ip->ip_id));
(void)printf(" %1lx %04lx",
(u_long) (ntohl(ip->ip_off) & 0xe000) >> 13,
(u_long) ntohl(ip->ip_off) & 0x1fff);
(void)printf(" %1x %04x",
(ntohs(ip->ip_off) & 0xe000) >> 13,
ntohs(ip->ip_off) & 0x1fff);
(void)printf(" %02x %02x %04x", ip->ip_ttl, ip->ip_p,
ntohs(ip->ip_sum));
memcpy(&ina, &ip->ip_src.s_addr, sizeof ina);

View File

@ -919,7 +919,6 @@ Vr HL TOS Len ID Flg off TTL Pro cks Src Dst
"stderr": "",
"redacted": False,
},
marks=pytest.mark.skip("XXX currently failing"),
id="_3_1_flags_DF",
),
]