Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/ntp/ntpdate/ntpdate.c
Show First 20 Lines • Show All 555 Lines • ▼ Show 20 Lines | #endif | ||||
if (!was_alarmed && tot_recvbufs == 0) { | if (!was_alarmed && tot_recvbufs == 0) { | ||||
/* | /* | ||||
* Nothing to do. Wait for something. | * Nothing to do. Wait for something. | ||||
*/ | */ | ||||
#ifdef HAVE_POLL_H | #ifdef HAVE_POLL_H | ||||
nfound = poll(rdfdes, (unsigned int)nbsock, timeout.tv_sec * 1000); | nfound = poll(rdfdes, (unsigned int)nbsock, timeout.tv_sec * 1000); | ||||
#else | #else | ||||
nfound = select(maxfd, &rdfdes, (fd_set *)0, | nfound = select(maxfd, &rdfdes, NULL, NULL, | ||||
(fd_set *)0, &timeout); | &timeout); | ||||
#endif | #endif | ||||
if (nfound > 0) | if (nfound > 0) | ||||
input_handler(); | input_handler(); | ||||
else if (nfound == SOCKET_ERROR) | else if (nfound == SOCKET_ERROR) | ||||
{ | { | ||||
#ifndef SYS_WINNT | #ifndef SYS_WINNT | ||||
if (errno != EINTR) | if (errno != EINTR) | ||||
#else | #else | ||||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | transmit( | ||||
L_CLR(&xpkt.rec); | L_CLR(&xpkt.rec); | ||||
/* | /* | ||||
* Determine whether to authenticate or not. If so, | * Determine whether to authenticate or not. If so, | ||||
* fill in the extended part of the packet and do it. | * fill in the extended part of the packet and do it. | ||||
* If not, just timestamp it and send it away. | * If not, just timestamp it and send it away. | ||||
*/ | */ | ||||
if (sys_authenticate) { | if (sys_authenticate) { | ||||
int len; | size_t len; | ||||
xpkt.exten[0] = htonl(sys_authkey); | xpkt.exten[0] = htonl(sys_authkey); | ||||
get_systime(&server->xmt); | get_systime(&server->xmt); | ||||
L_ADDUF(&server->xmt, sys_authdelay); | L_ADDUF(&server->xmt, sys_authdelay); | ||||
HTONL_FP(&server->xmt, &xpkt.xmt); | HTONL_FP(&server->xmt, &xpkt.xmt); | ||||
len = authencrypt(sys_authkey, (u_int32 *)&xpkt, LEN_PKT_NOMAC); | len = authencrypt(sys_authkey, (u_int32 *)&xpkt, LEN_PKT_NOMAC); | ||||
sendpkt(&server->srcadr, &xpkt, (int)(LEN_PKT_NOMAC + len)); | sendpkt(&server->srcadr, &xpkt, (int)(LEN_PKT_NOMAC + len)); | ||||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | if (!sys_authenticate) | ||||
is_authentic = 1; | is_authentic = 1; | ||||
else { | else { | ||||
is_authentic = 0; | is_authentic = 0; | ||||
if (debug > 3) | if (debug > 3) | ||||
printf("receive: rpkt keyid=%ld sys_authkey=%ld decrypt=%ld\n", | printf("receive: rpkt keyid=%ld sys_authkey=%ld decrypt=%ld\n", | ||||
(long int)ntohl(rpkt->exten[0]), (long int)sys_authkey, | (long int)ntohl(rpkt->exten[0]), (long int)sys_authkey, | ||||
(long int)authdecrypt(sys_authkey, (u_int32 *)rpkt, | (long int)authdecrypt(sys_authkey, (u_int32 *)rpkt, | ||||
LEN_PKT_NOMAC, (int)(rbufp->recv_length - LEN_PKT_NOMAC))); | LEN_PKT_NOMAC, (size_t)(rbufp->recv_length - LEN_PKT_NOMAC))); | ||||
if (has_mac && ntohl(rpkt->exten[0]) == sys_authkey && | if (has_mac && ntohl(rpkt->exten[0]) == sys_authkey && | ||||
authdecrypt(sys_authkey, (u_int32 *)rpkt, LEN_PKT_NOMAC, | authdecrypt(sys_authkey, (u_int32 *)rpkt, LEN_PKT_NOMAC, | ||||
(int)(rbufp->recv_length - LEN_PKT_NOMAC))) | (size_t)(rbufp->recv_length - LEN_PKT_NOMAC))) | ||||
is_authentic = 1; | is_authentic = 1; | ||||
if (debug) | if (debug) | ||||
printf("receive: authentication %s\n", | printf("receive: authentication %s\n", | ||||
is_authentic ? "passed" : "failed"); | is_authentic ? "passed" : "failed"); | ||||
} | } | ||||
server->trust <<= 1; | server->trust <<= 1; | ||||
if (!is_authentic) | if (!is_authentic) | ||||
server->trust |= 1; | server->trust |= 1; | ||||
▲ Show 20 Lines • Show All 1,059 Lines • ▼ Show 20 Lines | input_handler(void) | ||||
GETSOCKNAME_SOCKLEN_TYPE fromlen; | GETSOCKNAME_SOCKLEN_TYPE fromlen; | ||||
l_fp ts; | l_fp ts; | ||||
int i; | int i; | ||||
#ifdef HAVE_POLL_H | #ifdef HAVE_POLL_H | ||||
struct pollfd fds[MAX_AF]; | struct pollfd fds[MAX_AF]; | ||||
#else | #else | ||||
fd_set fds; | fd_set fds; | ||||
#endif | #endif | ||||
int fdc = 0; | SOCKET fdc = 0; | ||||
/* | /* | ||||
* Do a poll to see if we have data | * Do a poll to see if we have data | ||||
*/ | */ | ||||
for (;;) { | for (;;) { | ||||
tvzero.tv_sec = tvzero.tv_usec = 0; | tvzero.tv_sec = tvzero.tv_usec = 0; | ||||
#ifdef HAVE_POLL_H | #ifdef HAVE_POLL_H | ||||
memcpy(fds, fdmask, sizeof(fdmask)); | memcpy(fds, fdmask, sizeof(fdmask)); | ||||
n = poll(fds, (unsigned int)nbsock, tvzero.tv_sec * 1000); | n = poll(fds, (unsigned int)nbsock, tvzero.tv_sec * 1000); | ||||
/* | /* | ||||
* Determine which socket received data | * Determine which socket received data | ||||
*/ | */ | ||||
for(i=0; i < nbsock; i++) { | for(i=0; i < nbsock; i++) { | ||||
if(fds[i].revents & POLLIN) { | if(fds[i].revents & POLLIN) { | ||||
fdc = fd[i]; | fdc = fd[i]; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
#else | #else | ||||
fds = fdmask; | fds = fdmask; | ||||
n = select(maxfd, &fds, (fd_set *)0, (fd_set *)0, &tvzero); | n = select(maxfd, &fds, NULL, NULL, &tvzero); | ||||
/* | /* | ||||
* Determine which socket received data | * Determine which socket received data | ||||
*/ | */ | ||||
for(i=0; i < nbsock; i++) { | for(i=0; i < nbsock; i++) { | ||||
if(FD_ISSET(fd[i], &fds)) { | if(FD_ISSET(fd[i], &fds)) { | ||||
fdc = fd[i]; | fdc = fd[i]; | ||||
▲ Show 20 Lines • Show All 323 Lines • Show Last 20 Lines |