003 File Manager
Current Path:
/usr/src/contrib/ntp/libntp
usr
/
src
/
contrib
/
ntp
/
libntp
/
📁
..
📄
Makefile.am
(3.27 KB)
📄
Makefile.in
(105.83 KB)
📄
README
(272 B)
📄
a_md5encrypt.c
(6.76 KB)
📄
adjtime.c
(10.29 KB)
📄
adjtimex.c
(334 B)
📄
atoint.c
(801 B)
📄
atolfp.c
(1.88 KB)
📄
atouint.c
(885 B)
📄
audio.c
(13.09 KB)
📄
authkeys.c
(19.92 KB)
📄
authreadkeys.c
(9.06 KB)
📄
authusekey.c
(748 B)
📄
bsd_strerror.c
(1.35 KB)
📄
buftvtots.c
(643 B)
📄
caljulian.c
(891 B)
📄
caltontp.c
(2.25 KB)
📄
calyearstart.c
(2.1 KB)
📄
clocktime.c
(4.49 KB)
📄
clocktypes.c
(3.69 KB)
📄
decodenetnum.c
(3.93 KB)
📄
dofptoa.c
(2.19 KB)
📄
dolfptoa.c
(3.14 KB)
📄
emalloc.c
(3.4 KB)
📄
findconfig.c
(1.46 KB)
📄
getopt.c
(2.21 KB)
📄
hextoint.c
(673 B)
📄
hextolfp.c
(1.35 KB)
📄
humandate.c
(1.1 KB)
📄
icom.c
(4.22 KB)
📄
iosignal.c
(12.27 KB)
📄
is_ip_address.c
(2.02 KB)
📄
lib_strbuf.c
(633 B)
📄
libssl_compat.c
(6.13 KB)
📄
machines.c
(13.05 KB)
📄
mktime.c
(8.29 KB)
📄
modetoa.c
(507 B)
📄
mstolfp.c
(2.01 KB)
📄
msyslog.c
(12.67 KB)
📄
netof.c
(1.17 KB)
📄
ntp_calendar.c
(58.49 KB)
📄
ntp_calgps.c
(15.73 KB)
📄
ntp_crypto_rnd.c
(2.11 KB)
📄
ntp_intres.c
(28.64 KB)
📄
ntp_libopts.c
(1.27 KB)
📄
ntp_lineedit.c
(3.88 KB)
📄
ntp_random.c
(17.63 KB)
📄
ntp_rfc2553.c
(14.85 KB)
📄
ntp_worker.c
(7.21 KB)
📄
numtoa.c
(963 B)
📄
numtohost.c
(908 B)
📄
octtoint.c
(578 B)
📄
prettydate.c
(5.53 KB)
📄
recvbuff.c
(7.3 KB)
📄
refidsmear.c
(1.05 KB)
📄
refnumtoa.c
(673 B)
📄
snprintf.c
(52.56 KB)
📄
socket.c
(4.88 KB)
📄
socktoa.c
(2.88 KB)
📄
socktohost.c
(2.54 KB)
📄
ssl_init.c
(5.09 KB)
📄
statestr.c
(11.4 KB)
📄
strdup.c
(854 B)
📄
strl_obsd.c
(3.65 KB)
📄
syssignal.c
(2.69 KB)
📄
systime.c
(17.51 KB)
📄
systime_s.c
(33 B)
📄
timespecops.c
(4.27 KB)
📄
timetoa.c
(2.75 KB)
📄
timevalops.c
(12.97 KB)
📄
timexsup.c
(1.17 KB)
📄
uglydate.c
(958 B)
📄
vint64ops.c
(5.1 KB)
📄
work_fork.c
(12.73 KB)
📄
work_thread.c
(22.88 KB)
📄
xsbprintf.c
(2.06 KB)
📄
ymd2yd.c
(582 B)
Editing: clocktime.c
/* * clocktime - compute the NTP date from a day of year, hour, minute * and second. */ #include <config.h> #include "ntp_fp.h" #include "ntp_unixtime.h" #include "ntp_stdlib.h" #include "ntp_calendar.h" /* * We check that the time be within CLOSETIME seconds of the receive * time stamp. This is about 4 hours, which hopefully should be wide * enough to collect most data, while close enough to keep things from * getting confused. */ #define CLOSETIME (4u*60u*60u) /* * Since we try to match years, the result of a full search will not * change when we are already less than a half year from the receive * time stamp. Since the length of a year is variable we use a * slightly narrower limit; this might require a full evaluation near * the edge, but will make sure we always get the correct result. */ #define NEARTIME (182u * SECSPERDAY) /* * local calendar helpers */ static int32 ntp_to_year(u_int32); static u_int32 year_to_ntp(int32); /* * Take a time spec given as day-of-year, hour, minute and second as * well as a GMT offset in hours and convert it to a NTP time stamp in * '*ts_ui'. The value will be in the range (rec_ui-0.5yrs) to * (rec_ui+0.5yrs). A hint for the current start-of-year will be * read from '*yearstart'. * * On return '*ts_ui' will always the best matching solution, and * '*yearstart' will receive the associated start-of-year. * * The function will tell if the result in 'ts_ui' is in CLOSETIME * (+/-4hrs) around the receive time by returning a non-zero value. * * Note: The function puts no constraints on the value ranges for the * time specification, but evaluates the effective seconds in * 32-bit arithmetic. */ int clocktime( int yday , /* day-of-year */ int hour , /* hour of day */ int minute , /* minute of hour */ int second , /* second of minute */ int tzoff , /* hours west of GMT */ u_int32 rec_ui , /* pivot value */ u_long *yearstart, /* cached start-of-year, should be fixed to u_int32 */ u_int32 *ts_ui ) /* effective time stamp */ { u_int32 ystt[3]; /* year start */ u_int32 test[3]; /* result time stamp */ u_int32 diff[3]; /* abs difference to receive */ int32 y, tmp, idx, min; /* * Compute the offset into the year in seconds. Note that * this could come out to be a negative number. */ tmp = ((int32)second + SECSPERMIN * ((int32)minute + MINSPERHR * ((int32)hour + (int32)tzoff + HRSPERDAY * ((int32)yday - 1)))); /* * Based on the cached year start, do a first attempt. Be * happy and return if this gets us better than NEARTIME to * the receive time stamp. Do this only if the cached year * start is not zero, which will not happen after 1900 for the * next few thousand years. */ if (*yearstart) { /* -- get time stamp of potential solution */ test[0] = (u_int32)(*yearstart) + tmp; /* -- calc absolute difference to receive time */ diff[0] = test[0] - rec_ui; if (diff[0] >= 0x80000000u) diff[0] = ~diff[0] + 1; /* -- can't get closer if diff < NEARTIME */ if (diff[0] < NEARTIME) { *ts_ui = test[0]; return diff[0] < CLOSETIME; } } /* * Now the dance begins. Based on the receive time stamp and * the seconds offset in 'tmp', we make an educated guess * about the year to start with. This takes us on the spot * with a fuzz of +/-1 year. * * We calculate the effective timestamps for the three years * around the guess and select the entry with the minimum * absolute difference to the receive time stamp. */ y = ntp_to_year(rec_ui - tmp); for (idx = 0; idx < 3; idx++) { /* -- get year start of potential solution */ ystt[idx] = year_to_ntp(y + idx - 1); /* -- get time stamp of potential solution */ test[idx] = ystt[idx] + tmp; /* -- calc absolute difference to receive time */ diff[idx] = test[idx] - rec_ui; if (diff[idx] >= 0x80000000u) diff[idx] = ~diff[idx] + 1; } /* -*- assume current year fits best, then search best fit */ for (min = 1, idx = 0; idx < 3; idx++) if (diff[idx] < diff[min]) min = idx; /* -*- store results and update year start */ *ts_ui = test[min]; *yearstart = ystt[min]; /* -*- tell if we could get into CLOSETIME*/ return diff[min] < CLOSETIME; } static int32 ntp_to_year( u_int32 ntp) { vint64 t; ntpcal_split s; t = ntpcal_ntp_to_ntp(ntp, NULL); s = ntpcal_daysplit(&t); s = ntpcal_split_eradays(s.hi + DAY_NTP_STARTS - 1, NULL); return s.hi + 1; } static u_int32 year_to_ntp( int32 year) { u_int32 days; days = ntpcal_days_in_years(year-1) - DAY_NTP_STARTS + 1; return days * SECSPERDAY; }
Upload File
Create Folder