From 4c92b223198c6b3d6ba0b052f1baea1d33abf31e Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sun, 6 Nov 2016 10:21:35 +0100 Subject: [PATCH] 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; ^ --- src/modbus.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) 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; } -- 2.30.2