]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-ntp.c
Check against various modes explicitly.
[tcpdump] / print-ntp.c
index 9079c616cef3d8172f6f940effeb914e309a2aa2..b4fa61297301e7bb8ea7549bfd223b19196d2ba2 100644 (file)
@@ -290,7 +290,7 @@ ntp_time_print(netdissect_options *ndo,
        ND_PRINT(", Root dispersion: ");
        p_sfix(ndo, &bp->root_dispersion);
 
-       ND_TCHECK(bp->refid);
+       ND_TCHECK_4(bp->refid);
        ND_PRINT(", Reference-ID: ");
        /* Interpretation depends on stratum */
        switch (stratum) {
@@ -317,7 +317,7 @@ ntp_time_print(netdissect_options *ndo,
        default:
                /* In NTPv4 (RFC 5905) refid is an IPv4 address or first 32 bits of
                   MD5 sum of IPv6 address */
-               ND_PRINT("0x%08x", EXTRACT_BE_U_4(&bp->refid));
+               ND_PRINT("0x%08x", EXTRACT_BE_U_4(bp->refid));
                break;
        }
 
@@ -453,14 +453,14 @@ ntp_print(netdissect_options *ndo,
           const u_char *cp, u_int length)
 {
        const union ntpdata *bp = (const union ntpdata *)cp;
-       int mode, version, leapind;
+       u_int mode, version, leapind;
        uint8_t status;
 
-       ND_TCHECK(bp->td.status);
+       ND_TCHECK_1(bp->td.status);
        status = EXTRACT_U_1(bp->td.status);
 
        version = (status & VERSIONMASK) >> VERSIONSHIFT;
-       ND_PRINT("NTPv%d", version);
+       ND_PRINT("NTPv%u", version);
 
        mode = (status & MODEMASK) >> MODESHIFT;
        if (!ndo->ndo_vflag) {
@@ -479,12 +479,24 @@ ntp_print(netdissect_options *ndo,
                  tok2str(ntp_leapind_values, "Unknown", leapind),
                  leapind);
 
-       if (mode >= MODE_UNSPEC && mode <= MODE_BROADCAST)
+       switch (mode) {
+
+       case MODE_UNSPEC:
+       case MODE_SYM_ACT:
+       case MODE_SYM_PAS:
+       case MODE_CLIENT:
+       case MODE_SERVER:
+       case MODE_BROADCAST:
                ntp_time_print(ndo, &bp->td, length);
-       else if (mode == MODE_CONTROL)
+               break;
+
+       case MODE_CONTROL:
                ntp_control_print(ndo, &bp->cd, length);
-       else
-               {;}                     /* XXX: not implemented! */
+               break;
+
+       default:
+               break;                  /* XXX: not implemented! */
+       }
        return;
 
 trunc:
@@ -499,8 +511,8 @@ p_sfix(netdissect_options *ndo,
        int f;
        double ff;
 
-       i = EXTRACT_BE_U_2(&sfp->int_part);
-       f = EXTRACT_BE_U_2(&sfp->fraction);
+       i = EXTRACT_BE_U_2(sfp->int_part);
+       f = EXTRACT_BE_U_2(sfp->fraction);
        ff = f / 65536.0;               /* shift radix point by 16 bits */
        f = (int)(ff * 1000000.0);      /* Treat fraction as parts per million */
        ND_PRINT("%d.%06d", i, f);
@@ -517,8 +529,8 @@ p_ntp_time(netdissect_options *ndo,
        uint32_t f;
        double ff;
 
-       i = EXTRACT_BE_U_4(&lfp->int_part);
-       uf = EXTRACT_BE_U_4(&lfp->fraction);
+       i = EXTRACT_BE_U_4(lfp->int_part);
+       uf = EXTRACT_BE_U_4(lfp->fraction);
        ff = uf;
        if (ff < 0.0)           /* some compilers are buggy */
                ff += FMAXINT;
@@ -575,10 +587,10 @@ p_ntp_delta(netdissect_options *ndo,
        double ff;
        int signbit;
 
-       u = EXTRACT_BE_U_4(&lfp->int_part);
-       ou = EXTRACT_BE_U_4(&olfp->int_part);
-       uf = EXTRACT_BE_U_4(&lfp->fraction);
-       ouf = EXTRACT_BE_U_4(&olfp->fraction);
+       u = EXTRACT_BE_U_4(lfp->int_part);
+       ou = EXTRACT_BE_U_4(olfp->int_part);
+       uf = EXTRACT_BE_U_4(lfp->fraction);
+       ouf = EXTRACT_BE_U_4(olfp->fraction);
        if (ou == 0 && ouf == 0) {
                p_ntp_time(ndo, lfp);
                return;