From 74cbd37e12e80656845738ba7ae5e8fc2a1108e0 Mon Sep 17 00:00:00 2001 From: Babak Farrokhi Date: Sun, 17 Sep 2017 20:09:25 +0430 Subject: [PATCH] Get pps counter from all interfaces --- pps.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 pps.c diff --git a/pps.c b/pps.c new file mode 100644 index 0000000..78b5168 --- /dev/null +++ b/pps.c @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +#define IFA_STAT(s) (((struct if_data *)ifa->ifa_data)->ifi_ ## s) + +int main(void) +{ + struct ifaddrs *ifap, *ifa; + char *name; + + if (getifaddrs(&ifap) != 0) { + printf("error\n"); + } + else { + for (ifa = ifap; ifa; ifa= ifa->ifa_next) { + name = ifa->ifa_name; + printf("%s: %lu, %lu\n", ifa->ifa_name, IFA_STAT(opackets), IFA_STAT(ipackets)); + while (ifa->ifa_next != NULL && + (strcmp(ifa->ifa_next->ifa_name, name) == 0)) { + ifa = ifa->ifa_next; + } + } + } +}