diff options
author | Laurent Ghigonis <laurent@p1sec.com> | 2013-06-27 23:52:32 +0200 |
---|---|---|
committer | Laurent Ghigonis <laurent@p1sec.com> | 2013-06-27 23:52:32 +0200 |
commit | 88382cc6d864fe872f57593092ba86304474dfe0 (patch) | |
tree | 3ad53336e908e71dd25b8571c076767b363d79bf /libglouglou | |
parent | gg_map: improve argparse (diff) | |
download | glouglou-88382cc6d864fe872f57593092ba86304474dfe0.tar.xz glouglou-88382cc6d864fe872f57593092ba86304474dfe0.zip |
libglouglou: traceroute: count hops
Diffstat (limited to 'libglouglou')
-rw-r--r-- | libglouglou/libggnet_traceroute.c | 8 | ||||
-rw-r--r-- | libglouglou/libggnet_traceroute.h | 1 |
2 files changed, 9 insertions, 0 deletions
diff --git a/libglouglou/libggnet_traceroute.c b/libglouglou/libggnet_traceroute.c index 0c18d9f..352cb0b 100644 --- a/libglouglou/libggnet_traceroute.c +++ b/libglouglou/libggnet_traceroute.c @@ -259,6 +259,10 @@ ggnet_traceroute_report(struct ggnet_traceroute_req *req) { #define left (sizeof(report) - (p - report)) p = report; + if (req->hopcount != 0) + p += (u_char)snprintf(p, left, "%d hops\n", req->hopcount); + else + p += (u_char)snprintf(p, left, "target not answering\n"); TAILQ_FOREACH(hop, &req->hops_list, entry) { p += (u_char)snprintf(p, left, "%.2d: %s %s %.2f [XXX %p]\n", hop->ttl, addr_ntoa(&hop->ip), hop->answer, hop->delay, hop); } @@ -536,6 +540,7 @@ _hop_sport(struct ggnet_traceroute_req *req, int sport) /** * Returns the target hop, and clean the hops_list before calling user callback + * Also sets the hopcount */ static struct ggnet_traceroute_hop * _hop_last(struct ggnet_traceroute_req *req) @@ -543,13 +548,16 @@ _hop_last(struct ggnet_traceroute_req *req) struct ggnet_traceroute_hop *h, *ht; struct ggnet_traceroute_hop *last = NULL; int found = 0; + int count = 0; TAILQ_FOREACH_SAFE(h, &req->hops_list, entry, ht) { + count++; if (found) TAILQ_REMOVE(&req->hops_list, h, entry); else if (addr_cmp(&h->ip, &req->target->ip) == 0) { last = h; found = 1; + req->hopcount = count; } } diff --git a/libglouglou/libggnet_traceroute.h b/libglouglou/libggnet_traceroute.h index c32dcaa..dbbb9ec 100644 --- a/libglouglou/libggnet_traceroute.h +++ b/libglouglou/libggnet_traceroute.h @@ -55,6 +55,7 @@ struct ggnet_traceroute_req { struct ggnet_traceroute_hop *target; struct addr srcip; struct ggnet_traceroute_req_params *params; + int hopcount; TAILQ_HEAD(tailhead, ggnet_traceroute_hop) hops_list; struct { struct event *ev_recv; |