X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fethstat.c;h=b30f614eab93460d7db4cc87d68d67c71d046b7f;hb=3fae5596643f1e361eb18c3d65448f8bc02fdd80;hp=8971f4dfcc2cb0cc10dbf7cf4c8e6ca271fbdc52;hpb=36ee20dc97d0e0a5483892667f5d032618e18f10;p=collectd.git diff --git a/src/ethstat.c b/src/ethstat.c index 8971f4df..b30f614e 100644 --- a/src/ethstat.c +++ b/src/ethstat.c @@ -119,7 +119,7 @@ static int ethstat_add_map (const oconfig_item_t *ci) /* {{{ */ if (value_map == NULL) { - value_map = c_avl_create ((void *) strcmp); + value_map = c_avl_create ((int (*) (const void *, const void *)) strcmp); if (value_map == NULL) { sfree (map); @@ -216,8 +216,6 @@ static void ethstat_submit_value (const char *device, static int ethstat_read_interface (char *device) { int fd; - struct ifreq req; - struct ethtool_drvinfo drvinfo; struct ethtool_gstrings *strings; struct ethtool_stats *stats; size_t n_stats; @@ -226,9 +224,6 @@ static int ethstat_read_interface (char *device) size_t i; int status; - memset (&req, 0, sizeof (req)); - sstrncpy(req.ifr_name, device, sizeof (req.ifr_name)); - fd = socket(AF_INET, SOCK_DGRAM, /* protocol = */ 0); if (fd < 0) { @@ -238,9 +233,16 @@ static int ethstat_read_interface (char *device) return 1; } - memset (&drvinfo, 0, sizeof (drvinfo)); - drvinfo.cmd = ETHTOOL_GDRVINFO; - req.ifr_data = (void *) &drvinfo; + struct ethtool_drvinfo drvinfo = { + .cmd = ETHTOOL_GDRVINFO + }; + + struct ifreq req = { + .ifr_data = (void *) &drvinfo + }; + + sstrncpy(req.ifr_name, device, sizeof (req.ifr_name)); + status = ioctl (fd, SIOCETHTOOL, &req); if (status < 0) { @@ -311,9 +313,13 @@ static int ethstat_read_interface (char *device) for (i = 0; i < n_stats; i++) { - const char *stat_name; + char *stat_name; stat_name = (void *) &strings->data[i * ETH_GSTRING_LEN]; + /* Remove leading spaces in key name */ + while (isspace ((int) *stat_name)) + stat_name++; + DEBUG("ethstat plugin: device = \"%s\": %s = %"PRIu64, device, stat_name, (uint64_t) stats->data[i]); ethstat_submit_value (device,