1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2014 Kay Sievers
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
28 #include <arpa/inet.h>
29 #include <netinet/in.h>
30 #include <netinet/ip.h>
31 #include <sys/timex.h>
32 #include <sys/socket.h>
37 #include "timedate-sntp.h"
39 typedef struct Manager Manager;
45 static void manager_free(Manager *m);
46 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
47 #define _cleanup_manager_free_ _cleanup_(manager_freep)
49 static int manager_new(Manager **ret) {
50 _cleanup_manager_free_ Manager *m = NULL;
57 r = sd_event_default(&m->event);
67 static void manager_free(Manager *m) {
72 m->sntp = sntp_unref(m->sntp);
73 sd_event_unref(m->event);
77 static void manager_report(usec_t poll_usec, double offset, double delay, double jitter, bool spike) {
78 log_info("%4llu %+10f %10f %10f%s",
79 poll_usec / USEC_PER_SEC, offset, delay, jitter, spike ? " spike" : "");
82 int main(int argc, char *argv[]) {
83 _cleanup_manager_free_ Manager *m = NULL;
91 r = sntp_new(&m->sntp, m->event);
96 log_set_max_level(LOG_DEBUG);
98 sntp_report_register(m->sntp, manager_report);
100 //server = "216.239.32.15"; /* time1.google.com */
101 //server = "192.53.103.108"; /* ntp1.ptb.de */
102 server = "27.54.95.11"; /* au.pool.ntp.org */
103 r = sntp_server_connect(m->sntp, server);
108 r = sd_event_loop(m->event);
113 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;