ping: Fix the spacing between the time stamp and cp/dp

When an echo reply packet is received, the data is compared with the
sent data.  When a wrong byte is detected the command displays a report
with the differences.

The first row (the first 8-bytes of data after the ICMP header) should
include the time stamp (if data is at least 8-bytes), this value is not
taken into consideration for the comparison.  The remaining rows
represent the data (padded pattern) received/sent, with each byte being
compared for differences.

Print the space before (not after), to add an extra space after cp:/dp:
for better readability when the first time stamp octet is not
zero-padded, and to remove trailing spaces in the output.

Before:
    cp:99  0  0  c  1  5  c  0␣
    	ab cd ab cd ab cd ab cd ab cd ab cd ab cd ab cd␣
    	...

After:
    cp: 99  0  0  c  1  5  c  0
    	 ab cd ab cd ab cd ab cd ab cd ab cd ab cd ab cd
    	 ...

Reviewed by:	markj
MFC after:	1 week
Pull Request:	https://github.com/freebsd/freebsd-src/pull/863
Differential Revision:	https://reviews.freebsd.org/D39492
This commit is contained in:
Jose Luis Duran 2023-04-10 16:58:42 +00:00 committed by Mark Johnston
parent 03d4d1c778
commit 8db2c5802a
2 changed files with 37 additions and 2 deletions

View file

@ -1261,14 +1261,14 @@ pr_pack(char *buf, ssize_t cc, struct sockaddr_in *from, struct timespec *tv)
for (i = 0; i < datalen; ++i, ++cp) {
if ((i % 16) == 8)
(void)printf("\n\t");
(void)printf("%2x ", *cp);
(void)printf(" %2x", *cp);
}
(void)printf("\ndp:");
cp = &outpack[ICMP_MINLEN];
for (i = 0; i < datalen; ++i, ++cp) {
if ((i % 16) == 8)
(void)printf("\n\t");
(void)printf("%2x ", *cp);
(void)printf(" %2x", *cp);
}
break;
}

View file

@ -275,6 +275,8 @@ def redact(output):
("hlim=[0-9]*", "hlim="),
("ttl=[0-9]*", "ttl="),
("time=[0-9.-]*", "time="),
("cp: .*", "cp: xx xx xx xx xx xx xx xx"),
("dp: .*", "dp: xx xx xx xx xx xx xx xx"),
("\(-[0-9\.]+[0-9]+ ms\)", "(- ms)"),
("[0-9\.]+/[0-9.]+", "/"),
]
@ -1401,6 +1403,39 @@ def test_ping_46(self, expected):
},
id="_0_0_special_warp",
),
pytest.param(
{
"src": "192.0.2.1",
"dst": "192.0.2.2",
"icmp_type": 0,
"icmp_code": 0,
"special": "wrong",
},
{
"returncode": 0,
"stdout": """\
PATTERN: 0x01
PING 192.0.2.2 (192.0.2.2): 56 data bytes
64 bytes from: icmp_seq=0 ttl= time= ms
wrong data byte #55 should be 0x1 but was 0x0
cp: xx xx xx xx xx xx xx xx
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
dp: xx xx xx xx xx xx xx xx
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
--- 192.0.2.2 ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = /// ms
""",
"stderr": "",
"redacted": True,
},
id="_0_0_special_wrong",
),
]
@pytest.mark.parametrize("pinger_kargs, expected", pinger_testdata)