Merge branch 'pr/1792'
[collectd.git] / src / interface.c
index 3024313..849de95 100644 (file)
@@ -26,7 +26,6 @@
 
 #include "common.h"
 #include "plugin.h"
-#include "configfile.h"
 #include "utils_ignorelist.h"
 
 #if HAVE_SYS_TYPES_H
@@ -169,17 +168,17 @@ static void if_submit (const char *dev, const char *type,
                derive_t rx,
                derive_t tx)
 {
-       value_t values[2];
        value_list_t vl = VALUE_LIST_INIT;
+       value_t values[] = {
+               { .derive = rx },
+               { .derive = tx },
+       };
 
        if (ignorelist_match (ignorelist, dev) != 0)
                return;
 
-       values[0].derive = rx;
-       values[1].derive = tx;
-
        vl.values = values;
-       vl.values_len = 2;
+       vl.values_len = STATIC_ARRAY_SIZE (values);
        sstrncpy (vl.host, hostname_g, sizeof (vl.host));
        sstrncpy (vl.plugin, "interface", sizeof (vl.plugin));
        sstrncpy (vl.plugin_instance, dev, sizeof (vl.plugin_instance));
@@ -192,7 +191,6 @@ static int interface_read (void)
 {
 #if HAVE_GETIFADDRS
        struct ifaddrs *if_list;
-       struct ifaddrs *if_ptr;
 
 /* Darwin/Mac OS X and possible other *BSDs */
 #if HAVE_STRUCT_IF_DATA
@@ -222,7 +220,7 @@ static int interface_read (void)
        if (getifaddrs (&if_list) != 0)
                return (-1);
 
-       for (if_ptr = if_list; if_ptr != NULL; if_ptr = if_ptr->ifa_next)
+       for (struct ifaddrs *if_ptr = if_list; if_ptr != NULL; if_ptr = if_ptr->ifa_next)
        {
                if (if_ptr->ifa_addr != NULL && if_ptr->ifa_addr->sa_family == AF_LINK) {
                        if_data = (struct IFA_DATA *) if_ptr->ifa_data;
@@ -306,7 +304,6 @@ static int interface_read (void)
 /* #endif KERNEL_LINUX */
 
 #elif HAVE_LIBKSTAT
-       int i;
        derive_t rx;
        derive_t tx;
        char iname[DATA_MAX_NAME_LEN];
@@ -314,7 +311,7 @@ static int interface_read (void)
        if (kc == NULL)
                return (-1);
 
-       for (i = 0; i < numif; i++)
+       for (int i = 0; i < numif; i++)
        {
                if (kstat_read (kc, ksp[i], NULL) == -1)
                        continue;
@@ -358,11 +355,11 @@ static int interface_read (void)
 
 #elif defined(HAVE_LIBSTATGRAB)
        sg_network_io_stats *ios;
-       int i, num;
+       int num;
 
        ios = sg_get_network_io_stats (&num);
 
-       for (i = 0; i < num; i++) {
+       for (int i = 0; i < num; i++) {
                if (!report_inactive && ios[i].rx == 0 && ios[i].tx == 0)
                        continue;
                if_submit (ios[i].interface_name, "if_octets", ios[i].rx, ios[i].tx);
@@ -371,7 +368,7 @@ static int interface_read (void)
 
 #elif defined(HAVE_PERFSTAT)
        perfstat_id_t id;
-       int i, ifs;
+       int ifs;
 
        if ((nif =  perfstat_netinterface(NULL, NULL, sizeof(perfstat_netinterface_t), 0)) < 0)
        {
@@ -397,7 +394,7 @@ static int interface_read (void)
                return (-1);
        }
 
-       for (i = 0; i < ifs; i++)
+       for (int i = 0; i < ifs; i++)
        {
                if (!report_inactive && ifstat[i].ipackets == 0 && ifstat[i].opackets == 0)
                        continue;