]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-ptp.c
icmp: clean up the extension code and comments.
[tcpdump] / print-ptp.c
index abf0bd39e984e7b46623fb6147789d467619c67d..c4ff02042e4ef2e480908aa20f1521fa38e6fce2 100644 (file)
@@ -24,7 +24,6 @@
 #include "netdissect-stdinc.h"
 #include "netdissect.h"
 #include "extract.h"
-#include <string.h>
 
 /*
  * PTP header
  *    |                         Nano Seconds                          |
  *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  *
- *  Delay Resp Message (msg type = 0x9)
+ *  Delay Resp Message (msg type=0x9)
  *     0                   1                   2                   3
  *     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  *                                    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  *                                    | Requesting Port Identity      |
  *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  *
- *  Management Message (msg_type=0xD)
+ *  Management Message (msg type=0xD)
  *     0                   1                   2                   3
  *     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  *                                    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -259,9 +258,9 @@ static const struct tok ptp_flag_values[] = {
             ND_PRINT("(%s)", tok2str(ptp_msg_type, "unknown", e)); \
         }
 
-const char *p_porigin_ts = "preciseOriginTimeStamp";
-const char *p_origin_ts = "originTimeStamp";
-const char *p_recv_ts = "recieveTimeStamp";
+static const char *p_porigin_ts = "preciseOriginTimeStamp";
+static const char *p_origin_ts = "originTimeStamp";
+static const char *p_recv_ts = "receiveTimeStamp";
 
 #define PTP_VER_1 0x1
 #define PTP_VER_2 0x2
@@ -337,14 +336,15 @@ print_field(netdissect_options *ndo, const char *st, uint32_t flen,
 static void
 ptp_print_1(netdissect_options *ndo)
 {
-    ND_PRINT("ptp version 1: not implemented\n");
+    ND_PRINT(" (not implemented)");
 }
 
-static void ptp_print_2(netdissect_options *ndo, const u_char *bp, u_int length)
+static void
+ptp_print_2(netdissect_options *ndo, const u_char *bp, u_int length)
 {
     u_int len = length;
-    uint16_t msg_len, flags, seq_id;
-    uint8_t foct, domain_no, msg_type, v1_compat, rsvd1, port_id, lm_int, control;
+    uint16_t msg_len, flags, port_id, seq_id;
+    uint8_t foct, domain_no, msg_type, v1_compat, rsvd1, lm_int, control;
     uint32_t ns_corr, sns_corr, rsvd2;
     uint64_t clk_id;
 
@@ -358,7 +358,7 @@ static void ptp_print_2(netdissect_options *ndo, const u_char *bp, u_int length)
     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; 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;
@@ -374,7 +374,7 @@ static void ptp_print_2(netdissect_options *ndo, const u_char *bp, u_int length)
     len -= 4; bp += 4; sns_corr = GET_BE_U_4(bp); ND_PRINT(", sub NS correction : %u", sns_corr);
 
     /* Reserved 2 */
-    len -= 4; bp += 4; rsvd2 = GET_BE_U_4(bp); ND_PRINT(", sub NS correction : 0x%x", rsvd2);
+    len -= 4; bp += 4; 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);
@@ -431,14 +431,12 @@ static void ptp_print_2(netdissect_options *ndo, const u_char *bp, u_int length)
  * PTP general message
  */
 void
-ptp_print(netdissect_options *ndo, const u_char *bp, u_int len)
+ptp_print(netdissect_options *ndo, const u_char *bp, u_int length)
 {
     u_int vers;
 
     ndo->ndo_protocol = "ptp";
-    if (len < PTP_HDR_LEN) {
-        goto trunc;
-    }
+    ND_ICHECK_U(length, <, PTP_HDR_LEN);
     vers = GET_BE_U_2(bp) & PTP_VERS_MASK;
     ND_PRINT("PTPv%u",vers);
     switch(vers) {
@@ -446,7 +444,7 @@ ptp_print(netdissect_options *ndo, const u_char *bp, u_int len)
             ptp_print_1(ndo);
             break;
         case PTP_VER_2:
-            ptp_print_2(ndo, bp, len);
+            ptp_print_2(ndo, bp, length);
             break;
         default:
             //ND_PRINT("ERROR: unknown-version\n");
@@ -454,9 +452,8 @@ ptp_print(netdissect_options *ndo, const u_char *bp, u_int len)
     }
     return;
 
-trunc:
-    nd_print_trunc(ndo);
-    return;
+invalid:
+    nd_print_invalid(ndo);
 }
 
 static void
@@ -465,9 +462,9 @@ 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_2(bp) + GET_BE_U_4(bp+2);
+    secs = GET_BE_U_6(bp);
     ND_PRINT(" %"PRIu64" seconds,", secs);
     *len -= 6;
     bp += 6;
@@ -487,9 +484,9 @@ 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_2(bp) + GET_BE_U_4(bp+2);
+    secs = GET_BE_U_6(bp);
     ND_PRINT(" %"PRIu64" seconds,", secs);
     *len -= 6;
     bp += 6;
@@ -521,9 +518,9 @@ 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_2(bp) + GET_BE_U_4(bp+2);
+    secs = GET_BE_U_6(bp);
     ND_PRINT(" %"PRIu64" seconds", secs);
     *len -= 6;
     bp += 6;