{"id":4398,"date":"2015-12-07T13:17:53","date_gmt":"2015-12-07T13:17:53","guid":{"rendered":"http:\/\/blog.bachi.net\/?p=4398"},"modified":"2016-03-16T14:57:19","modified_gmt":"2016-03-16T14:57:19","slug":"ntpd-ntpq-internals","status":"publish","type":"post","link":"https:\/\/blog.bachi.net\/?p=4398","title":{"rendered":"ntpd \/ ntpq Internals"},"content":{"rendered":"<h3>Documentation<\/h3>\n<p><a href=\"https:\/\/de.wikipedia.org\/wiki\/Network_Time_Protocol\">Wikipedia: ntpd<\/a> (de)<br \/>\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/Ntpd\">Wikipedia: ntpd<\/a> (en)<br \/>\n<a href=\"http:\/\/www.ntp.org\/ntpfaq\/NTP-a-faq.htm\">The NTP FAQ and HOWTO<\/a>, Understanding and using the Network Time Protocol (2006-11-21)<br \/>\n<a href=\"https:\/\/www.eecis.udel.edu\/~mills\/ntp.html\">Network Time Synchronization Research Project<\/a> (with PowerPoint\/PDF presentations)<br \/>\n<a href=\"https:\/\/www.eecis.udel.edu\/~mills\/ntp\/html\/index.html\">The Network Time Protocol (NTP) Distribution<\/a> (31-Mar-2014 05:41)<br \/>\n<a href=\"http:\/\/doc.ntp.org\/4.2.6p5\/\">The Network Time Protocol (NTP) Distribution<\/a> (07-Nov-2009 20:43 UTC)<br \/>\n<a href=\"https:\/\/www.eecis.udel.edu\/~mills\/ntp\/html\/stats.html\">Performance Metrics<\/a> for root distance statistic (root delay, root dispersion),  26.07.2015<\/p>\n<h3>support.ntp.org Wiki<\/h3>\n<p><a href=\"http:\/\/support.ntp.org\/bin\/view\/Main\/WebHome\">The NTP Public Services Project<\/a><br \/>\n<a href=\"http:\/\/support.ntp.org\/bin\/view\/Support\/WebHome\">NTP Support Web<\/a><br \/>\n<a href=\"http:\/\/support.ntp.org\/bin\/view\/Support\/ConfiguringNTP\">Configuring NTP<\/a><br \/>\n<a href=\"http:\/\/support.ntp.org\/bin\/view\/Support\/AccessRestrictions\">ntpd access restrictions <\/a><\/p>\n<h3>Timescale<\/h3>\n<p>Major definitions of time<\/p>\n<ul>\n<li>Atomic Time &#8211; or TAI<\/li>\n<li>Universal Time &#8211; or UT0 and UT1<\/li>\n<li>oordinated Universal Time &#8211; or UTC<\/li>\n<\/ul>\n<ul>\n<li>Unix epoch = 1 January 1970<\/li>\n<li>NTP epoch = 1 January 1900<\/li>\n<li>constant 2,208,988,800 between 1900 and 1970<\/li>\n<\/ul>\n<ul>\n<li>TAI seconds: seconds since 01.01.1970 00:00 without leap seconds<\/li>\n<li>UTC seconds: seconds since 01.01.1970 00:00 with leap seconds (today 36 leap seconds) without daylight-saving time and time-zone information<\/li>\n<li>NTP seconds: seconds since 01.01.1900 00:00 with leap seconds without daylight-saving time and time-zone information<\/li>\n<\/ul>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/2641954\/create-ntp-time-stamp-from-gettimeofday\">Create ntp time stamp from gettimeofday<\/a><br \/>\n<a href=\"http:\/\/thompsonng.blogspot.ch\/2010\/04\/ntp-timestamp_21.html\">NTP Timestamp calculation<\/a><\/p>\n<table>\n<tr>\n<td><a href=\"http:\/\/blog.bachi.net\/wp-content\/uploads\/2015\/12\/ntp_fraction.png\" rel=\"attachment wp-att-4773\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.bachi.net\/wp-content\/uploads\/2015\/12\/ntp_fraction-300x30.png\" alt=\"ntp_fraction\" width=\"300\" height=\"30\" class=\"alignleft size-medium wp-image-4773\" srcset=\"https:\/\/blog.bachi.net\/wp-content\/uploads\/2015\/12\/ntp_fraction-300x30.png 300w, https:\/\/blog.bachi.net\/wp-content\/uploads\/2015\/12\/ntp_fraction.png 486w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/td>\n<\/tr>\n<\/table>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\na\r\n<\/pre>\n<p><a href=\"http:\/\/www.catb.org\/esr\/time-programming\/\">Time, Clock, and Calendar Programming In C<\/a><br \/>\n<a href=\"http:\/\/souptonuts.sourceforge.net\/readme_working_with_time.html\">NTP, UTC, and Working with Time on Linux<\/a><br \/>\n<a href=\"http:\/\/www.madore.org\/~david\/computers\/unix-leap-seconds.html\">The Unix leap second mess<\/a><br \/>\n<a href=\"https:\/\/www.eecis.udel.edu\/~mills\/y2k.html\">The NTP Era and Era Numbering<\/a><br \/>\n<a href=\"https:\/\/www.eecis.udel.edu\/~mills\/time.html\">NTP Timestamp Calculations<\/a><\/p>\n<p><a href=\"https:\/\/blog.habets.se\/2010\/09\/gettimeofday-should-never-be-used-to-measure-time\">gettimeofday() should never be used to measure time<\/a><br \/>\n<a href=\"http:\/\/nadeausoftware.com\/articles\/2012\/04\/c_c_tip_how_measure_elapsed_real_time_benchmarking\">C\/C++ tip: How to measure elapsed real time for benchmarking<\/a><\/p>\n<h4>stackoverflow<\/h4>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/2641954\/create-ntp-time-stamp-from-gettimeofday\">Create ntp time stamp from gettimeofday<\/a><br \/>\n<a href=\"http:\/\/stackoverflow.com\/questions\/12392278\/measure-time-in-linux-getrusage-vs-clock-gettime-vs-clock-vs-gettimeofday\">Measure time in Linux &#8211; getrusage vs clock_gettime vs clock vs gettimeofday?<\/a><br \/>\n<a href=\"http:\/\/stackoverflow.com\/questions\/6498972\/faster-equivalent-of-gettimeofday\">faster equivalent of gettimeofday<\/a><br \/>\n<a href=\"http:\/\/stackoverflow.com\/questions\/11765301\/how-do-i-get-the-unix-timestamp-in-c-as-an-int\">How do I get the unix timestamp in C as an int?<\/a><\/p>\n<h3>Manual Pages<\/h3>\n<p><a href=\"http:\/\/manpages.ubuntu.com\/manpages\/wily\/man5\/ntp.conf.5.html\">Ubuntu Wily: man ntp.conf<\/a><br \/>\n<a href=\"https:\/\/www.freebsd.org\/cgi\/man.cgi?query=ntp.conf&#038;sektion=5\">FreeBSD 10.2: man ntp.conf<\/a><\/p>\n<h3>Reference Clock<\/h3>\n<p><a href=\"https:\/\/www.eecis.udel.edu\/~mills\/ntp\/html\/drivers\/driver8.html\">Generic Reference Driver<\/a><\/p>\n<h3>IPv6<\/h3>\n<p><a href=\"https:\/\/tools.ietf.org\/html\/draft-boudreault-ipv6-ntp-refid-00\">RFC: Reference ID for NTPv6<\/a><br \/>\n<a href=\"http:\/\/support.ntp.org\/bin\/view\/Support\/RefidFormat\">REFID Format<\/a><br \/>\n<a href=\"https:\/\/support.ntp.org\/bin\/view\/Dev\/UpdatingTheRefidFormat\">Updating the REFID format <\/a><\/p>\n<h3>HowTos<\/h3>\n<p><a href=\"https:\/\/wiki.ubuntuusers.de\/Systemzeit\/\">Ubuntuuser.de: Systemzeit<\/a><br \/>\n<a href=\"https:\/\/ntpserver.wordpress.com\/2008\/09\/10\/ntp-server-stratum-levels-explained\/\">NTP Server \u2013 Stratum Levels Explained<\/a><br \/>\n<a href=\"http:\/\/www.satsignal.eu\/ntp\/Raspberry-Pi-NTP.html\">The Raspberry Pi as a Stratum-1 NTP Server<\/a><br \/>\n<a href=\"https:\/\/readme.phys.ethz.ch\/attic\/how_to_build_a_stratum_1_ntp_server_with_gps_time_reference\/\">How to build a stratum 1 NTP server with GPS time reference<\/a><br \/>\n<a href=\"http:\/\/serverfault.com\/questions\/153206\/setting-up-a-local-stratum-2-ntp-server\">Setting up a local stratum 2 NTP server<\/a><br \/>\n<a href=\"http:\/\/doc-tcpip.org\/Ntp\/config.html\">NTP-Deamon Konfiguration<\/a><br \/>\n<a href=\"http:\/\/www.brennan.id.au\/09-Network_Time_Protocol.html\">Network Time Protocol<\/a><\/p>\n<h4>Root distance \/ dispersion<\/h4>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/30431358\/root-delay-and-root-dispersion-values-in-ntp-protocol\">Root delay and Root dispersion values in NTP protocol?<\/a><br \/>\n<a href=\"http:\/\/superuser.com\/questions\/843580\/ntpd-not-updating-time-date-on-centos\/845013#845013\">NTPD not updating time date on CENTOS<\/a><\/p>\n<h3>FAQ<\/h3>\n<h4>Question<\/h4>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\npowerpc-e300c3-linux-gnu-gcc -o ntpd ntp_config.o ntp_io.o \\\r\nntp_parser.o ntp_scanner.o ntpd.o ntpd-opts.o \\\r\n-L. -lopts -lntp -lntpd -lrt -lcap -lm -lssl -lcrypto\r\n\r\nntpd.o: In function `ntpdmain':\r\n.\/libntpd.a(ntp_control.o): In function `ctl_putadr':\r\nsrc\/ntpd\/ntp_control.c:1678: undefined reference to `numtoa'\r\n.\/libntpd.a(ntp_control.o): In function `ctl_putsys':\r\nsrc\/ntpd\/ntp_control.c:2214: undefined reference to `k_st_flags'\r\n.\/libntpd.a(ntp_control.o): In function `send_restrict_entry':\r\nsrc\/ntpd\/ntp_control.c:4239: undefined reference to `res_match_flags'\r\nsrc\/ntpd\/ntp_control.c:4240: undefined reference to `res_access_flags'\r\n.\/libntpd.a(ntp_control.o): In function `write_variables':\r\nsrc\/ntpd\/ntp_control.c:3283: undefined reference to `atoint'\r\n.\/libntpd.a(ntp_control.o): In function `report_event':\r\nsrc\/ntpd\/ntp_control.c:4773: undefined reference to `eventstr'\r\nsrc\/ntpd\/ntp_control.c:4741: undefined reference to `eventstr'\r\n<\/pre>\n<h4>Answer<\/h4>\n<p>Libraries order were not right<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nbefore:\r\n-lopts -lntp -lntpd\r\n\r\nafter:\r\n-lntpd -lntp -lopts\r\n<\/pre>\n<p>Is it possible to have circular dependencies?<br \/>\n<a href=\"http:\/\/stackoverflow.com\/questions\/9380363\/resolving-circular-dependencies-by-linking-the-same-library-twice\">Resolving circular dependencies by linking the same library twice?<\/a><br \/>\n<a href=\"http:\/\/www.oracle.com\/technetwork\/articles\/servers-storage-dev\/linkinglibraries4-405107.html\">Avoiding Linking Problems<\/a>, Darryl Gove and Stephen Clamage, May 2011<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n-lfoo -lbar -lfoo\r\nor\r\n-Wl,--start-group -lfoo -lbar -Wl,--end-group\r\n<\/pre>\n<h4>Question<\/h4>\n<p>How does asynchronouse \/ non-blocking sockets work?<br \/>\nnon-blocking sockets + signal SIGALRM<\/p>\n<h4>Answer<\/h4>\n<p><a href=\"http:\/\/www.mikrocontroller.net\/topic\/278522\">SIGALRM, setitimer(), sleep(), select()<\/a><br \/>\n<a href=\"http:\/\/stackoverflow.com\/questions\/17526107\/select-returns-that-socket-is-ready-when-sigalrm\">select() returns that socket is ready when SIGALRM<\/a><br \/>\n<a href=\"https:\/\/gist.github.com\/aspyct\/3462238\">Unix signal handling example in C, SIGINT, SIGALRM, SIGHUP&#8230; <\/a><\/p>\n<blockquote><p>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<br \/>\nset to EINTR 2. The system call will be automatically restarted. It may be advisable to reset errno to zero. <\/p><\/blockquote>\n<p><a href=\"http:\/\/www.math.stonybrook.edu\/~ccc\/sockets.html\">Berkeley UNIX System Calls and Interprocess Communication <\/a><br \/>\n<a href=\"http:\/\/www.madore.org\/~david\/computers\/connect-intr.html\">Unix connect() and interrupted system calls<\/a><br \/>\n<a href=\"http:\/\/stackoverflow.com\/questions\/6030310\/c-interrupted-system-call-fork-vs-thread\">c \/ interrupted system call \/ fork vs. thread<\/a><br \/>\n<a href=\"http:\/\/stackoverflow.com\/questions\/13356497\/system-call-interrupted-by-a-signal-still-has-to-be-completed\">System call interrupted by a signal still has to be completed<\/a><br \/>\n<a href=\"http:\/\/stackoverflow.com\/questions\/14134440\/eintr-and-non-blocking-calls\">EINTR and non-blocking calls<\/a><br \/>\n<a href=\"https:\/\/developer.apple.com\/library\/ios\/documentation\/NetworkingInternetWeb\/Conceptual\/NetworkingOverview\/CommonPitfalls\/CommonPitfalls.html\">Apple: Avoiding Common Networking Mistakes<\/a><br \/>\n<a href=\"https:\/\/www.gnu.org\/software\/libc\/manual\/html_node\/Waiting-for-I_002fO.html\">glibc: Waiting for Input or Output<\/a><br \/>\n<a href=\"http:\/\/developerweb.net\/viewtopic.php?id=2933\">select() usage examples<\/a><br \/>\n<a href=\"http:\/\/uw714doc.sco.com\/en\/SDK_sysprog\/SCL_SysCallErrHdl.html\">System call error handling<\/a><\/p>\n<h4>Question<\/h4>\n<p>How to listen only on specific interfaces?<\/p>\n<h4>Answer<\/h4>\n<p><a href=\"http:\/\/serverfault.com\/questions\/475635\/how-to-prevent-ntpd-to-listen-on-0-0-0-0123\">How to prevent ntpd to listen on 0.0.0.0:123?<\/a><br \/>\n<a href=\"http:\/\/serverfault.com\/questions\/236883\/does-ntpd-have-to-listen-on-an-interface-or-address-for-updating-the-server-time\">Does NTPd have to listen on an interface or address for updating the server time?<\/a><\/p>\n<h4>Question<\/h4>\n<p>No header files for simulation \/ standalone<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&#x5B;CC] src\/ntpd\/cmd_args.c\r\ngcc -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 \r\nIn file included from include\/ntp.h:14:0,\r\n                 from include\/ntpd.h:11,\r\n                 from src\/ntpd\/cmd_args.c:8:\r\ninclude\/ntp_crypto.h:27:25: fatal error: openssl\/evp.h: No such file or directory\r\n<\/pre>\n<h4>Answer<\/h4>\n<p>Install header files<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n$ sudo apt-get install libssl-dev\r\n<\/pre>\n<h4>Question<\/h4>\n<p>YACC not found<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&#x5B;CC] src\/ntpd\/ntp_io.c\r\ngcc -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\r\nsrc\/ntpd\/ntp_io.c: In function \u2018io_setbclient\u2019:\r\nsrc\/ntpd\/ntp_io.c:2672:5: warning: assuming signed overflow does not occur when simplifying conditional to constant &#x5B;-Wstrict-overflow]\r\n  if (nif &gt; 0) {\r\n     ^\r\nsrc\/ntpd\/ntp_io.c:2672:5: warning: assuming signed overflow does not occur when simplifying conditional to constant &#x5B;-Wstrict-overflow]\r\nyacc  src\/ntpd\/ntp_parser.y \r\nmake: yacc: Command not found\r\n&lt;builtin&gt;: recipe for target 'src\/ntpd\/ntp_parser.c' failed\r\nmake: *** &#x5B;src\/ntpd\/ntp_parser.c] Error 127\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Documentation 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), [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4398","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/4398","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4398"}],"version-history":[{"count":27,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/4398\/revisions"}],"predecessor-version":[{"id":4774,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/4398\/revisions\/4774"}],"wp:attachment":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}