X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmbmon.c;h=184bb9942a7b32f62c2a74a56499b6b1e1a87166;hb=448627953cde2f7b3b138f53f4f2c62f0d48b726;hp=d23062db2d54734551789c76cac837c9915c43f2;hpb=f14feb1eddfe5760a64640b98ab7bbc5c493f614;p=collectd.git diff --git a/src/mbmon.c b/src/mbmon.c index d23062db..184bb994 100644 --- a/src/mbmon.c +++ b/src/mbmon.c @@ -24,12 +24,12 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" #include "configfile.h" #include -#include #include #include @@ -85,19 +85,9 @@ static int mbmon_query_daemon (char *buffer, int buffer_size) const char *host; const char *port; - struct addrinfo ai_hints; - struct addrinfo *ai_list, *ai_ptr; + struct addrinfo *ai_list; int ai_return; - memset (&ai_hints, '\0', sizeof (ai_hints)); - ai_hints.ai_flags = 0; -#ifdef AI_ADDRCONFIG - ai_hints.ai_flags |= AI_ADDRCONFIG; -#endif - ai_hints.ai_family = PF_UNSPEC; - ai_hints.ai_socktype = SOCK_STREAM; - ai_hints.ai_protocol = IPPROTO_TCP; - host = mbmon_host; if (host == NULL) host = MBMON_DEF_HOST; @@ -106,6 +96,13 @@ static int mbmon_query_daemon (char *buffer, int buffer_size) if (port == NULL) port = MBMON_DEF_PORT; + struct addrinfo ai_hints = { + .ai_family = AF_UNSPEC, + .ai_flags = AI_ADDRCONFIG, + .ai_protocol = IPPROTO_TCP, + .ai_socktype = SOCK_STREAM + }; + if ((ai_return = getaddrinfo (host, port, &ai_hints, &ai_list)) != 0) { char errbuf[1024]; @@ -118,7 +115,7 @@ static int mbmon_query_daemon (char *buffer, int buffer_size) } fd = -1; - for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) + for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { /* create our socket descriptor */ if ((fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol)) < 0) @@ -240,9 +237,7 @@ static void mbmon_submit (const char *type, const char *type_instance, /* Trim trailing whitespace from a string. */ static void trim_spaces (char *s) { - size_t l; - - for (l = strlen (s) - 1; (l > 0) && isspace ((int) s[l]); l--) + for (size_t l = strlen (s) - 1; (l > 0) && isspace ((int) s[l]); l--) s[l] = '\0'; } @@ -261,8 +256,8 @@ static int mbmon_read (void) double value; char *nextc; - char *type; - char *inst; + const char *type; + const char *inst; *t++ = '\0'; trim_spaces (s);