* Copyright (c) 1983 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
static char sccsid
[] = "@(#)correct.c 1.2 (Berkeley) %G%";
#include <protocols/timed.h>
extern struct sockaddr_in server
;
* `correct' sends to the slaves the corrections for their clocks
struct timeval
mstotvround();
struct tsp
*answer
, *acksend();
for(i
=0; i
<slvcount
; i
++) {
if (hp
[i
].delta
== HOSTDOWN
)
fprintf(fp
, "%s\t", "down");
fprintf(fp
, "%d\t", hp
[i
].delta
);
corr
= avdelta
- hp
[0].delta
;
adjlocal
= mstotvround(&corr
);
fprintf(fp
, "%d\t", corr
);
for(i
=1; i
<slvcount
; i
++) {
if (hp
[i
].delta
!= HOSTDOWN
) {
bcopy((char *)&hp
[i
].addr
,
(char *)&(server
.sin_addr
.s_addr
),
corr
= avdelta
- hp
[i
].delta
;
msgs
.tsp_time
= mstotvround(&corr
);
msgs
.tsp_type
= (u_char
)TSP_ADJTIME
;
(void)strcpy(msgs
.tsp_name
, hostname
);
answer
= acksend(&msgs
, hp
[i
].name
, TSP_ACK
);
fprintf(fp
, "%s\t", "down");
fprintf(fp
, "%d\t", corr
);
fprintf(fp
, "%s\t", "down");
* `mstotvround' rounds up the value of the argument to the
* nearest multiple of five, and converts it into a timeval
struct timeval
mstotvround(x
)
adj
.tv_usec
= (*x
-adj
.tv_sec
*1000)*1000;
if (corr
->tv_sec
< SAMPLEINTVL
/10 &&
corr
->tv_sec
> - SAMPLEINTVL
/10) {
(void)adjtime(corr
, (struct timeval
*)0);
corr
->tv_sec
= SAMPLEINTVL
/10 - 2;
corr
->tv_sec
= - SAMPLEINTVL
/10 + 2;
(void)adjtime(corr
, (struct timeval
*)0);
syslog(LOG_WARNING
, "timed: adjclock called with too large a parameter");