1
\$\begingroup\$

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), ReceiveOriginate (int), Originate + rttTransmit (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
#

(Note that the math values might be negative.)

\$\endgroup\$
5
  • \$\begingroup\$ @LegionMammal978, you can use any language! But it has to be executable from POSIX shell or tcsh, so perl is naturally the likely contender (but surprises are welcome!). You aren't at all required to use hping, unbuffer or perl! I think it's also been implied that you can install any packages using standard OS tools, without such steps affecting the total character count, either. \$\endgroup\$
    – cnst
    Oct 11, 2015 at 20:55
  • \$\begingroup\$ ...so can I ssh into my computer to use Mathematica? :P \$\endgroup\$ Oct 11, 2015 at 23:45
  • \$\begingroup\$ @LegionMammal978, if you can send ICMP timestamp packets that way, go ahead! \$\endgroup\$
    – cnst
    Oct 11, 2015 at 23:58
  • \$\begingroup\$ I'm not sure whether the question is requiring all answers to use hping (in which case it seems rather perverse that you seem to assume that the answer will call hping 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 about unbuffer, which seems completely unnecessary. \$\endgroup\$ Oct 12, 2015 at 7:53
  • \$\begingroup\$ @PeterTaylor, no, mentioned many times that hping use is not required; and, no, without unbuffer 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\$
    – cnst
    Oct 12, 2015 at 8:17

0

Browse other questions tagged or ask your own question.