X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fntpd.c;h=1071d0b34544aa773017f483381f69333f239234;hb=95dcf60c822e4ab92c0dd1a7ff6cba73bc55bcd1;hp=67fff22a82e026f2b75e5785ddd7904dd8983818;hpb=60451f81f174fc283345ade43d95857c56d17e88;p=collectd.git diff --git a/src/ntpd.c b/src/ntpd.c index 67fff22a..1071d0b3 100644 --- a/src/ntpd.c +++ b/src/ntpd.c @@ -2,18 +2,23 @@ * collectd - src/ntpd.c * Copyright (C) 2006-2012 Florian octo Forster * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; only version 2 of the License is applicable. + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. * * Authors: * Florian octo Forster @@ -33,9 +38,6 @@ #if HAVE_NETDB_H # include #endif -#if HAVE_SYS_SOCKET_H -# include -#endif #if HAVE_NETINET_IN_H # include #endif @@ -245,7 +247,7 @@ struct info_kernel }; /* List of reference clock names */ -static char *refclock_names[] = +static const char *refclock_names[] = { "UNKNOWN", "LOCAL", "GPS_TRAK", "WWV_PST", /* 0- 3 */ "SPECTRACOM", "TRUETIME", "IRIG_AUDIO", "CHU_AUDIO", /* 4- 7 */ @@ -260,7 +262,7 @@ static char *refclock_names[] = "JJY", "TT_IRIG", "GPS_ZYFER", "GPS_RIPENCC", /* 40-43 */ "NEOCLK4X" /* 44 */ }; -static int refclock_names_num = STATIC_ARRAY_SIZE (refclock_names); +static size_t refclock_names_num = STATIC_ARRAY_SIZE (refclock_names); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * End of the copied stuff.. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ @@ -305,7 +307,7 @@ static int ntpd_config (const char *key, const char *value) return (0); } -static void ntpd_submit (char *type, char *type_inst, gauge_t value) +static void ntpd_submit (const char *type, const char *type_inst, gauge_t value) { value_t values[1]; value_list_t vl = VALUE_LIST_INIT; @@ -326,8 +328,8 @@ static void ntpd_submit (char *type, char *type_inst, gauge_t value) /* Each time a peer is polled, ntpd shifts the reach register to the left and * sets the LSB based on whether the peer was reachable. If the LSB is zero, * the values are out of date. */ -static void ntpd_submit_reach (char *type, char *type_inst, uint8_t reach, - gauge_t value) +static void ntpd_submit_reach (const char *type, const char *type_inst, + uint8_t reach, gauge_t value) { if (!(reach & 1)) value = NAN; @@ -337,8 +339,8 @@ static void ntpd_submit_reach (char *type, char *type_inst, uint8_t reach, static int ntpd_connect (void) { - char *host; - char *port; + const char *host; + const char *port; struct addrinfo ai_hints; struct addrinfo *ai_list; @@ -661,7 +663,7 @@ static int ntpd_receive_response (int *res_items, int *res_size, */ DEBUG ("realloc (%p, %zu)", (void *) *res_data, (items_num + pkt_item_num) * res_item_size); - items = realloc ((void *) *res_data, + items = realloc (*res_data, (items_num + pkt_item_num) * res_item_size); if (items == NULL) { @@ -863,7 +865,7 @@ static int ntpd_get_name_refclock (char *buffer, size_t buffer_size, uint32_t refclock_id = ntpd_get_refclock_id (peer_info); uint32_t unit_id = ntohl (peer_info->srcadr) & 0x00FF; - if (refclock_id >= refclock_names_num) + if (((size_t) refclock_id) >= refclock_names_num) return (ntpd_get_name_from_address (buffer, buffer_size, peer_info, /* do_reverse_lookup = */ 0));