diff options
Diffstat (limited to 'print-ptp.c')
| -rw-r--r-- | print-ptp.c | 80 |
1 files changed, 42 insertions, 38 deletions
diff --git a/print-ptp.c b/print-ptp.c index 09180110a818..4fc0a4550ed0 100644 --- a/print-ptp.c +++ b/print-ptp.c @@ -292,10 +292,10 @@ static void ptp_print_2(netdissect_options *ndo, const u_char *bp, u_int len); 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) { @@ -344,6 +344,8 @@ print_field(netdissect_options *ndo, const char *st, uint32_t flen, default: break; } + + return bp; } static void @@ -365,47 +367,47 @@ ptp_print_2(netdissect_options *ndo, const u_char *bp, u_int length) foct = GET_U_1(bp); major_sdo_id = (foct & PTP_MAJOR_SDO_ID_MASK) >> 4; - ND_PRINT(", majorSdoId : 0x%x", major_sdo_id); + ND_PRINT(", majorSdoId: 0x%x", major_sdo_id); msg_type = foct & PTP_MSG_TYPE_MASK; - ND_PRINT(", msg type : %s", tok2str(ptp_msg_type, "Reserved", msg_type)); + ND_PRINT(", msg type: %s", tok2str(ptp_msg_type, "Reserved", msg_type)); /* msg length */ - len -= 2; bp += 2; msg_len = GET_BE_U_2(bp); ND_PRINT(", length : %u", msg_len); + len -= 2; bp += 2; msg_len = GET_BE_U_2(bp); ND_PRINT(", length: %u", msg_len); /* domain */ - len -= 2; bp += 2; domain_no = (GET_BE_U_2(bp) & PTP_DOMAIN_MASK) >> 8; ND_PRINT(", domain : %u", domain_no); + len -= 2; bp += 2; domain_no = (GET_BE_U_2(bp) & PTP_DOMAIN_MASK) >> 8; ND_PRINT(", domain: %u", domain_no); /* rsvd 1*/ rsvd1 = GET_BE_U_2(bp) & PTP_RSVD1_MASK; - ND_PRINT(", reserved1 : %u", rsvd1); + ND_PRINT(", reserved1: %u", rsvd1); /* flags */ len -= 2; bp += 2; flags = GET_BE_U_2(bp); ND_PRINT(", Flags [%s]", bittok2str(ptp_flag_values, "none", flags)); /* correction NS (48 bits) */ - len -= 2; bp += 2; ns_corr = GET_BE_U_6(bp); ND_PRINT(", NS correction : %"PRIu64, ns_corr); + len -= 2; bp += 2; ns_corr = GET_BE_U_6(bp); ND_PRINT(", NS correction: %"PRIu64, ns_corr); /* correction sub NS (16 bits) */ - len -= 6; bp += 6; sns_corr = GET_BE_U_2(bp); ND_PRINT(", sub NS correction : %u", sns_corr); + len -= 6; bp += 6; sns_corr = GET_BE_U_2(bp); ND_PRINT(", sub NS correction: %u", sns_corr); /* Reserved 2 */ - len -= 2; bp += 2; rsvd2 = GET_BE_U_4(bp); ND_PRINT(", reserved2 : %u", rsvd2); + len -= 2; bp += 2; rsvd2 = GET_BE_U_4(bp); ND_PRINT(", reserved2: %u", rsvd2); /* clock identity */ - len -= 4; bp += 4; clk_id = GET_BE_U_8(bp); ND_PRINT(", clock identity : 0x%"PRIx64, clk_id); + len -= 4; bp += 4; clk_id = GET_BE_U_8(bp); ND_PRINT(", clock identity: 0x%"PRIx64, clk_id); /* port identity */ - len -= 8; bp += 8; port_id = GET_BE_U_2(bp); ND_PRINT(", port id : %u", port_id); + len -= 8; bp += 8; port_id = GET_BE_U_2(bp); ND_PRINT(", port id: %u", port_id); /* sequence ID */ - len -= 2; bp += 2; seq_id = GET_BE_U_2(bp); ND_PRINT(", seq id : %u", seq_id); + len -= 2; bp += 2; seq_id = GET_BE_U_2(bp); ND_PRINT(", seq id: %u", seq_id); /* control */ len -= 2; bp += 2; control = GET_U_1(bp) ; - ND_PRINT(", control : %u (%s)", control, tok2str(ptp_control_field, "Reserved", control)); + ND_PRINT(", control: %u (%s)", control, tok2str(ptp_control_field, "Reserved", control)); /* log message interval */ - lm_int = GET_BE_U_2(bp) & PTP_LOGMSG_MASK; ND_PRINT(", log message interval : %u", lm_int); len -= 2; bp += 2; + lm_int = GET_BE_U_2(bp) & PTP_LOGMSG_MASK; ND_PRINT(", log message interval: %u", lm_int); len -= 2; bp += 2; switch(msg_type) { case M_SYNC: @@ -489,7 +491,7 @@ ptp_print_timestamp(netdissect_options *ndo, const u_char *bp, u_int *len, const uint64_t secs; uint32_t nsecs; - ND_PRINT(", %s :", stype); + ND_PRINT(", %s:", stype); /* sec time stamp 6 bytes */ secs = GET_BE_U_6(bp); ND_PRINT(" %"PRIu64" seconds,", secs); @@ -511,7 +513,7 @@ ptp_print_timestamp_identity(netdissect_options *ndo, uint16_t port_id; uint64_t port_identity; - ND_PRINT(", %s :", ttype); + ND_PRINT(", %s:", ttype); /* sec time stamp 6 bytes */ secs = GET_BE_U_6(bp); ND_PRINT(" %"PRIu64" seconds,", secs); @@ -526,13 +528,13 @@ ptp_print_timestamp_identity(netdissect_options *ndo, /* port identity*/ port_identity = GET_BE_U_8(bp); - ND_PRINT(", port identity : 0x%"PRIx64, port_identity); + ND_PRINT(", port identity: 0x%"PRIx64, port_identity); *len -= 8; bp += 8; /* port id */ port_id = GET_BE_U_2(bp); - ND_PRINT(", port id : %u", port_id); + ND_PRINT(", port id: %u", port_id); *len -= 2; bp += 2; } @@ -545,7 +547,7 @@ ptp_print_announce_msg(netdissect_options *ndo, const u_char *bp, u_int *len) uint64_t secs; uint32_t nsecs; - ND_PRINT(", %s :", p_origin_ts); + ND_PRINT(", %s:", p_origin_ts); /* sec time stamp 6 bytes */ secs = GET_BE_U_6(bp); ND_PRINT(" %"PRIu64" seconds", secs); @@ -560,61 +562,62 @@ ptp_print_announce_msg(netdissect_options *ndo, const u_char *bp, u_int *len) /* origin cur utc */ origin_cur_utc = GET_BE_U_2(bp); - ND_PRINT(", origin cur utc :%u", origin_cur_utc); + ND_PRINT(", origin cur utc:%u", origin_cur_utc); *len -= 2; bp += 2; /* rsvd */ rsvd = GET_U_1(bp); - ND_PRINT(", rsvd : %u", rsvd); + ND_PRINT(", rsvd: %u", rsvd); *len -= 1; bp += 1; /* gm prio */ gm_prio_1 = GET_U_1(bp); - ND_PRINT(", gm priority_1 : %u", gm_prio_1); + ND_PRINT(", gm priority_1: %u", gm_prio_1); *len -= 1; bp += 1; /* GM clock class */ gm_clk_cls = GET_U_1(bp); - ND_PRINT(", gm clock class : %u", gm_clk_cls); + ND_PRINT(", gm clock class: %u", gm_clk_cls); *len -= 1; bp += 1; /* GM clock accuracy */ gm_clk_acc = GET_U_1(bp); - ND_PRINT(", gm clock accuracy : %u", gm_clk_acc); + ND_PRINT(", gm clock accuracy: %u", gm_clk_acc); *len -= 1; bp += 1; /* GM clock variance */ gm_clk_var = GET_BE_U_2(bp); - ND_PRINT(", gm clock variance : %u", gm_clk_var); + ND_PRINT(", gm clock variance: %u", gm_clk_var); *len -= 2; bp += 2; /* GM Prio 2 */ gm_prio_2 = GET_U_1(bp); - ND_PRINT(", gm priority_2 : %u", gm_prio_2); + ND_PRINT(", gm priority_2: %u", gm_prio_2); *len -= 1; bp += 1; /* GM Clock Identity */ gm_clock_id = GET_BE_U_8(bp); - ND_PRINT(", gm clock id : 0x%"PRIx64, gm_clock_id); + ND_PRINT(", gm clock id: 0x%"PRIx64, gm_clock_id); *len -= 8; bp += 8; /* steps removed */ steps_removed = GET_BE_U_2(bp); - ND_PRINT(", steps removed : %u", steps_removed); + ND_PRINT(", steps removed: %u", steps_removed); *len -= 2; bp += 2; /* Time source */ time_src = GET_U_1(bp); - ND_PRINT(", time source : 0x%x", time_src); + ND_PRINT(", time source: 0x%x", time_src); *len -= 1; 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; @@ -622,24 +625,25 @@ ptp_print_port_id(netdissect_options *ndo, const u_char *bp, u_int *len) /* port identity*/ port_identity = GET_BE_U_8(bp); - ND_PRINT(", port identity : 0x%"PRIx64, port_identity); + ND_PRINT(", port identity: 0x%"PRIx64, port_identity); *len -= 8; bp += 8; /* port id */ port_id = GET_BE_U_2(bp); - ND_PRINT(", port id : %u", port_id); + ND_PRINT(", port id: %u", 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); } |
