#include "common.h"
#include "plugin.h"
-#if HAVE_STDINT_H
-#include <stdint.h>
-#endif
#if HAVE_NETDB_H
#include <netdb.h>
#endif
if (ntpd_host != NULL)
free(ntpd_host);
if ((ntpd_host = strdup(value)) == NULL)
- return (1);
+ return 1;
} else if (strcasecmp(key, "Port") == 0) {
int port = (int)(atof(value));
if ((port > 0) && (port <= 65535))
- ssnprintf(ntpd_port, sizeof(ntpd_port), "%i", port);
+ snprintf(ntpd_port, sizeof(ntpd_port), "%i", port);
else
sstrncpy(ntpd_port, value, sizeof(ntpd_port));
} else if (strcasecmp(key, "ReverseLookups") == 0) {
else
include_unit_id = 0;
} else {
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
}
static void ntpd_submit(const char *type, const char *type_inst,
int status;
if (sock_descr >= 0)
- return (sock_descr);
+ return sock_descr;
DEBUG("Opening a new socket");
ERROR("ntpd plugin: getaddrinfo (%s, %s): %s", host, port,
(status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
: gai_strerror(status));
- return (-1);
+ return -1;
}
for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL;
ERROR("ntpd plugin: Unable to connect to server.");
}
- return (sock_descr);
+ return sock_descr;
}
/* For a description of the arguments see `ntpd_do_query' below. */
ssize_t pkt_padding; /* Padding in this packet */
if ((sd = ntpd_connect()) < 0)
- return (-1);
+ return -1;
items = NULL;
items_num = 0;
char errbuf[1024];
ERROR("ntpd plugin: gettimeofday failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
- return (-1);
+ return -1;
}
time_end.tv_sec++; /* wait for a most one second */
char errbuf[1024];
ERROR("ntpd plugin: gettimeofday failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
- return (-1);
+ return -1;
}
if (timeval_cmp(time_end, time_now, &time_left) <= 0)
char errbuf[1024];
ERROR("ntpd plugin: poll failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
- return (-1);
+ return -1;
}
if (status == 0) /* timeout */
DEBUG("Closing socket #%i", sd);
close(sd);
sock_descr = sd = -1;
- return (-1);
+ return -1;
}
DEBUG("recv'd %i bytes", status);
if (INFO_ERR(res.err_nitems) != 0) {
ERROR("ntpd plugin: Received error code %i",
(int)INFO_ERR(res.err_nitems));
- return ((int)INFO_ERR(res.err_nitems));
+ return (int)INFO_ERR(res.err_nitems);
}
/* extract number of items in this packet and the size of these items */
done = 1;
} /* while (done == 0) */
- return (0);
+ return 0;
} /* int ntpd_receive_response */
/* For a description of the arguments see `ntpd_do_query' below. */
assert(req_size >= 0);
if ((sd = ntpd_connect()) < 0)
- return (-1);
+ return -1;
req.rm_vn_mode = RM_VN_MODE(0, 0, 0);
req.auth_seq = AUTH_SEQ(0, 0);
DEBUG("`swrite' failed. Closing socket #%i", sd);
close(sd);
sock_descr = sd = -1;
- return (status);
+ return status;
}
- return (0);
+ return 0;
}
/*
status = ntpd_send_request(req_code, req_items, req_size, req_data);
if (status != 0)
- return (status);
+ return status;
status = ntpd_receive_response(res_items, res_size, res_data, res_item_size);
- return (status);
+ return status;
}
static double ntpd_read_fp(int32_t val_int) {
val_int = ntohl(val_int);
val_double = ((double)val_int) / FP_FRAC;
- return (val_double);
+ return val_double;
}
static uint32_t
uint32_t addr = ntohl(peer_info->srcadr);
uint32_t refclock_id = (addr >> 8) & 0x00FF;
- return (refclock_id);
+ return refclock_id;
}
static int ntpd_get_name_from_address(char *buffer, size_t buffer_size,
ERROR("ntpd plugin: getnameinfo failed: %s",
(status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
: gai_strerror(status));
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
} /* ntpd_get_name_from_address */
static int ntpd_get_name_refclock(char *buffer, size_t buffer_size,
uint32_t unit_id = ntohl(peer_info->srcadr) & 0x00FF;
if (((size_t)refclock_id) >= refclock_names_num)
- return (ntpd_get_name_from_address(buffer, buffer_size, peer_info,
- /* do_reverse_lookup = */ 0));
+ return ntpd_get_name_from_address(buffer, buffer_size, peer_info, 0);
if (include_unit_id)
- ssnprintf(buffer, buffer_size, "%s-%" PRIu32, refclock_names[refclock_id],
- unit_id);
+ snprintf(buffer, buffer_size, "%s-%" PRIu32, refclock_names[refclock_id],
+ unit_id);
else
sstrncpy(buffer, refclock_names[refclock_id], buffer_size);
- return (0);
+ return 0;
} /* int ntpd_get_name_refclock */
static int ntpd_get_name(char *buffer, size_t buffer_size,
uint32_t addr = ntohl(peer_info->srcadr);
if (!peer_info->v6_flag && ((addr & REFCLOCK_MASK) == REFCLOCK_ADDR))
- return (ntpd_get_name_refclock(buffer, buffer_size, peer_info));
+ return ntpd_get_name_refclock(buffer, buffer_size, peer_info);
else
- return (ntpd_get_name_from_address(buffer, buffer_size, peer_info,
- do_reverse_lookups));
+ return ntpd_get_name_from_address(buffer, buffer_size, peer_info,
+ do_reverse_lookups);
} /* int ntpd_addr_to_name */
static int ntpd_read(void) {
if (status != 0) {
ERROR("ntpd plugin: ntpd_do_query (REQ_GET_KERNEL) failed with status %i",
status);
- return (status);
+ return status;
} else if ((ik == NULL) || (ik_num == 0) || (ik_size == 0)) {
ERROR("ntpd plugin: ntpd_do_query returned unexpected data. "
"(ik = %p; ik_num = %i; ik_size = %i)",
(void *)ik, ik_num, ik_size);
- return (-1);
+ return -1;
}
if (ntohs(ik->status) & STA_NANO) {
}
/* kerninfo -> estimated error */
- offset_loop = scale_loop * ((gauge_t)ntohl(ik->offset));
+ offset_loop = (gauge_t)((int32_t)ntohl(ik->offset) * scale_loop);
freq_loop = ntpd_read_fp(ik->freq);
- offset_error = scale_error * ((gauge_t)ntohl(ik->esterror));
+ offset_error = (gauge_t)((int32_t)ntohl(ik->esterror) * scale_error);
DEBUG("info_kernel:\n"
" pll offset = %.8g\n"
ERROR(
"ntpd plugin: ntpd_do_query (REQ_PEER_LIST_SUM) failed with status %i",
status);
- return (status);
+ return status;
} else if ((ps == NULL) || (ps_num == 0) || (ps_size == 0)) {
ERROR("ntpd plugin: ntpd_do_query returned unexpected data. "
"(ps = %p; ps_num = %i; ps_size = %i)",
(void *)ps, ps_num, ps_size);
- return (-1);
+ return -1;
}
for (int i = 0; i < ps_num; i++) {
free(ps);
ps = NULL;
- return (0);
+ return 0;
} /* int ntpd_read */
void module_register(void) {