**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
return (ENOMEM);
}
- map = malloc (sizeof (*map));
+ map = calloc (1, sizeof (*map));
if (map == NULL)
{
sfree (key);
- ERROR ("ethstat plugin: malloc(3) failed.");
+ ERROR ("ethstat plugin: calloc failed.");
return (ENOMEM);
}
- memset (map, 0, sizeof (*map));
sstrncpy (map->type, ci->values[1].value.string, sizeof (map->type));
if (ci->values_num == 3)
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);
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;
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)
{
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)
{
close (fd);
sfree (strings);
sfree (stats);
- ERROR("ethstat plugin: malloc(3) failed.");
+ ERROR("ethstat plugin: malloc failed.");
return (-1);
}