From a4ea6d2f7c9aefb18cd3c503e107ce91dcffe193 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 21 Aug 2009 01:05:41 +0000 Subject: [PATCH] The previous method of calculating the true hop distance from traceroute was incorrect; the hopDistance member can be much higher than the actual number of hops recorded. It was 33 when the real distance was 17. Instead, enumerate and count all the probes that got a response. --- traceroute.cc | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/traceroute.cc b/traceroute.cc index 005c88e57..7d19f4169 100644 --- a/traceroute.cc +++ b/traceroute.cc @@ -1290,11 +1290,23 @@ TraceGroup::setHopDistance(u8 hop_distance, u8 ttl) { * reading hopDistance, which despite its name does not contain the final hop * count. */ int TraceGroup::getDistance() { + map < u8, TraceProbe * >ttlProbes; + int i; + if (this->getState() != G_FINISH) return -1; - /* After a successful trace, hopDistance is 1 greater than the number of - * hops. */ - return this->hopDistance - 1; + + for (i = 1; i < consolidation_start; i++) { + if (commonPath[i] == 0) + return i - 1; + } + ttlProbes = consolidateHops(); + for ( ; i < MAX_TTL; i++) { + if (ttlProbes.find(i) == ttlProbes.end()) + break; + } + + return i - 1; } TraceProbe::TraceProbe(u32 dip, u32 sip, u16 sport, struct probespec& probe) {