]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
Make lldpctl display the age of displayed information.
authorVincent Bernat <bernat@luffy.cx>
Mon, 19 Oct 2009 17:07:52 +0000 (19:07 +0200)
committerVincent Bernat <bernat@luffy.cx>
Wed, 28 Oct 2009 09:59:58 +0000 (10:59 +0100)
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

index 92256115397fb8a0fca1c33d255b2fd252d6eabe..6ab7a56c18fc67a9c2ad0367347c5f229a4c2416 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <stdio.h>
 #include <unistd.h>
+#include <time.h>
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -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);