ntp: Use mnemonics when checking reply flags
authorGrant Erickson <marathon96@gmail.com>
Mon, 16 Jul 2012 16:48:02 +0000 (09:48 -0700)
committerDaniel Wagner <daniel.wagner@bmw-carit.de>
Tue, 17 Jul 2012 08:13:36 +0000 (10:13 +0200)
Use mnemonics when checking reply flags and print out information in
debug mode about why the reply flags were rejected.

src/ntp.c

index 7ef072c..e4267ea 100644 (file)
--- a/src/ntp.c
+++ b/src/ntp.c
@@ -199,8 +199,20 @@ static void decode_msg(void *base, size_t len, struct timeval *tv)
 
        transmit_delay = LOGTOD(msg->poll);
 
 
        transmit_delay = LOGTOD(msg->poll);
 
-       if (msg->flags != 0x24)
+       if (NTP_FLAGS_LI_DECODE(msg->flags) == NTP_FLAG_LI_NOTINSYNC) {
+               DBG("ignoring unsynchronized peer");
                return;
                return;
+       }
+
+       if (NTP_FLAGS_VN_DECODE(msg->flags) != 4) {
+               DBG("unsupported version %d", NTP_FLAGS_VN_DECODE(msg->flags));
+               return;
+       }
+
+       if (NTP_FLAGS_MD_DECODE(msg->flags) != NTP_FLAG_MD_SERVER) {
+               DBG("unsupported mode %d", NTP_FLAGS_MD_DECODE(msg->flags));
+               return;
+       }
 
        org = transmit_timeval.tv_sec +
                        (1.0e-6 * transmit_timeval.tv_usec) + OFFSET_1900_1970;
 
        org = transmit_timeval.tv_sec +
                        (1.0e-6 * transmit_timeval.tv_usec) + OFFSET_1900_1970;