+ ND_TCHECK2(*bp, length);
+ return;
+
+trunc:
+ ND_PRINT((ndo, " [|ntp]"));
+}
+
+/*
+ * Print NTP control message requests and responses
+ */
+static void
+ntp_control_print(netdissect_options *ndo,
+ register const struct ntp_control_data *cd, u_int length)
+{
+ u_char R, E, M, opcode;
+ uint16_t sequence, status, assoc, offset, count;
+
+ R = (cd->control & 0x80) != 0;
+ E = (cd->control & 0x40) != 0;
+ M = (cd->control & 0x20) != 0;
+ opcode = cd->control & 0x1f;
+ ND_PRINT((ndo, ", %s, %s, %s, OpCode=%u\n",
+ R ? "Response" : "Request", E ? "Error" : "OK",
+ M ? "More" : "Last", (unsigned)opcode));
+
+ sequence = EXTRACT_16BITS(&cd->sequence);
+ ND_PRINT((ndo, "\tSequence=%hu", sequence));
+
+ status = EXTRACT_16BITS(&cd->status);
+ ND_PRINT((ndo, ", Status=%#hx", status));
+
+ assoc = EXTRACT_16BITS(&cd->assoc);
+ ND_PRINT((ndo, ", Assoc.=%hu", assoc));
+
+ offset = EXTRACT_16BITS(&cd->offset);
+ ND_PRINT((ndo, ", Offset=%hu", offset));
+
+ count = EXTRACT_16BITS(&cd->count);
+ ND_PRINT((ndo, ", Count=%hu", count));
+
+ if ((cd->data - (const u_char *)cd) + count > length)
+ goto trunc;
+ if (count != 0)
+ ND_PRINT((ndo, "\n\tTO-BE-DONE: data not interpreted"));
+ return;
+
+trunc:
+ ND_PRINT((ndo, " [|ntp]"));
+}
+
+union ntpdata {
+ struct ntp_time_data td;
+ struct ntp_control_data cd;
+};
+
+/*
+ * Print NTP requests, handling the common VN, LI, and Mode
+ */
+void
+ntp_print(netdissect_options *ndo,
+ register const u_char *cp, u_int length)
+{
+ register const union ntpdata *bp = (const union ntpdata *)cp;
+ int mode, version, leapind;
+
+ ND_TCHECK(bp->td.status);
+
+ version = (bp->td.status & VERSIONMASK) >> VERSIONSHIFT;
+ ND_PRINT((ndo, "NTPv%d", version));
+
+ mode = (bp->td.status & MODEMASK) >> MODESHIFT;
+ if (!ndo->ndo_vflag) {
+ ND_PRINT((ndo, ", %s, length %u",
+ tok2str(ntp_mode_values, "Unknown mode", mode),
+ length));
+ return;
+ }
+
+ ND_PRINT((ndo, ", %s, length %u\n",
+ tok2str(ntp_mode_values, "Unknown mode", mode), length));
+
+ /* leapind = (bp->td.status & LEAPMASK) >> LEAPSHIFT; */
+ leapind = (bp->td.status & LEAPMASK);
+ ND_PRINT((ndo, "\tLeap indicator: %s (%u)",
+ tok2str(ntp_leapind_values, "Unknown", leapind),
+ leapind));
+
+ if (mode >= MODE_UNSPEC && mode <= MODE_BROADCAST)
+ ntp_time_print(ndo, &bp->td, length);
+ else if (mode == MODE_CONTROL)
+ ntp_control_print(ndo, &bp->cd, length);
+ else
+ {;} /* XXX: not implemented! */