X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fntpd.c;h=a0093655e4066493cae5f0c3f5533b5ececb705f;hb=141816828389e3ad98f66db29b4a702479dcb05d;hp=f7b57ba30ce30ecc3c7826f879d2d4bb99629028;hpb=3fae5596643f1e361eb18c3d65448f8bc02fdd80;p=collectd.git diff --git a/src/ntpd.c b/src/ntpd.c index f7b57ba3..a0093655 100644 --- a/src/ntpd.c +++ b/src/ntpd.c @@ -28,6 +28,7 @@ #define _BSD_SOURCE /* For NI_MAXHOST */ #include "collectd.h" + #include "common.h" #include "plugin.h" #include "configfile.h" @@ -346,9 +347,7 @@ static int ntpd_connect (void) const char *host; const char *port; - struct addrinfo ai_hints = { 0 }; struct addrinfo *ai_list; - struct addrinfo *ai_ptr; int status; if (sock_descr >= 0) @@ -364,12 +363,12 @@ static int ntpd_connect (void) if (strlen (port) == 0) port = NTPD_DEFAULT_PORT; -#ifdef AI_ADDRCONFIG - ai_hints.ai_flags |= AI_ADDRCONFIG; -#endif - ai_hints.ai_family = PF_UNSPEC; - ai_hints.ai_socktype = SOCK_DGRAM; - ai_hints.ai_protocol = IPPROTO_UDP; + struct addrinfo ai_hints = { + .ai_family = AF_UNSPEC, + .ai_flags = AI_ADDRCONFIG, + .ai_protocol = IPPROTO_UDP, + .ai_socktype = SOCK_DGRAM + }; if ((status = getaddrinfo (host, port, &ai_hints, &ai_list)) != 0) { @@ -382,7 +381,7 @@ static int ntpd_connect (void) return (-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 ((sock_descr = socket (ai_ptr->ai_family, @@ -420,7 +419,6 @@ static int ntpd_receive_response (int *res_items, int *res_size, struct resp_pkt res; int status; int done; - int i; char *items; size_t items_num; @@ -674,7 +672,7 @@ static int ntpd_receive_response (int *res_items, int *res_size, items_num += pkt_item_num; *res_data = items; - for (i = 0; i < pkt_item_num; i++) + for (int i = 0; i < pkt_item_num; i++) { /* dst: There are already `*res_items' items with * res_item_size bytes each in in `*res_data'. Set @@ -903,7 +901,6 @@ static int ntpd_read (void) gauge_t offset_error; int status; - int i; /* On Linux, if the STA_NANO bit is set in ik->status, then ik->offset * is is nanoseconds, otherwise it's microseconds. */ @@ -971,7 +968,7 @@ static int ntpd_read (void) return (-1); } - for (i = 0; i < ps_num; i++) + for (int i = 0; i < ps_num; i++) { struct info_peer_summary *ptr; double offset;