The challenge involves printing the difference between ICMP originate and receive timestamps.
The idea is being able to determine which asymmetric internet path is responsible for packet delay.
One can use hping
with --icmp-ts
option to gain the raw data on ICMP_TSTAMP
. The task is complicated by the fact that hping
does a fully-buffered output when piped, so, an extra bit of non-portable code is required to unbuffer
hping
prior to applying something like perl
.
Your programme snippet must execute from POSIX shell, ksh
or tcsh
, and output icmp_seq
(int), rtt
(float), tsrtt
(int), Receive
− Originate
(int), Originate
+ rtt
− Transmit
(int), one set per line, unbuffered or line buffered.
Shortest snippet wins. If needed, you can assume that unbuffer
is available (taking 9 characters), and hping
doesn't have an extra 2
in its name. (E.g., do the math to compensate if either are missing from your system and require an alias, which you must provide for your shell and system, but without penalising the score.) Also, subtract the domain name, too (extra bonus if you can make it easier to modify, e.g., appearing as the final argument of the snippet).
This is a sample raw data produced by hping
, should you wish to use it:
# hping --icmp-ts www.internet2.edu
HPING www.internet2.edu (re0 207.75.164.248): icmp mode set, 28 headers + 0 data bytes
len=46 ip=207.75.164.248 ttl=50 id=21731 icmp_seq=0 rtt=114.0 ms
ICMP timestamp: Originate=34679222 Receive=34679279 Transmit=34679279
ICMP timestamp RTT tsrtt=114
len=46 ip=207.75.164.248 ttl=50 id=21732 icmp_seq=1 rtt=114.1 ms
ICMP timestamp: Originate=34680225 Receive=34680282 Transmit=34680282
ICMP timestamp RTT tsrtt=115
^C
--- www.internet2.edu hping statistic ---
2 packets tramitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 114.0/114.0/114.1 ms
#
This is a screenshot of a sample complete solution which generates the required output in required format:
# unbuffer hping --icmp-ts www.internet2.edu \
| perl -ne 'if (/icmp_seq=(\d+) rtt=(\d+\.\d)/) {($s, $p) = ($1, $2);} \
if (/ate=(\d+) Receive=(\d+) Transmit=(\d+)/) {($o, $r, $t) = ($1, $2, $3);} \
if (/tsrtt=(\d+)/) { \
print $s, "\t", $p, "\t", $1, " = ", $r - $o, " + ", $o + $1 - $t, "\n"; }'
0 114.0 114 = 56 + 58
1 113.8 114 = 57 + 57
2 114.1 115 = 57 + 58
3 114.0 114 = 57 + 57
4 114.3 115 = 57 + 58
5 114.1 115 = 57 + 58
6 113.9 114 = 57 + 57
7 114.0 114 = 57 + 57
8 114.0 114 = 57 + 57
9 114.0 114 = 57 + 57
^C
#
ssh
into my computer to use Mathematica? :P \$\endgroup\$hping
(in which case it seems rather perverse that you seem to assume that the answer will callhping
rather than just act as a filter to take its output and reformat it) or whether it allows other methods to access ICMP packets. I'm also not sure why all the palaver aboutunbuffer
, which seems completely unnecessary. \$\endgroup\$hping
use is not required; and, no, withoutunbuffer
the presented solution won't work; i'm just presenting all the facts so people have a better idea of where they could start \$\endgroup\$