From fa835fd553832d53a6167b42aa23edf117a9c0bb Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Mon, 19 Oct 2009 19:07:52 +0200 Subject: [PATCH] Make lldpctl display the age of displayed information. We rely on recorded time for last change and display the difference with the current time. Information is displayed like this: Interface: veth1 (via LLDP) - RID: 1 - Time: 0 day, 00:04:42 Any change will reset this time (for example, a new VLAN). This should close ticket #21. --- src/lldpctl.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/lldpctl.c b/src/lldpctl.c index 92256115..6ab7a56c 100644 --- a/src/lldpctl.c +++ b/src/lldpctl.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -818,6 +819,23 @@ display_vlans(struct lldpd_port *port) } #endif +static const char* +display_age(struct lldpd_port *port) +{ + static char sage[30]; + int age = (int)(time(NULL) - port->p_lastchange); + if (snprintf(sage, sizeof(sage), + "%d day%s, %02d:%02d:%02d", + age / (60*60*24), + (age / (60*60*24) > 1)?"s":"", + (age / (60*60)) % (60*60*24), + (age / 60) % (60*60), + age % 60) >= sizeof(sage)) + return "too much"; + else + return sage; +} + static void display_interfaces(int s, int argc, char *argv[]) { @@ -861,7 +879,8 @@ display_interfaces(int s, int argc, char *argv[]) case (LLDPD_MODE_SONMP): printf("SONMP"); break; default: printf("unknown protocol"); break; } - printf(") - RID: %d\n", chassis.c_index); + printf(") - RID: %d", chassis.c_index); + printf(" - Time: %s\n", display_age(&port)); display_chassis(&chassis); printf("\n"); display_port(&port); -- 2.39.5