Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/ntp/ntpd/ntp_io.c
Show All 35 Lines | |||||
#include "ntp_refclock.h" | #include "ntp_refclock.h" | ||||
#include "ntp_stdlib.h" | #include "ntp_stdlib.h" | ||||
#include "ntp_worker.h" | #include "ntp_worker.h" | ||||
#include "ntp_request.h" | #include "ntp_request.h" | ||||
#include "ntp_assert.h" | #include "ntp_assert.h" | ||||
#include "timevalops.h" | #include "timevalops.h" | ||||
#include "timespecops.h" | #include "timespecops.h" | ||||
#include "ntpd-opts.h" | #include "ntpd-opts.h" | ||||
#include "safecast.h" | |||||
/* Don't include ISC's version of IPv6 variables and structures */ | /* Don't include ISC's version of IPv6 variables and structures */ | ||||
#define ISC_IPV6_H 1 | #define ISC_IPV6_H 1 | ||||
#include <isc/mem.h> | #include <isc/mem.h> | ||||
#include <isc/interfaceiter.h> | #include <isc/interfaceiter.h> | ||||
#include <isc/netaddr.h> | #include <isc/netaddr.h> | ||||
#include <isc/result.h> | #include <isc/result.h> | ||||
#include <isc/sockaddr.h> | #include <isc/sockaddr.h> | ||||
▲ Show 20 Lines • Show All 715 Lines • ▼ Show 20 Lines | if (sizeof(tmpbuf) > strlen(host)) { | ||||
} else { | } else { | ||||
strlcpy(tmpbuf, host, sizeof(tmpbuf)); | strlcpy(tmpbuf, host, sizeof(tmpbuf)); | ||||
} | } | ||||
ZERO(hints); | ZERO(hints); | ||||
hints.ai_family = AF_INET6; | hints.ai_family = AF_INET6; | ||||
hints.ai_flags |= AI_NUMERICHOST; | hints.ai_flags |= AI_NUMERICHOST; | ||||
if (getaddrinfo(tmpbuf, NULL, &hints, &result) == 0) { | if (getaddrinfo(tmpbuf, NULL, &hints, &result) == 0) { | ||||
AF(addr) = AF_INET6; | AF(addr) = AF_INET6; | ||||
resaddr6 = (struct sockaddr_in6 *)result->ai_addr; | resaddr6 = UA_PTR(struct sockaddr_in6, result->ai_addr); | ||||
SET_ADDR6N(addr, resaddr6->sin6_addr); | SET_ADDR6N(addr, resaddr6->sin6_addr); | ||||
SET_SCOPE(addr, resaddr6->sin6_scope_id); | SET_SCOPE(addr, resaddr6->sin6_scope_id); | ||||
freeaddrinfo(result); | freeaddrinfo(result); | ||||
return TRUE; | return TRUE; | ||||
} | } | ||||
} | } | ||||
/* | /* | ||||
▲ Show 20 Lines • Show All 2,576 Lines • ▼ Show 20 Lines | #ifdef HAVE_BINTIME | ||||
nts.l_uf = (unsigned long)(ticks * (unsigned long)(sys_tick * FRAC)); | nts.l_uf = (unsigned long)(ticks * (unsigned long)(sys_tick * FRAC)); | ||||
} | } | ||||
DPRINTF(4, ("fetch_timestamp: system bintime network time stamp: %ld.%09lu\n", | DPRINTF(4, ("fetch_timestamp: system bintime network time stamp: %ld.%09lu\n", | ||||
btp->sec, (unsigned long)((nts.l_uf / FRAC) * 1e9))); | btp->sec, (unsigned long)((nts.l_uf / FRAC) * 1e9))); | ||||
break; | break; | ||||
#endif /* HAVE_BINTIME */ | #endif /* HAVE_BINTIME */ | ||||
#ifdef HAVE_TIMESTAMPNS | #ifdef HAVE_TIMESTAMPNS | ||||
case SCM_TIMESTAMPNS: | case SCM_TIMESTAMPNS: | ||||
tsp = (struct timespec *)CMSG_DATA(cmsghdr); | tsp = UA_PTR(struct timespec, CMSG_DATA(cmsghdr)); | ||||
if (sys_tick > measured_tick && | if (sys_tick > measured_tick && | ||||
sys_tick > 1e-9) { | sys_tick > 1e-9) { | ||||
ticks = (unsigned long)((tsp->tv_nsec * 1e-9) / | ticks = (unsigned long)((tsp->tv_nsec * 1e-9) / | ||||
sys_tick); | sys_tick); | ||||
tsp->tv_nsec = (long)(ticks * 1e9 * | tsp->tv_nsec = (long)(ticks * 1e9 * | ||||
sys_tick); | sys_tick); | ||||
} | } | ||||
DPRINTF(4, ("fetch_timestamp: system nsec network time stamp: %ld.%09ld\n", | DPRINTF(4, ("fetch_timestamp: system nsec network time stamp: %ld.%09ld\n", | ||||
▲ Show 20 Lines • Show All 284 Lines • ▼ Show 20 Lines | #endif | ||||
/* | /* | ||||
* Do a poll to see who has data | * Do a poll to see who has data | ||||
*/ | */ | ||||
fds = activefds; | fds = activefds; | ||||
tvzero.tv_sec = tvzero.tv_usec = 0; | tvzero.tv_sec = tvzero.tv_usec = 0; | ||||
n = select(maxactivefd + 1, &fds, (fd_set *)0, (fd_set *)0, | n = select(maxactivefd + 1, &fds, NULL, NULL, &tvzero); | ||||
&tvzero); | |||||
/* | /* | ||||
* If there are no packets waiting just return | * If there are no packets waiting just return | ||||
*/ | */ | ||||
if (n < 0) { | if (n < 0) { | ||||
int err = errno; | int err = errno; | ||||
int j, b, prior; | int j, b, prior; | ||||
/* | /* | ||||
▲ Show 20 Lines • Show All 763 Lines • ▼ Show 20 Lines | close_and_delete_fd_from_list( | ||||
switch (lsock->type) { | switch (lsock->type) { | ||||
case FD_TYPE_SOCKET: | case FD_TYPE_SOCKET: | ||||
closesocket(lsock->fd); | closesocket(lsock->fd); | ||||
break; | break; | ||||
case FD_TYPE_FILE: | case FD_TYPE_FILE: | ||||
closeserial(lsock->fd); | closeserial((int)lsock->fd); | ||||
break; | break; | ||||
default: | default: | ||||
msyslog(LOG_ERR, | msyslog(LOG_ERR, | ||||
"internal error - illegal descriptor type %d - EXITING", | "internal error - illegal descriptor type %d - EXITING", | ||||
(int)lsock->type); | (int)lsock->type); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 179 Lines • ▼ Show 20 Lines | if (cnt < 0) { | ||||
} | } | ||||
return; | return; | ||||
} | } | ||||
/* | /* | ||||
* process routing message | * process routing message | ||||
*/ | */ | ||||
#ifdef HAVE_RTNETLINK | #ifdef HAVE_RTNETLINK | ||||
for (nh = (struct nlmsghdr *)buffer; | for (nh = UA_PTR(struct nlmsghdr, buffer); | ||||
NLMSG_OK(nh, cnt); | NLMSG_OK(nh, cnt); | ||||
nh = NLMSG_NEXT(nh, cnt)) { | nh = NLMSG_NEXT(nh, cnt)) { | ||||
msg_type = nh->nlmsg_type; | msg_type = nh->nlmsg_type; | ||||
#else | #else | ||||
for (p = buffer; | for (p = buffer; | ||||
(p + sizeof(struct rt_msghdr)) <= (buffer + cnt); | (p + sizeof(struct rt_msghdr)) <= (buffer + cnt); | ||||
p += rtm.rtm_msglen) { | p += rtm.rtm_msglen) { | ||||
memcpy(&rtm, p, sizeof(rtm)); | memcpy(&rtm, p, sizeof(rtm)); | ||||
▲ Show 20 Lines • Show All 132 Lines • Show Last 20 Lines |