Merge branch 'pull/collectd-4'
[collectd.git] / src / traffic.c
index 91b624f..e08dc14 100644 (file)
@@ -1,11 +1,10 @@
 /**
  * collectd - src/traffic.c
- * Copyright (C) 2005,2006  Florian octo Forster
+ * Copyright (C) 2005-2007  Florian octo Forster
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
+ * Free Software Foundation; only version 2 of the License is applicable.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -47,8 +46,6 @@
 #  include <ifaddrs.h>
 #endif
 
-#define MODULE_NAME "traffic"
-
 /*
  * Various people have reported problems with `getifaddrs' and varying versions
  * of `glibc'. That's why it's disabled by default. Since more statistics are
@@ -67,8 +64,6 @@
 # define TRAFFIC_HAVE_READ 0
 #endif
 
-#define BUFSIZE 512
-
 /*
  * (Module-)Global variables
  */
@@ -226,7 +221,7 @@ static void if_submit (const char *dev, const char *type,
                unsigned long long tx)
 {
        value_t values[2];
-       value_list_t vl;
+       value_list_t vl = VALUE_LIST_INIT;
 
        if (check_ignore_if (dev))
                return;
@@ -237,14 +232,7 @@ static void if_submit (const char *dev, const char *type,
        vl.values = values;
        vl.values_len = 2;
        vl.time = time (NULL);
-
-       /* FIXME: do this globally */
-       if (gethostname (vl.host, sizeof (vl.host)) != 0)
-       {
-               syslog (LOG_ERR, "load plugin: gethostname failed: %s",
-                               strerror (errno));
-               return;
-       }
+       strcpy (vl.host, hostname);
        strcpy (vl.plugin, "interface");
        strcpy (vl.plugin_instance, "");
        strncpy (vl.type_instance, dev, sizeof (vl.type_instance));
@@ -284,7 +272,7 @@ static int traffic_read (void)
        struct IFA_DATA *if_data;
 
        if (getifaddrs (&if_list) != 0)
-               return;
+               return (-1);
 
        for (if_ptr = if_list; if_ptr != NULL; if_ptr = if_ptr->ifa_next)
        {
@@ -417,6 +405,3 @@ void module_register (void)
        plugin_register_read ("interface", traffic_read);
 #endif
 }
-
-#undef BUFSIZE
-#undef MODULE_NAME