mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
Merge from svn://svn.insecure.org/nmap-exp/david/nmap-traceroute. This
brings in a new, faster, parallel version of traceroute.
This commit is contained in:
219
traceroute.h
219
traceroute.h
@@ -93,221 +93,6 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
/* Probe types */
|
||||
#define PROBE_TRACE 0
|
||||
#define PROBE_TTL 1
|
||||
int traceroute(std::vector<Target *> &Targets);
|
||||
|
||||
/* Probe states */
|
||||
#define P_TIMEDOUT 0 /* probe has timedout */
|
||||
#define P_RETRANS 1 /* probe needs to be retransmitted */
|
||||
#define P_OK 2 /* waiting for response or received response */
|
||||
|
||||
/* Group states */
|
||||
#define G_OK P_OK
|
||||
#define G_DEAD_TTL 3 /* TTL has reached maximum value */
|
||||
#define G_FINISH 5 /* tracing has complete successfully */
|
||||
|
||||
#define MAX_TTL 50
|
||||
|
||||
#define HOP_COL 0
|
||||
#define RTT_COL 1
|
||||
#define HOST_COL 2
|
||||
|
||||
#define NAMEIPLEN MAXHOSTNAMELEN+INET6_ADDRSTRLEN
|
||||
|
||||
class NmapOutputTable;
|
||||
|
||||
/* Keeps track of each probes timing state */
|
||||
class TimeInfo {
|
||||
public:
|
||||
TimeInfo();
|
||||
int retranLimit();
|
||||
void adjustTimeouts(struct timeval *recv, u16 scan_delay);
|
||||
|
||||
unsigned long probeTimeout() {
|
||||
return MIN(10000000, to.timeout * 10);
|
||||
}
|
||||
/* true if this probe has been replied to */
|
||||
u8 gotReply() {
|
||||
return recvTime.tv_usec != 0 && recvTime.tv_sec != 0;
|
||||
}
|
||||
u8 getState() {
|
||||
return state;
|
||||
}
|
||||
u8 setState(u8 state);
|
||||
|
||||
struct timeout_info to;
|
||||
/* set to true if this probe is going to
|
||||
* consolidated because it has timed out */
|
||||
bool consolidated;
|
||||
|
||||
/* Rtt and timeout calculation */
|
||||
struct timeval recvTime;
|
||||
struct timeval sendTime;
|
||||
|
||||
private:
|
||||
u8 retransmissions;
|
||||
u8 state;
|
||||
};
|
||||
|
||||
/* traceprobes represent a single packet at a specific ttl. Traceprobes are
|
||||
* stored inside tracegroups. */
|
||||
class TraceProbe {
|
||||
public:
|
||||
TraceProbe(u32 dip, u32 sip, u16 sport, struct probespec& probe);
|
||||
~TraceProbe();
|
||||
|
||||
/* Return the ip address and resolved hostname in a string such as
|
||||
* "host.com (1.2.3.4)" or "6.6.6.6". */
|
||||
const char *nameIP();
|
||||
const char *HostName() {
|
||||
if (!hostname || !(*hostname))
|
||||
return NULL;
|
||||
else
|
||||
return *hostname;
|
||||
}
|
||||
/* probe type is either a standard probe (PROBE_TRACE) or a hop distance
|
||||
* probe (PROBE_TTL) */
|
||||
void setProbeType(u8 type) {
|
||||
this->probetype = type;
|
||||
}
|
||||
u8 probeType() {
|
||||
return probetype;
|
||||
}
|
||||
char *ipReplyStr() {
|
||||
return inet_ntoa (ipreplysrc);
|
||||
}
|
||||
|
||||
/* protocol information for this probe */
|
||||
TimeInfo timing;
|
||||
struct in_addr ipdst;
|
||||
struct in_addr ipsrc;
|
||||
struct in_addr ipreplysrc;
|
||||
struct probespec probe;
|
||||
u16 sport;
|
||||
u8 ttl;
|
||||
char **hostname;
|
||||
|
||||
private:
|
||||
u8 probetype;
|
||||
char *hostnameip;
|
||||
};
|
||||
|
||||
/* each trace group represents a target ip and contains a map of probes that
|
||||
* have been sent/recv'ed to/from the ip */
|
||||
class TraceGroup {
|
||||
public:
|
||||
TraceGroup(u32 dip, u16 sport, struct probespec& probe);
|
||||
~TraceGroup();
|
||||
/* map of all probes sent to this TraceGroups IP address. The map is keyed
|
||||
* by the source port number of the probe */
|
||||
std::map < u16, TraceProbe * >TraceProbes;
|
||||
std::map < u16, TraceProbe * >::size_type size() {
|
||||
return TraceProbes.size ();
|
||||
}
|
||||
/* checks for timedout probes and retransmits them Any probe that exceeds
|
||||
* the timing limits is considered non-responsive */
|
||||
void retransmissions(std::vector < TraceProbe * >&retrans);
|
||||
/* Returns a map from TTLs to probes, stripped of all unneeded probes and
|
||||
* with timed-out probes marked for consolidation. */
|
||||
std::map < u8, TraceProbe * > consolidateHops() const;
|
||||
/* the next ttl to send, if the destination has replied the ttl is
|
||||
* decremented, if it hasn't it is incremented */
|
||||
void nextTTL();
|
||||
/* number of probes currently waiting for replies */
|
||||
void incRemaining();
|
||||
void decRemaining();
|
||||
char *IPStr();
|
||||
u8 getRemaining() {
|
||||
return remaining;
|
||||
}
|
||||
u8 getState() {
|
||||
return state;
|
||||
}
|
||||
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;
|
||||
|
||||
/* Group wide timing */
|
||||
int scanDelay;
|
||||
int maxRetransmissions;
|
||||
u16 droppedPackets;
|
||||
u16 repliedPackets;
|
||||
u8 consecTimeouts;
|
||||
/* protocol information */
|
||||
struct probespec probe;
|
||||
u16 sport;
|
||||
u32 ipdst;
|
||||
/* estimated ttl distance to target */
|
||||
u8 hopDistance;
|
||||
/* largest ttl send so far */
|
||||
u8 ttl;
|
||||
/* the initial ttl guess. This is needed because the ttl may have to be
|
||||
* incremented to reach the destination host. Once nmap has reached the
|
||||
* destination it needs to start decrementing the ttl from the original
|
||||
* value so no duplicate probes are sent.
|
||||
*
|
||||
* For example, if the guess is 20 but the target is at 23. We will start
|
||||
* tracing backwards at 19. */
|
||||
u8 start_ttl;
|
||||
u8 consolidation_start;
|
||||
const u8 *src_mac_addr;
|
||||
const u8 *nxt_mac_addr;
|
||||
|
||||
private:
|
||||
/* the number of probes sent but and not yet replied to */
|
||||
u8 remaining;
|
||||
/* default state is G_OK, set to G_FINISH when
|
||||
* complete or one of the G_* error codes if this
|
||||
* group fails */
|
||||
u8 state;
|
||||
};
|
||||
|
||||
/* Public interface to traceroute functionality */
|
||||
class Traceroute {
|
||||
public:
|
||||
Traceroute(const char *device_name, devtype type, const scan_lists * probe_ports);
|
||||
~Traceroute();
|
||||
|
||||
/* perform the traceroute on a list of targets */
|
||||
void trace(std::vector < Target * >&Targets);
|
||||
/* Use nmaps rDNS functions to mass resolve the hops ip addresses */
|
||||
void resolveHops();
|
||||
/* display plain and XML traceroutes for target t */
|
||||
void outputTarget(Target * t);
|
||||
|
||||
private:
|
||||
/* map of all TraceGroups, keyed by
|
||||
* the groups destination IP address */
|
||||
std::map < u32, TraceGroup * >TraceGroups;
|
||||
|
||||
const struct scan_lists * scanlists;
|
||||
Target **hops;
|
||||
pcap_t *pd;
|
||||
eth_t *ethsd;
|
||||
int fd, total_size, cp_flag;
|
||||
struct in_addr ref_ipaddr;
|
||||
|
||||
/* called by outputTarget to log XML data */
|
||||
void outputXMLTrace(TraceGroup * tg);
|
||||
/* find a responsive port for t based on scan results */
|
||||
const probespec getTraceProbe(Target * t);
|
||||
/* sendTTLProbes() guesses the hop distance to a target by actively probing
|
||||
* the host. */
|
||||
void sendTTLProbes(std::vector < Target * >&Targets, std::vector < Target * >&vaild_targets);
|
||||
int sendProbe(TraceProbe * tp);
|
||||
/* reads probe replies for all protocols. returns finished(), which returns
|
||||
* true when all groups have finished or failed */
|
||||
bool readTraceResponses();
|
||||
bool finished();
|
||||
/* add message to output table "hops 1 to X are the same as <reference ip>".
|
||||
* This message should always come before none-consolidated hop output */
|
||||
void addConsolidationMessage(NmapOutputTable *Tbl, unsigned short row_count, unsigned short ttl);
|
||||
};
|
||||
void traceroute_hop_cache_clear();
|
||||
|
||||
Reference in New Issue
Block a user