From: Marc Fournier Date: Tue, 7 Jan 2014 15:06:10 +0000 (+0100) Subject: interface.c: FreeBSD-10 support X-Git-Tag: collectd-5.4.1~3^2^2~1 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=645dadb3fcc466e8880fda4eb23b21ad433631fc;p=collectd.git interface.c: FreeBSD-10 support Quoting @trtrmitya in github issue #506 : "[...] it is broken on FreeBSD-10, in which getifaddrs() returns not only link level stats for a particular interface, but also entries for each IP configured on that interface. As a result if_submit() is called several times for each interface, which results in incorrect data being logged. I am attaching a patch which fixes a problem on FreeBSD (9/10), but it should work for every *BSD because [...] the getifaddrs implementation first appeared in BSDi BSD/OS." Many thanks to @trtrmitya for providing the patch ! --- diff --git a/src/interface.c b/src/interface.c index db998a3f..9b566eaa 100644 --- a/src/interface.c +++ b/src/interface.c @@ -213,18 +213,19 @@ static int interface_read (void) 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; + if (if_ptr->ifa_addr != NULL && if_ptr->ifa_addr->sa_family == AF_LINK) { + if_data = (struct IFA_DATA *) if_ptr->ifa_data; - if_submit (if_ptr->ifa_name, "if_octets", + if_submit (if_ptr->ifa_name, "if_octets", if_data->IFA_RX_BYTES, if_data->IFA_TX_BYTES); - if_submit (if_ptr->ifa_name, "if_packets", + if_submit (if_ptr->ifa_name, "if_packets", if_data->IFA_RX_PACKT, if_data->IFA_TX_PACKT); - if_submit (if_ptr->ifa_name, "if_errors", + if_submit (if_ptr->ifa_name, "if_errors", if_data->IFA_RX_ERROR, if_data->IFA_TX_ERROR); + } } freeifaddrs (if_list);