From: Florian Forster Date: Sun, 6 Nov 2016 09:21:35 +0000 (+0100) Subject: modbus plugin: Avoid sizeof(struct sockaddr). X-Git-Tag: collectd-5.5.3~4^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4c92b223198c6b3d6ba0b052f1baea1d33abf31e;p=collectd.git modbus plugin: Avoid sizeof(struct sockaddr). The previous version failed on FreeBSD with: modbus.c: In function 'mb_read_data': modbus.c:476:21: error: storage size of 'sockaddr' isn't known struct sockaddr sockaddr; ^ --- diff --git a/src/modbus.c b/src/modbus.c index c04b308d..cf126b5a 100644 --- a/src/modbus.c +++ b/src/modbus.c @@ -21,13 +21,14 @@ **/ #include "collectd.h" + #include "common.h" -#include "plugin.h" #include "configfile.h" - -#include +#include "plugin.h" #include +#include +#include #ifndef LIBMODBUS_VERSION_CHECK /* Assume version 2.0.3 */ @@ -473,12 +474,9 @@ static int mb_read_data (mb_host_t *host, mb_slave_t *slave, /* {{{ */ } else if (host->conntype == MBCONN_TCP) { - struct sockaddr sockaddr; - socklen_t saddrlen = sizeof (sockaddr); - - status = getpeername (modbus_get_socket (host->connection), - &sockaddr, &saddrlen); - if (status != 0) + if (getpeername (modbus_get_socket (host->connection), + (void *) &(struct sockaddr_storage) {0}, + &(socklen_t) {sizeof(struct sockaddr_storage)}) != 0) status = errno; }