From 88382cc6d864fe872f57593092ba86304474dfe0 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 27 Jun 2013 23:52:32 +0200 Subject: libglouglou: traceroute: count hops --- libglouglou/libggnet_traceroute.c | 8 ++++++++ libglouglou/libggnet_traceroute.h | 1 + 2 files changed, 9 insertions(+) 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; -- cgit v1.2.3-59-g8ed1b