The Traceroute class is a container for global functions and state.
Each target has a TraceGroup (the "group" is a group of TraceProbes).
There's no need for a reference trace. It's arbitrary to pick a single host to be the reference host, when it may not even share all that many hops with other hosts.
Nmap does not perform a full trace to every host, so necessarily it must make assumptions about the hops that it has not probed. The first and most fundamental of these is that, in tracing a host, we find an intermediate hop that has already been seen in tracing another host, we may assume that it and all it parents' hops are shared between the two hosts.
This suggests a different algorithm and data structure for storing the topology information. We represent the topology as a tree composed of nodes of the form
struct Hop {
struct sockaddr_storage hop_address; struct sockaddr_storage in_trace_for; struct Node *parent;
}
You don't traverse the tree downward from the root; you traverse it upward from the leaves; from the targets back to localhost.
A side effect of this change is that it might be necessary to consult the records for more than one host when reading consolidated results. For example, the results for one host might say "hops 1-5 are the same as for host 1.1.1.1" and the results for 1.1.1.1 might say "hops 1-3 are the same as for host 2.2.2.2.
nmap -sP --traceroute scanme.nmap.org/30 -n
| 1 | 192.168.0.1 | == | 1 | 192.168.0.1 |
| 2 | 206.81.73.81 | == | 2 | 206.81.73.81 |
| 3 | 206.81.73.82 | == | 3 | 206.81.73.82 |
| 4 | 66.54.149.185 | == | 4 | 66.54.149.185 |
| 5 | 63.211.250.17 | == | 5 | 63.211.250.17 |
| 6 | 4.68.107.190 | != | 6 | 4.68.107.30 |
| 7 | 4.69.132.37 | |||
| 8 | 4.69.132.57 | == | 7 | 4.69.132.57 |
| 9 | 4.69.134.218 | != | 8 | 4.69.134.222 |
| 10 | 4.69.134.233 | != | 9 | 4.69.134.237 |
| 11 | 4.69.132.10 | == | 10 | 4.69.132.10 |
| 12 | 4.69.144.111 | != | 11 | 4.69.144.47 |
| 13 | 4.78.194.18 | == | 12 | 4.78.194.18 |
| 14 | 69.17.82.198 | == | 13 | 69.17.82.198 |
| 15 | 64.81.99.73 | != | 14 | 64.81.99.74 |

