This patch adds two changes that make the NTP request packet sent by connman more consistent with those sent from ntpdate or ntpd in one-shot mode.
Grant Erickson (2): ntp: send a transmit time value that reflects current system time ntp: specify leap-not-in-sync in flags -- 1.7.10 >From e06aa8a29fc61e00d9675ea6b4fa6e2ab3c743ae Mon Sep 17 00:00:00 2001 From: Grant Erickson <[email protected]> Date: Fri, 13 Jul 2012 09:38:52 -0700 Subject: [PATCH 1/2] ntp: send a transmit time value that reflects current system time This sets the ntp request packet transmit time to the current system time to reflect behavior implemented by ntpdate and ntpd in one-shot mode. --- src/ntp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ntp.c b/src/ntp.c index f257cda..88c8b8e 100644 --- a/src/ntp.c +++ b/src/ntp.c @@ -117,8 +117,6 @@ static void send_packet(int fd, const char *server) msg.flags = NTP_FLAGS_ENCODE(NTP_FLAG_LI_NOWARNING, 4, NTP_FLAG_MD_CLIENT);; msg.poll = 4; // min msg.poll = 10; // max - msg.xmttime.seconds = random(); - msg.xmttime.fraction = random(); memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; @@ -127,6 +125,9 @@ static void send_packet(int fd, const char *server) gettimeofday(&transmit_timeval, NULL); + msg.xmttime.seconds = htonl(transmit_timeval.tv_sec + OFFSET_1900_1970); + msg.xmttime.fraction = htonl(transmit_timeval.tv_usec * 1000); + len = sendto(fd, &msg, sizeof(msg), MSG_DONTWAIT, &addr, sizeof(addr)); if (len < 0) { -- 1.7.10 >From 3c0a58203fd20df3db5572243d35b29e83abc895 Mon Sep 17 00:00:00 2001 From: Grant Erickson <[email protected]> Date: Fri, 13 Jul 2012 09:41:20 -0700 Subject: [PATCH 2/2] ntp: specify leap-not-in-sync in flags This patch sets the non-in-sync flag of the leap subfield of the packet flags field. This reflects behavior implemented by ntpdate or ntpd in one-shot mode. --- src/ntp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ntp.c b/src/ntp.c index 88c8b8e..623c21e 100644 --- a/src/ntp.c +++ b/src/ntp.c @@ -114,7 +114,7 @@ static void send_packet(int fd, const char *server) ssize_t len; memset(&msg, 0, sizeof(msg)); - msg.flags = NTP_FLAGS_ENCODE(NTP_FLAG_LI_NOWARNING, 4, NTP_FLAG_MD_CLIENT);; + msg.flags = NTP_FLAGS_ENCODE(NTP_FLAG_LI_NOTINSYNC, 4, NTP_FLAG_MD_CLIENT);; msg.poll = 4; // min msg.poll = 10; // max -- 1.7.10 _______________________________________________ connman mailing list [email protected] http://lists.connman.net/listinfo/connman
