+ uint8_t control, R, E, M, opcode;
+ uint16_t sequence, status, assoc, offset, count;
+
+ if (length < NTP_CTRLMSG_MINLEN)
+ goto invalid;
+
+ ND_TCHECK_1(cd->control);
+ control = EXTRACT_U_1(cd->control);
+ R = (control & 0x80) != 0;
+ E = (control & 0x40) != 0;
+ M = (control & 0x20) != 0;
+ opcode = control & 0x1f;
+ ND_PRINT(", %s, %s, %s, OpCode=%u\n",
+ R ? "Response" : "Request", E ? "Error" : "OK",
+ M ? "More" : "Last", opcode);
+
+ ND_TCHECK_2(cd->sequence);
+ sequence = EXTRACT_BE_U_2(cd->sequence);
+ ND_PRINT("\tSequence=%hu", sequence);
+
+ ND_TCHECK_2(cd->status);
+ status = EXTRACT_BE_U_2(cd->status);
+ ND_PRINT(", Status=%#hx", status);
+
+ ND_TCHECK_2(cd->assoc);
+ assoc = EXTRACT_BE_U_2(cd->assoc);
+ ND_PRINT(", Assoc.=%hu", assoc);
+
+ ND_TCHECK_2(cd->offset);
+ offset = EXTRACT_BE_U_2(cd->offset);
+ ND_PRINT(", Offset=%hu", offset);
+
+ ND_TCHECK_2(cd->count);
+ count = EXTRACT_BE_U_2(cd->count);
+ ND_PRINT(", Count=%hu", count);
+
+ if (NTP_CTRLMSG_MINLEN + count > length)
+ goto invalid;
+ if (count != 0) {
+ ND_TCHECK_LEN(cd->data, count);
+ ND_PRINT("\n\tTO-BE-DONE: data not interpreted");
+ }
+ return;
+
+invalid:
+ ND_PRINT("%s", istr);
+ ND_TCHECK_LEN(cd, length);
+ return;
+
+trunc:
+ nd_print_trunc(ndo);
+}
+
+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,
+ const u_char *cp, u_int length)
+{
+ const union ntpdata *bp = (const union ntpdata *)cp;
+ u_int mode, version, leapind;
+ uint8_t status;
+
+ ndo->ndo_protocol = "ntp";
+ ND_TCHECK_1(bp->td.status);
+ status = EXTRACT_U_1(bp->td.status);
+
+ version = (status & VERSIONMASK) >> VERSIONSHIFT;
+ ND_PRINT("NTPv%u", version);
+
+ mode = (status & MODEMASK) >> MODESHIFT;
+ if (!ndo->ndo_vflag) {
+ ND_PRINT(", %s, length %u",
+ tok2str(ntp_mode_values, "Unknown mode", mode),
+ length);
+ return;
+ }
+
+ ND_PRINT(", %s, length %u\n",
+ tok2str(ntp_mode_values, "Unknown mode", mode), length);
+
+ /* leapind = (status & LEAPMASK) >> LEAPSHIFT; */
+ leapind = (status & LEAPMASK);
+ ND_PRINT("\tLeap indicator: %s (%u)",
+ tok2str(ntp_leapind_values, "Unknown", leapind),
+ leapind);
+
+ 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);
+ break;
+
+ case MODE_CONTROL:
+ ntp_control_print(ndo, &bp->cd, length);
+ break;
+
+ default:
+ break; /* XXX: not implemented! */
+ }
+ return;
+
+trunc:
+ nd_print_trunc(ndo);
+}
+
+static void
+p_sfix(netdissect_options *ndo,
+ const struct s_fixedpt *sfp)
+{
+ int i;
+ int f;
+ double ff;
+
+ 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);