ntpd / ntpq Internals


Wikipedia: ntpd (de)
Wikipedia: ntpd (en)
The NTP FAQ and HOWTO, Understanding and using the Network Time Protocol (2006-11-21)
Network Time Synchronization Research Project (with PowerPoint/PDF presentations)
The Network Time Protocol (NTP) Distribution (31-Mar-2014 05:41)
The Network Time Protocol (NTP) Distribution (07-Nov-2009 20:43 UTC)
Performance Metrics for root distance statistic (root delay, root dispersion), 26.07.2015

support.ntp.org Wiki

The NTP Public Services Project
NTP Support Web
Configuring NTP
ntpd access restrictions


Major definitions of time

  • Atomic Time – or TAI
  • Universal Time – or UT0 and UT1
  • oordinated Universal Time – or UTC
  • Unix epoch = 1 January 1970
  • NTP epoch = 1 January 1900
  • constant 2,208,988,800 between 1900 and 1970
  • TAI seconds: seconds since 01.01.1970 00:00 without leap seconds
  • UTC seconds: seconds since 01.01.1970 00:00 with leap seconds (today 36 leap seconds) without daylight-saving time and time-zone information
  • NTP seconds: seconds since 01.01.1900 00:00 with leap seconds without daylight-saving time and time-zone information

Create ntp time stamp from gettimeofday
NTP Timestamp calculation


Time, Clock, and Calendar Programming In C
NTP, UTC, and Working with Time on Linux
The Unix leap second mess
The NTP Era and Era Numbering
NTP Timestamp Calculations

gettimeofday() should never be used to measure time
C/C++ tip: How to measure elapsed real time for benchmarking


Create ntp time stamp from gettimeofday
Measure time in Linux – getrusage vs clock_gettime vs clock vs gettimeofday?
faster equivalent of gettimeofday
How do I get the unix timestamp in C as an int?

Manual Pages

Ubuntu Wily: man ntp.conf
FreeBSD 10.2: man ntp.conf

Reference Clock

Generic Reference Driver


RFC: Reference ID for NTPv6
REFID Format
Updating the REFID format


Ubuntuuser.de: Systemzeit
NTP Server – Stratum Levels Explained
The Raspberry Pi as a Stratum-1 NTP Server
How to build a stratum 1 NTP server with GPS time reference
Setting up a local stratum 2 NTP server
NTP-Deamon Konfiguration
Network Time Protocol

Root distance / dispersion

Root delay and Root dispersion values in NTP protocol?
NTPD not updating time date on CENTOS



powerpc-e300c3-linux-gnu-gcc -o ntpd ntp_config.o ntp_io.o \
ntp_parser.o ntp_scanner.o ntpd.o ntpd-opts.o \
-L. -lopts -lntp -lntpd -lrt -lcap -lm -lssl -lcrypto

ntpd.o: In function `ntpdmain':
./libntpd.a(ntp_control.o): In function `ctl_putadr':
src/ntpd/ntp_control.c:1678: undefined reference to `numtoa'
./libntpd.a(ntp_control.o): In function `ctl_putsys':
src/ntpd/ntp_control.c:2214: undefined reference to `k_st_flags'
./libntpd.a(ntp_control.o): In function `send_restrict_entry':
src/ntpd/ntp_control.c:4239: undefined reference to `res_match_flags'
src/ntpd/ntp_control.c:4240: undefined reference to `res_access_flags'
./libntpd.a(ntp_control.o): In function `write_variables':
src/ntpd/ntp_control.c:3283: undefined reference to `atoint'
./libntpd.a(ntp_control.o): In function `report_event':
src/ntpd/ntp_control.c:4773: undefined reference to `eventstr'
src/ntpd/ntp_control.c:4741: undefined reference to `eventstr'


Libraries order were not right

-lopts -lntp -lntpd

-lntpd -lntp -lopts

Is it possible to have circular dependencies?
Resolving circular dependencies by linking the same library twice?
Avoiding Linking Problems, Darryl Gove and Stephen Clamage, May 2011

-lfoo -lbar -lfoo
-Wl,--start-group -lfoo -lbar -Wl,--end-group


How does asynchronouse / non-blocking sockets work?
non-blocking sockets + signal SIGALRM


SIGALRM, setitimer(), sleep(), select()
select() returns that socket is ready when SIGALRM
Unix signal handling example in C, SIGINT, SIGALRM, SIGHUP…

If any of these (as well as other) system calls is interrupted by a signal, such as SIGALRM or SIGIO, the call will return -1 and the variable errno will be
set to EINTR 2. The system call will be automatically restarted. It may be advisable to reset errno to zero.

Berkeley UNIX System Calls and Interprocess Communication
Unix connect() and interrupted system calls
c / interrupted system call / fork vs. thread
System call interrupted by a signal still has to be completed
EINTR and non-blocking calls
Apple: Avoiding Common Networking Mistakes
glibc: Waiting for Input or Output
select() usage examples
System call error handling


How to listen only on specific interfaces?


How to prevent ntpd to listen on
Does NTPd have to listen on an interface or address for updating the server time?


No header files for simulation / standalone

[CC] src/ntpd/cmd_args.c
gcc -o obj/osa541x_sim/libntpd.a/ntpd/cmd_args.o -c src/ntpd/cmd_args.c -Iinclude/config/x86 -DHAVE_CONFIG_H -Iinclude -Wall -Wcast-align -Wcast-qual -Wmissing-prototypes -Wpointer-arith -Wshadow -Winit-self -Wstrict-overflow -Wno-strict-prototypes -g -O2 
In file included from include/ntp.h:14:0,
                 from include/ntpd.h:11,
                 from src/ntpd/cmd_args.c:8:
include/ntp_crypto.h:27:25: fatal error: openssl/evp.h: No such file or directory


Install header files

$ sudo apt-get install libssl-dev


YACC not found

[CC] src/ntpd/ntp_io.c
gcc -o obj/osa541x_sim/advaNtpd/ntpd/ntp_io.o -c src/ntpd/ntp_io.c -Iinclude/config/x86 -DHAVE_CONFIG_H -Iinclude -Wall -Wcast-align -Wcast-qual -Wmissing-prototypes -Wpointer-arith -Wshadow -Winit-self -Wstrict-overflow -Wno-strict-prototypes -g -O2
src/ntpd/ntp_io.c: In function ‘io_setbclient’:
src/ntpd/ntp_io.c:2672:5: warning: assuming signed overflow does not occur when simplifying conditional to constant [-Wstrict-overflow]
  if (nif > 0) {
src/ntpd/ntp_io.c:2672:5: warning: assuming signed overflow does not occur when simplifying conditional to constant [-Wstrict-overflow]
yacc  src/ntpd/ntp_parser.y 
make: yacc: Command not found
<builtin>: recipe for target 'src/ntpd/ntp_parser.c' failed
make: *** [src/ntpd/ntp_parser.c] Error 127

Leave a Reply

Your email address will not be published. Required fields are marked *