1

prevent ping output from showing (truncated) instead of time=##.# ms

The problem of undesired output format is clearly due to the test I'm running: determining packet loss threshold by packet size. My question is, how can I view the time (instead of "truncated") anyways?

Desired output format:

user@desktop:~$ ping -c 10 -s 1372 -v hostname.com
PING hostname.com (X.X.X.X) 1372(1400) bytes of data.
1380 bytes from hostname.com (X.X.X.X): icmp_req=1 ttl=242 time=82.8 ms
1380 bytes from hostname.com (X.X.X.X): icmp_req=2 ttl=242 time=82.7 ms

--- hostname.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 82.826/83.038/83.250/0.212 ms

Undesired output format:

user@desktop:~$ ping -c 10 -s 1373 -v hostname.com
PING hostname.com (X.X.X.X) 1373(1401) bytes of data.
1376 bytes from hostname.com (X.X.X.X): icmp_req=1 ttl=242 (truncated)
1376 bytes from hostname.com (X.X.X.X): icmp_req=2 ttl=242 (truncated)

--- hostname.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 82.997/83.010/83.023/0.013 ms

In the interest of completeness, also showing an intermittent error.

user@desktop:~$ ping -c 2 -s 1373 -v hostname.com
PING hostname.com (X.X.X.X) 1373(1401) bytes of data.
From hostname2.com (Y.Y.Y.Y) icmp_seq=1 Frag needed and DF set (mtu = 1400)
1376 bytes from hostname.com (X.X.X.X): icmp_req=2 ttl=242 (truncated)

--- hostname.com ping statistics ---
2 packets transmitted, 1 received, +1 errors, 50% packet loss, time 999ms
rtt min/avg/max/mdev = 82.937/82.937/82.937/0.000 ms
  • I cannot reproduce the (truncated) output. – mjb2kmn Sep 18 '17 at 19:17
1

I believe this is not possible.

Given my reading of the ping source code if the data size returned is smaller than the data size sent, it will always print that.

My guess is that the time is viewed as invalid or useless due to the data being truncated.

For clarification: The conditional on the line linked above is

if (cc < datalen+8) {

cc represents the number of bytes received and datalen is the number you provided with the -s option. Therefor, this is checking if the size of the reply is less than the size sent (1373 in your 2nd example).

Another thing I just noticed is the timing is calculated in the very next block following the one that detects the truncated data. After the line that prints the (truncated) text, the function returns, so the timing block never runs.

Not really an answer solving your problem, but an explanation of why it can't be done.
The answer of how to not show (truncated) is: make the remote host to not truncate the packets.

  • The link to the highlighted source code is very helpful. You've explained the reason as being because of the issue described in the question, so I dont think this deserves to be marked as an answer. Why was the if statement written into the ping program and what is meant by truncated? It seems to be an attempt to conserve output line space, and also able to be negated. – conman253 Sep 19 '17 at 20:39
  • I don't believe it has anything to do with the output in the terminal. I believe this is referring to the return packet's data size being truncated. – mjb2kmn Sep 19 '17 at 21:00
  • The "why" you mention is what I'm guessing at by saying "viewed as invalid or useless due to the data being truncated" -- Perhaps a proper network engineer would be of use here. – mjb2kmn Sep 19 '17 at 21:16
  • This is a good answer. @conman253 the reason was provided by mjb2kmn "if the data size returned is smaller than the data size sent, it will always print [truncated]" – thinkmassive Jan 18 '18 at 22:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.