From: Vincent Bernat Date: Fri, 21 Jun 2013 07:10:02 +0000 (+0200) Subject: lldpd: count number of chassis to get number of neighbors X-Git-Tag: 0.7.4~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=480f1c6130eff6a7cd453d4b3d3f5d809f6d6138;p=thirdparty%2Flldpd.git lldpd: count number of chassis to get number of neighbors Also, if only one neighbor, just display its name. --- diff --git a/src/daemon/lldpd.c b/src/daemon/lldpd.c index 79bea501..300ae8f0 100644 --- a/src/daemon/lldpd.c +++ b/src/daemon/lldpd.c @@ -216,16 +216,21 @@ lldpd_hardware_cleanup(struct lldpd *cfg, struct lldpd_hardware *hardware) static void lldpd_count_neighbors(struct lldpd *cfg) { - struct lldpd_hardware *hardware; - struct lldpd_port *port; + struct lldpd_chassis *chassis; + const char *neighbor; unsigned neighbors = 0; - TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) { - TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { - if (!port->p_hidden_in) - neighbors++; - } + TAILQ_FOREACH(chassis, &cfg->g_chassis, c_entries) { + neighbors++; + neighbor = chassis->c_name; } - setproctitle("%d neighbor%s", neighbors, (neighbors > 1)?"s":""); + neighbors--; + if (neighbors == 0) + setproctitle("no neighbor"); + else if (neighbors == 1 && neighbor) + setproctitle("connected to %s", neighbor); + else + setproctitle("%d neighbor%s", neighbors, + (neighbors > 1)?"s":""); } static void