util: round up when converting to 32-bit NTP values
NTP clients shouldn't get root delay and dispersion smaller than the server's values.
This commit is contained in:
parent
6cd558398a
commit
7ffe59a734
1 changed files with 16 additions and 5 deletions
21
util.c
21
util.c
|
@ -632,11 +632,22 @@ UTI_Int32ToDouble(NTP_int32 x)
|
||||||
NTP_int32
|
NTP_int32
|
||||||
UTI_DoubleToInt32(double x)
|
UTI_DoubleToInt32(double x)
|
||||||
{
|
{
|
||||||
if (x > MAX_NTP_INT32)
|
NTP_int32 r;
|
||||||
x = MAX_NTP_INT32;
|
|
||||||
else if (x < 0)
|
if (x >= MAX_NTP_INT32) {
|
||||||
x = 0.0;
|
r = 0xffffffff;
|
||||||
return htonl((NTP_int32)(0.5 + 65536.0 * x));
|
} else if (x <= 0.0) {
|
||||||
|
r = 0;
|
||||||
|
} else {
|
||||||
|
x *= 65536.0;
|
||||||
|
r = x;
|
||||||
|
|
||||||
|
/* Round up */
|
||||||
|
if (r < x)
|
||||||
|
r++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return htonl(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
Loading…
Reference in a new issue