#undef fileno
#include "ntp_refclock.h"
#undef fileno
-#include "timevalops.h"
+#include "timespecops.h"
#undef fileno
#include "ntp_stdlib.h"
return 0;
}
if (shm->valid) {
- struct timeval tvr;
- struct timeval tvt;
+ struct timespec tvr;
+ struct timespec tvt;
struct tm *t;
char timestr[20]; /* "%Y-%m-%dT%H:%M:%S" + 1 */
int c;
int ok = 1;
- unsigned cns_new, rns_new, cns_valid, rns_valid;
+ unsigned cns_new, rns_new;
int cnt;
tvr.tv_sec = 0;
- tvr.tv_usec = 0;
+ tvr.tv_nsec = 0;
tvt.tv_sec = 0;
- tvt.tv_usec = 0;
+ tvt.tv_nsec = 0;
switch (shm->mode) {
case 0:
tvr.tv_sec = shm->receiveTimeStampSec;
- tvr.tv_usec = shm->receiveTimeStampUSec;
+ tvr.tv_nsec = shm->receiveTimeStampUSec * 1000;
rns_new = shm->receiveTimeStampNSec;
tvt.tv_sec = shm->clockTimeStampSec;
- tvt.tv_usec = shm->clockTimeStampUSec;
+ tvt.tv_nsec = shm->clockTimeStampUSec * 1000;
cns_new = shm->clockTimeStampNSec;
- rns_valid = ((unsigned) tvr.tv_usec) * 1000;
- cns_valid = ((unsigned) tvt.tv_usec) * 1000;
-
/* Since these comparisons are between unsigned
** variables they are always well defined, and any
** (signed) underflow will turn into very large
** unsigned values, well above the 1000 cutoff
*/
- if ( ((cns_new - cns_valid) < 1000)
- && ((rns_new - rns_valid) < 1000)) {
- cns_valid = cns_new;
- rns_valid = rns_new;
+ if ( ((cns_new - (unsigned)tvt.tv_nsec) < 1000)
+ && ((rns_new - (unsigned)tvr.tv_nsec) < 1000)) {
+ tvt.tv_nsec = cns_new;
+ tvr.tv_nsec = rns_new;
}
- // At this point [cr]ns_valid contains valid ns-level
+ // At this point tvr and tvt contains valid ns-level
// timestamps, possibly generated by extending the
- // old us_level timestamps
+ // old us-level timestamps
break;
cnt = shm->count;
tvr.tv_sec = shm->receiveTimeStampSec;
- tvr.tv_usec = shm->receiveTimeStampUSec;
+ tvr.tv_nsec = shm->receiveTimeStampUSec * 1000;
rns_new = shm->receiveTimeStampNSec;
tvt.tv_sec = shm->clockTimeStampSec;
- tvt.tv_usec = shm->clockTimeStampUSec;
+ tvt.tv_nsec = shm->clockTimeStampUSec * 1000;
cns_new = shm->clockTimeStampNSec;
ok = (cnt == shm->count);
- rns_valid = ((unsigned) tvr.tv_usec) * 1000;
- cns_valid = ((unsigned) tvt.tv_usec) * 1000;
-
/* Since these comparisons are between unsigned
** variables they are always well defined, and any
** (signed) underflow will turn into very large
** unsigned values, well above the 1000 cutoff
*/
- if ( ((cns_new - cns_valid) < 1000)
- && ((rns_new - rns_valid) < 1000)) {
- cns_valid = cns_new;
- rns_valid = rns_new;
+ if ( ((cns_new - (unsigned)tvt.tv_nsec) < 1000)
+ && ((rns_new - (unsigned)tvr.tv_nsec) < 1000)) {
+ tvt.tv_nsec = cns_new;
+ tvr.tv_nsec = rns_new;
}
- // At this point [cr]ns_valid contains valid ns-level
+ // At this point tvr and tvt contains valid ns-level
// timestamps, possibly generated by extending the
- // old us_level timestamps
+ // old us-level timestamps
break;
/* add ntpq -c cv timecode in ISO 8601 format */
strftime(timestr, sizeof(timestr), "%Y-%m-%dT%H:%M:%S", t);
c = snprintf(pp->a_lastcode, sizeof(pp->a_lastcode),
- "%s.%06ldZ", timestr, (long)tvt.tv_usec);
+ "%s.%09ldZ", timestr, (long)tvt.tv_nsec);
pp->lencode = (c < sizeof(pp->a_lastcode))
? c
: 0;
shm->valid = 0;
if (ok) {
- TVTOTS(&tvr,&pp->lastrec);
- pp->lastrec.l_ui += JAN_1970;
- /* pp->lasttime = current_time; */
+ pp->lastrec = tspec_stamp_to_lfp(tvr);
pp->polls++;
pp->day = t->tm_yday+1;
pp->hour = t->tm_hour;
pp->minute = t->tm_min;
pp->second = t->tm_sec;
- pp->nsec = cns_valid;
+ pp->nsec = tvt.tv_nsec;
peer->precision = shm->precision;
pp->leap = shm->leap;
} else {