AC_CHECK_HEADERS(utmp.h)
AC_CHECK_HEADERS(utmpx.h)
+# For traffic plugin
+AC_CHECK_HEADERS(net/if.h)
+AC_CHECK_HEADERS(ifaddrs.h)
+AC_CHECK_HEADERS(linux/if.h, [], [],
+[
+#if HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#if HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#endif
+])
+AC_CHECK_HEADERS(linux/netdevice.h, [], [],
+[
+#if HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#if HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#endif
+#if HAVE_LINUX_IF_H
+# include <linux/if.h>
+#endif
+])
+
# For apache plugin
AC_CHECK_HEADERS(curl/curl.h)
AC_CHECK_FUNCS(quotactl)
AC_CHECK_FUNCS(getgrgid getpwuid)
+# For traffic module
+AC_CHECK_FUNCS(getifaddrs)
+
# For mount interface
AC_CHECK_FUNCS(getfsent getvfsent listmntent)
AC_CHECK_FUNCS(getfsstat)
)
fi
+# Check for structures
+AC_CHECK_MEMBERS([struct if_data.ifi_ibytes, struct if_data.ifi_obytes],
+ [AC_DEFINE(HAVE_STRUCT_IF_DATA, 1, [Define if struct if_data exists and is usable.])],
+ [],
+ [#include <net/if.h>])
+AC_CHECK_MEMBERS([struct net_device_stats.rx_bytes, struct net_device_stats.tx_bytes],
+ [AC_DEFINE(HAVE_STRUCT_NET_DEVICE_STATS, 1, [Define if struct net_device_stats exists and is usable.])],
+ [],
+ [
+ #include <sys/types.h>
+ #include <sys/socket.h>
+ #include <linux/if.h>
+ #include <linux/netdevice.h>
+ ])
+
AC_MSG_CHECKING([for kernel type ($host_os)])
case $host_os in
*linux*)
#include "common.h"
#include "plugin.h"
+#if HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#if HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#endif
+
+/* One cannot include both. This sucks. */
+#if HAVE_LINUX_IF_H
+# include <linux/if.h>
+#elif HAVE_NET_IF_H
+# include <net/if.h>
+#endif
+
+#if HAVE_LINUX_NETDEVICE_H
+# include <linux/netdevice.h>
+#endif
+#if HAVE_IFADDRS_H
+# include <ifaddrs.h>
+#endif
+
#define MODULE_NAME "traffic"
-#if defined(KERNEL_LINUX) || defined(HAVE_LIBKSTAT) || defined(HAVE_LIBSTATGRAB)
+#if HAVE_GETIFADDRS || defined(KERNEL_LINUX) || defined(HAVE_LIBKSTAT) || defined(HAVE_LIBSTATGRAB)
# define TRAFFIC_HAVE_READ 1
#else
# define TRAFFIC_HAVE_READ 0
static void traffic_init (void)
{
-#ifdef HAVE_LIBKSTAT
+#if HAVE_GETIFADDRS
+ /* nothing */
+/* #endif HAVE_GETIFADDRS */
+
+#elif KERNEL_LINUX
+ /* nothing */
+/* #endif KERNEL_LINUX */
+
+#elif HAVE_LIBKSTAT
kstat_t *ksp_chain;
unsigned long long val;
continue;
ksp[numif++] = ksp_chain;
}
-#endif /* HAVE_LIBKSTAT */
+/* #endif HAVE_LIBKSTAT */
+
+#elif HAVE_LIBSTATG
+ /* nothing */
+#endif /* HAVE_LIBSTATG */
+
+ return;
}
static void traffic_write (char *host, char *inst, char *val)
static void traffic_read (void)
{
-#ifdef KERNEL_LINUX
+#if HAVE_GETIFADDRS
+ struct ifaddrs *if_list;
+ struct ifaddrs *if_ptr;
+
+#if HAVE_STRUCT_IF_DATA
+# define IFA_DATA if_data
+# define IFA_INCOMING ifi_ibytes
+# define IFA_OUTGOING ifi_obytes
+#elif HAVE_STRUCT_NET_DEVICE_STATS
+# define IFA_DATA net_device_stats
+# define IFA_INCOMING rx_bytes
+# define IFA_OUTGOING tx_bytes
+#else
+# error "No suitable type for `struct ifaddrs->ifa_data' found."
+#endif
+
+ struct IFA_DATA *if_data;
+
+ if (getifaddrs (&if_list) != 0)
+ return;
+
+ for (if_ptr = if_list; if_ptr != NULL; if_ptr = if_ptr->ifa_next)
+ {
+ if ((if_data = (struct IFA_DATA *) if_ptr->ifa_data) == NULL)
+ continue;
+
+ traffic_submit (if_ptr->ifa_name,
+ if_data->IFA_INCOMING,
+ if_data->IFA_OUTGOING);
+ }
+
+ freeifaddrs (if_list);
+/* #endif HAVE_GETIFADDRS */
+
+#elif KERNEL_LINUX
FILE *fh;
char buffer[1024];
unsigned long long incoming, outgoing;