diff options
author | delphij <delphij@FreeBSD.org> | 2015-07-15 19:21:26 +0000 |
---|---|---|
committer | delphij <delphij@FreeBSD.org> | 2015-07-15 19:21:26 +0000 |
commit | 2a25cee78ab1d37e7d2bc40ae675646974d99f56 (patch) | |
tree | b0302ac4be59e104f4e1e54014561a1389397192 /contrib/ntp/libntp/refidsmear.c | |
parent | a0741a75537b2e0514472ac3b28afc55a7846c30 (diff) | |
download | FreeBSD-src-2a25cee78ab1d37e7d2bc40ae675646974d99f56.zip FreeBSD-src-2a25cee78ab1d37e7d2bc40ae675646974d99f56.tar.gz |
MFC r280849,280915-280916,281015-281016,282097,282408,282415,283542,
284864,285169-285170,285435:
ntp 4.2.8p3.
Relnotes: yes
Approved by: re (?)
Diffstat (limited to 'contrib/ntp/libntp/refidsmear.c')
-rw-r--r-- | contrib/ntp/libntp/refidsmear.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/contrib/ntp/libntp/refidsmear.c b/contrib/ntp/libntp/refidsmear.c new file mode 100644 index 0000000..fef428e --- /dev/null +++ b/contrib/ntp/libntp/refidsmear.c @@ -0,0 +1,58 @@ +#include <config.h> + +#include <ntp.h> +#include <ntp_fp.h> +#include <refidsmear.h> + +/* + * we want to test a refid format of: + * 254.x.y.x + * + * where x.y.z are 24 bits containing 2 (signed) integer bits + * and 22 fractional bits. + * + */ + + +l_fp +convertRefIDToLFP(uint32_t r) +{ + l_fp temp; + + r = ntohl(r); + + // printf("%03d %08x: ", (r >> 24) & 0xFF, (r & 0x00FFFFFF) ); + + temp.l_uf = (r << 10); /* 22 fractional bits */ + + temp.l_ui = (r >> 22) & 0x3; + temp.l_ui |= ~(temp.l_ui & 2) + 1; + + return temp; +} + + +uint32_t +convertLFPToRefID(l_fp num) +{ + uint32_t temp; + + /* round the input with the highest bit to shift out from the + * fraction, then keep just two bits from the integral part. + * + * TODO: check for overflows; should we clamp/saturate or just + * complain? + */ + L_ADDUF(&num, 0x200); + num.l_ui &= 3; + + /* combine integral and fractional part to 24 bits */ + temp = (num.l_ui << 22) | (num.l_uf >> 10); + + /* put in the leading 254.0.0.0 */ + temp |= UINT32_C(0xFE000000); + + // printf("%03d %08x: ", (temp >> 24) & 0xFF, (temp & 0x00FFFFFF) ); + + return htonl(temp); +} |