X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmodbus.c;h=5d29791d337553f6defc8a039d0050e4d647095d;hb=3ab932283678297805292ed4bbbcda36763e4608;hp=f2d07cc8149e9d06de8a94aa61465f9915e37b84;hpb=2079ee1517e34de372f58e7e2267ad5c71a8a41f;p=collectd.git diff --git a/src/modbus.c b/src/modbus.c index f2d07cc8..5d29791d 100644 --- a/src/modbus.c +++ b/src/modbus.c @@ -443,6 +443,8 @@ static int mb_read_data(mb_host_t *host, mb_slave_t *slave, /* {{{ */ if (host->connection == NULL) { status = EBADF; } else if (host->conntype == MBCONN_TCP) { + /* getpeername() is used only to determine if the socket is connected, not + * because we're really interested in the peer's IP address. */ if (getpeername(modbus_get_socket(host->connection), (void *)&(struct sockaddr_storage){0}, &(socklen_t){sizeof(struct sockaddr_storage)}) != 0) @@ -930,17 +932,16 @@ static int mb_config_add_host(oconfig_item_t *ci) /* {{{ */ } if (status == 0) { - user_data_t ud; char name[1024]; - ud.data = host; - ud.free_func = host_free; - ssnprintf(name, sizeof(name), "modbus-%s", host->host); plugin_register_complex_read(/* group = */ NULL, name, /* callback = */ mb_read, - /* interval = */ host->interval, &ud); + /* interval = */ host->interval, + &(user_data_t){ + .data = host, .free_func = host_free, + }); } else { host_free(host); }