X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/a36b3aeb877e4357918cfd99ddad5ce913a3a0b6..refs/heads/master:/print-zep.c diff --git a/print-zep.c b/print-zep.c index e10ecb35..20a1e2ae 100644 --- a/print-zep.c +++ b/print-zep.c @@ -21,9 +21,7 @@ /* \summary: ZigBee Encapsulation Protocol (ZEP) printer */ -#ifdef HAVE_CONFIG_H #include -#endif #include "netdissect-stdinc.h" @@ -32,6 +30,8 @@ #include "extract.h" +#include "ntp.h" + /* From wireshark packet-zep.c: * *********************************************************************** @@ -57,42 +57,6 @@ *------------------------------------------------------------ */ -#define JAN_1970 2208988800U - -/* Print timestamp */ -static void zep_print_ts(netdissect_options *ndo, const u_char *p) -{ - int32_t i; - uint32_t uf; - uint32_t f; - float ff; - - i = GET_BE_U_4(p); - uf = GET_BE_U_4(p + 4); - ff = (float) uf; - if (ff < 0.0) /* some compilers are buggy */ - ff += FMAXINT; - ff = (float) (ff / FMAXINT); /* shift radix point by 32 bits */ - f = (uint32_t) (ff * 1000000000.0); /* treat fraction as parts per - billion */ - ND_PRINT("%u.%09d", i, f); - -#ifdef HAVE_STRFTIME - /* - * print the time in human-readable format. - */ - if (i) { - time_t seconds = i - JAN_1970; - struct tm *tm; - char time_buf[128]; - - tm = localtime(&seconds); - strftime(time_buf, sizeof (time_buf), "%Y/%m/%d %H:%M:%S", tm); - ND_PRINT(" (%s)", time_buf); - } -#endif -} - /* * Main function to print packets. */ @@ -123,6 +87,7 @@ zep_print(netdissect_options *ndo, if (version == 1) { /* ZEP v1 packet. */ + ND_ICHECK_U(len, <, 16); ND_PRINT("Channel ID %u, Device ID 0x%04x, ", GET_U_1(bp + 3), GET_BE_U_2(bp + 4)); if (GET_U_1(bp + 6)) @@ -138,6 +103,7 @@ zep_print(netdissect_options *ndo, /* ZEP v2 packet. */ if (GET_U_1(bp + 3) == 2) { /* ZEP v2 ack. */ + ND_ICHECK_U(len, <, 8); seq_no = GET_BE_U_4(bp + 4); ND_PRINT("ACK, seq# = %u", seq_no); inner_len = 0; @@ -145,6 +111,7 @@ zep_print(netdissect_options *ndo, len -= 8; } else { /* ZEP v2 data, or some other. */ + ND_ICHECK_U(len, <, 32); ND_PRINT("Type %u, Channel ID %u, Device ID 0x%04x, ", GET_U_1(bp + 3), GET_U_1(bp + 4), GET_BE_U_2(bp + 5)); @@ -153,7 +120,12 @@ zep_print(netdissect_options *ndo, else ND_PRINT("LQI %u, ", GET_U_1(bp + 8)); - zep_print_ts(ndo, bp + 9); + /* + * XXX - why a space rather than a "T" + * between the date and time? + */ + p_ntp_time_fmt(ndo, "%Y-%m-%d %H:%M:%S", + (const struct l_fixedpt *)(bp + 9)); seq_no = GET_BE_U_4(bp + 17); inner_len = GET_U_1(bp + 31); ND_PRINT(", seq# = %u, inner len = %u", @@ -175,4 +147,7 @@ zep_print(netdissect_options *ndo, if (!ndo->ndo_suppress_default_print) ND_DEFAULTPRINT(bp, len); + return; +invalid: + nd_print_invalid(ndo); }