X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Folsrd.c;h=0af32dc18bfb2f9cec29be73d4f8d214befeec9d;hb=6fd0d2574fc386c2724c8307d33b12529b30048b;hp=bbf387f4123dfe12a375ca85b234fd315843e385;hpb=029e88709f60d90fede55ed31f775602c1487d24;p=collectd.git diff --git a/src/olsrd.c b/src/olsrd.c index bbf387f4..0af32dc1 100644 --- a/src/olsrd.c +++ b/src/olsrd.c @@ -25,6 +25,7 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" @@ -149,22 +150,18 @@ static size_t strtabsplit (char *string, char **fields, size_t size) /* {{{ */ static FILE *olsrd_connect (void) /* {{{ */ { - struct addrinfo ai_hints; struct addrinfo *ai_list, *ai_ptr; int ai_return; FILE *fh; - 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; + struct addrinfo ai_hints = { + .ai_family = AF_UNSPEC, + .ai_flags = AI_ADDRCONFIG, + .ai_protocol = IPPROTO_TCP, + .ai_socktype = SOCK_STREAM + }; - ai_list = NULL; ai_return = getaddrinfo (olsrd_get_node (), olsrd_get_service (), &ai_hints, &ai_list); if (ai_return != 0) @@ -557,9 +554,8 @@ static int olsrd_cb_topology (int lineno, /* {{{ */ if (config_want_topology == OLSRD_WANT_DETAIL) { - char type_instance[DATA_MAX_NAME_LEN]; + char type_instance[DATA_MAX_NAME_LEN] = { 0 }; - memset (type_instance, 0, sizeof (type_instance)); ssnprintf (type_instance, sizeof (type_instance), "%s-%s-lq", fields[0], fields[1]); DEBUG ("olsrd plugin: type_instance = %s; lq = %g;", type_instance, lq); @@ -581,9 +577,8 @@ static int olsrd_cb_topology (int lineno, /* {{{ */ } else { - char type_instance[DATA_MAX_NAME_LEN]; + char type_instance[DATA_MAX_NAME_LEN] = { 0 }; - memset (type_instance, 0, sizeof (type_instance)); ssnprintf (type_instance, sizeof (type_instance), "%s-%s-nlq", fields[0], fields[1]); DEBUG ("olsrd plugin: type_instance = %s; nlq = %g;", type_instance, nlq); @@ -611,7 +606,7 @@ static int olsrd_read_table (FILE *fh, /* {{{ */ { /* An empty line ends the table. */ buffer_len = strchomp (buffer); - if (buffer_len <= 0) + if (buffer_len == 0) { (*callback) (lineno, /* fields_num = */ 0, /* fields = */ NULL); break; @@ -622,7 +617,7 @@ static int olsrd_read_table (FILE *fh, /* {{{ */ (*callback) (lineno, fields_num, fields); lineno++; } /* while (fgets) */ - + return (0); } /* }}} int olsrd_read_table */ @@ -663,9 +658,9 @@ static int olsrd_read (void) /* {{{ */ while (fgets (buffer, sizeof (buffer), fh) != NULL) { buffer_len = strchomp (buffer); - if (buffer_len <= 0) + if (buffer_len == 0) continue; - + if (strcmp ("Table: Links", buffer) == 0) olsrd_read_table (fh, olsrd_cb_links); else if (strcmp ("Table: Neighbors", buffer) == 0) @@ -690,7 +685,7 @@ static int olsrd_read (void) /* {{{ */ } /* while (fgets) */ fclose (fh); - + return (0); } /* }}} int olsrd_read */