#include "netdissect-stdinc.h"
#include "netdissect.h"
#include "extract.h"
+#include "timeval-operations.h"
/*
* PTP header
#define PTP_FALSE !PTP_TRUE
#define PTP_HDR_LEN 0x22
+#define PTP_TIMESTAMP_LEN 10U
/* mask based on the first byte */
#define PTP_MAJOR_VERS_MASK 0x0F
static void ptp_print_timestamp(netdissect_options *ndo, const u_char *bp, u_int *len, const char *stype);
static void ptp_print_timestamp_identity(netdissect_options *ndo, const u_char *bp, u_int *len, const char *ttype);
static void ptp_print_announce_msg(netdissect_options *ndo, const u_char *bp, u_int *len);
-static void ptp_print_port_id(netdissect_options *ndo, const u_char *bp, u_int *len);
+static const u_char *ptp_print_port_id(netdissect_options *ndo, const u_char *bp, u_int *len);
static void ptp_print_mgmt_msg(netdissect_options *ndo, const u_char *bp, u_int *len);
-static void
+static const u_char *
print_field(netdissect_options *ndo, const char *st, uint32_t flen,
const u_char *bp, u_int *len, uint8_t hex)
{
default:
break;
}
+
+ return bp;
}
static void
ND_PRINT(", %s:", stype);
/* sec time stamp 6 bytes */
secs = GET_BE_U_6(bp);
- ND_PRINT(" %"PRIu64" seconds,", secs);
+ ND_PRINT(" %"PRIu64".", secs);
*len -= 6;
bp += 6;
/* NS time stamp 4 bytes */
nsecs = GET_BE_U_4(bp);
- ND_PRINT(" %u nanoseconds", nsecs);
+ ND_PRINT("%09u seconds", nsecs);
+ if (nsecs > ND_NANO_PER_SEC - 1)
+ ND_PRINT(" " ND_INVALID_NANO_SEC_STR);
*len -= 4;
bp += 4;
}
ptp_print_timestamp_identity(netdissect_options *ndo,
const u_char *bp, u_int *len, const char *ttype)
{
- uint64_t secs;
- uint32_t nsecs;
uint16_t port_id;
uint64_t port_identity;
- ND_PRINT(", %s:", ttype);
- /* sec time stamp 6 bytes */
- secs = GET_BE_U_6(bp);
- ND_PRINT(" %"PRIu64" seconds,", secs);
- *len -= 6;
- bp += 6;
-
- /* NS time stamp 4 bytes */
- nsecs = GET_BE_U_4(bp);
- ND_PRINT(" %u nanoseconds", nsecs);
- *len -= 4;
- bp += 4;
+ ptp_print_timestamp(ndo, bp, len, ttype);
+ *len -= PTP_TIMESTAMP_LEN;
+ bp += PTP_TIMESTAMP_LEN;
/* port identity*/
port_identity = GET_BE_U_8(bp);
uint8_t rsvd, gm_prio_1, gm_prio_2, gm_clk_cls, gm_clk_acc, time_src;
uint16_t origin_cur_utc, gm_clk_var, steps_removed;
uint64_t gm_clock_id;
- uint64_t secs;
- uint32_t nsecs;
- ND_PRINT(", %s:", p_origin_ts);
- /* sec time stamp 6 bytes */
- secs = GET_BE_U_6(bp);
- ND_PRINT(" %"PRIu64" seconds", secs);
- *len -= 6;
- bp += 6;
-
- /* NS time stamp 4 bytes */
- nsecs = GET_BE_U_4(bp);
- ND_PRINT(" %u nanoseconds", nsecs);
- *len -= 4;
- bp += 4;
+ ptp_print_timestamp(ndo, bp, len, p_origin_ts);
+ *len -= PTP_TIMESTAMP_LEN;
+ bp += PTP_TIMESTAMP_LEN;
/* origin cur utc */
origin_cur_utc = GET_BE_U_2(bp);
bp += 1;
}
-static void
+
+static const u_char *
ptp_print_port_id(netdissect_options *ndo, const u_char *bp, u_int *len)
{
uint16_t port_id;
*len -= 2;
bp += 2;
+ return bp;
}
static void
ptp_print_mgmt_msg(netdissect_options *ndo, const u_char *bp, u_int *len)
{
- ptp_print_port_id(ndo, bp, len);
- print_field(ndo, ", start boundary hops ", PTP_UCHAR_LEN, bp, len, PTP_FALSE);
- print_field(ndo, ", boundary hops ", PTP_UCHAR_LEN, bp, len, PTP_FALSE);
- print_field(ndo, ", flags ", PTP_UCHAR_LEN, bp, len, PTP_TRUE);
- print_field(ndo, ", reserved ", PTP_UCHAR_LEN, bp, len, PTP_TRUE);
+ bp = ptp_print_port_id(ndo, bp, len);
+ bp = print_field(ndo, "start boundary hops:", PTP_UCHAR_LEN, bp, len, PTP_FALSE);
+ bp = print_field(ndo, "boundary hops:", PTP_UCHAR_LEN, bp, len, PTP_FALSE);
+ bp = print_field(ndo, "flags:", PTP_UCHAR_LEN, bp, len, PTP_TRUE);
+ bp = print_field(ndo, "reserved:", PTP_UCHAR_LEN, bp, len, PTP_TRUE);
}