From 5c1168c024292462b652e53c047743639d8b4564 Mon Sep 17 00:00:00 2001 From: david Date: Thu, 20 Aug 2009 20:57:35 +0000 Subject: [PATCH] After a successful traceroute, set the distance to the host in question so it appears in OS fingerprints. --- traceroute.cc | 22 +++++++++++++++++++++- traceroute.h | 5 +++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/traceroute.cc b/traceroute.cc index 0d76bad1a..adeebff79 100644 --- a/traceroute.cc +++ b/traceroute.cc @@ -802,6 +802,16 @@ Traceroute::trace(vector < Target * >&Targets) { swap(total_complete, total_size); SPM->printStats(MIN((double) total_complete / total_size, 0.99), NULL); } + + /* Now set the distance in the Target structure for each of the valid + * targets. */ + for (targ = valid_targets.begin(); targ != valid_targets.end(); ++targ) { + int distance; + distance = TraceGroups[t->v4host().s_addr]->getDistance(); + if (distance != -1) + (*targ)->distance = distance; + } + SPM->endTask(NULL, NULL); delete SPM; } @@ -1135,7 +1145,6 @@ TraceGroup::retransmissions(vector < TraceProbe * >&retrans) { if ((++consecTimeouts) > 5 && maxRetransmissions > 2) maxRetransmissions = 2; if (it->second->probeType() == PROBE_TTL) { - hopDistance = 1; noDistProbe = true; /* Give up on this host. We should be able to do a trace against an unresponsive target but for now it's too slow. */ @@ -1274,6 +1283,17 @@ TraceGroup::setHopDistance(u8 hop_distance, u8 ttl) { return this->hopDistance; } +/* Get the number of hops to the target, or -1 if unknown. Use this instead of + * reading hopDistance, which despite its name does not contain the final hop + * count. */ +int TraceGroup::getDistance() { + if (this->getState() != G_FINISH) + return -1; + /* After a successful trace, hopDistance is 1 greater than the number of + * hops. */ + return this->hopDistance - 1; +} + TraceProbe::TraceProbe(u32 dip, u32 sip, u16 sport, struct probespec& probe) { this->sport = sport; this->probe = probe; diff --git a/traceroute.h b/traceroute.h index 6b468bf02..91bab3481 100644 --- a/traceroute.h +++ b/traceroute.h @@ -227,6 +227,11 @@ class TraceGroup { u8 setState(u8 state); u8 setHopDistance(u8 hop_distance, u8 ttl); + /* Get the number of hops to the target, or -1 if unknown. Use this instead + * of reading hopDistance, which despite its name does not contain the final + * hop count. */ + int getDistance(); + bool gotReply; bool noDistProbe;