#! /bin/sh /usr/share/dpatch/dpatch-run ## getifaddrs.dpatch by Sebastian Harl ## ## All lines beginning with `## DP:' are a description of the patch. ## DP: Read traffic information from /proc by default instead of using ## DP: getifaddrs(). getifaddrs() does not seem to work correctly on AMD64. @DPATCH@ diff -urN collectd-3.9.2.orig/src/traffic.c collectd-3.9.2/src/traffic.c --- collectd-3.9.2.orig/src/traffic.c 2006-05-09 11:10:34.000000000 +0200 +++ collectd-3.9.2/src/traffic.c 2006-06-02 16:12:28.000000000 +0200 @@ -143,41 +143,7 @@ static void traffic_read (void) { -#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 +#if KERNEL_LINUX FILE *fh; char buffer[1024]; unsigned long long incoming, outgoing; @@ -221,6 +187,40 @@ fclose (fh); /* #endif KERNEL_LINUX */ +#elif 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 defined(HAVE_LIBKSTAT) int i; unsigned long long incoming, outgoing;