traceroute.h

来自「Ubuntu packages of security software。 相」· C头文件 代码 · 共 373 行 · 第 1/2 页

H
373
字号
/* 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 (u8 proto, u32 dip, u32 sip, u16 sport, u16 dport);    ~TraceProbe ();    /* Return the ip address and resolved hostname in a string      * EG     *   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;    u16 sport;    u16 dport;    u8 proto;    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 dport, u16 sport, u8 proto);    ~TraceGroup ();    /* map of all probes sent to this TraceGroups IP address. The map      * is keyed by the source port 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);    /* consolidate timeouts, remove common paths elements     * and performs general upkeep on a finished trace */    void consolidateHops ();    /* the next ttl to send, if the destination has replied     * the ttl is decremented, if it hasn't it is incremented */    void nextTTL () { if (gotReply) ttl--; else { ttl++; hopDistance++;}}    /* number of probes currently waiting for replies */    void incRemaining () { if (remaining < 255) ++remaining; }    void decRemaining () { if (remaining > 0) --remaining; }    char *IPStr () { struct in_addr s; s.s_addr = ipdst; return inet_ntoa (s);}    u8 getRemaining () { return remaining;}    u8 getState () { return state; }    u8 setState (u8 state);    u8 setHopDistance (u8 hop_distance, u8 ttl);    bool gotReply;    bool noDistProbe;    /* Group wide timing */    int scanDelay;    int maxRetransmissions;    u16 droppedPackets;    u16 repliedPackets;    u8 consecTimeouts;    /* protocol information */    u8 proto;    u16 sport;    u16 dport;    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     *     * EG. 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);     ~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;    struct scan_info scaninfo;    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 */    int getTracePort (u8 proto, 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);};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?