]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-cfm.c
CI: Add warning exemptions for Sun C (suncc-5.14) on Solaris 10
[tcpdump] / print-cfm.c
index 2a2485e96d7d7f69fe1227a89ab31c0b583c2d0b..84fd5d9406b5168288849628af354c2666e0dbfa 100644 (file)
 
 /* \summary: IEEE 802.1ag Connectivity Fault Management (CFM) protocols printer */
 
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
+#include <config.h>
 
-#include <netdissect-stdinc.h>
-
-#include <stdio.h>
+#include "netdissect-stdinc.h"
 
 #include "netdissect.h"
 #include "extract.h"
-#include "ether.h"
 #include "addrtoname.h"
 #include "oui.h"
 #include "af.h"
 
+
 struct cfm_common_header_t {
-    uint8_t mdlevel_version;
-    uint8_t opcode;
-    uint8_t flags;
-    uint8_t first_tlv_offset;
+    nd_uint8_t mdlevel_version;
+    nd_uint8_t opcode;
+    nd_uint8_t flags;
+    nd_uint8_t first_tlv_offset;
 };
 
 #define        CFM_VERSION 0
-#define CFM_EXTRACT_VERSION(x) (((x)&0x1f))
+#define CFM_EXTRACT_VERSION(x) ((x)&0x1f)
 #define CFM_EXTRACT_MD_LEVEL(x) (((x)&0xe0)>>5)
 
 #define        CFM_OPCODE_CCM 1
@@ -62,22 +58,22 @@ static const struct tok cfm_opcode_values[] = {
  * Message Formats.
  */
 struct cfm_ccm_t {
-    uint8_t sequence[4];
-    uint8_t ma_epi[2];
-    uint8_t names[48];
-    uint8_t itu_t_y_1731[16];
+    nd_uint32_t sequence;
+    nd_uint16_t ma_epi;
+    nd_byte     names[48];
+    nd_byte     itu_t_y_1731[16];
 };
 
 /*
  * Timer Bases for the CCM Interval field.
  * Expressed in units of seconds.
  */
-static const float ccm_interval_base[8] = {0, 0.003333, 0.01, 0.1, 1, 10, 60, 600};
+static const float ccm_interval_base[8] = {0.0f, 0.003333f, 0.01f, 0.1f, 1.0f, 10.0f, 60.0f, 600.0f};
 #define CCM_INTERVAL_MIN_MULTIPLIER 3.25
 #define CCM_INTERVAL_MAX_MULTIPLIER 3.5
 
 #define CFM_CCM_RDI_FLAG 0x80
-#define CFM_EXTRACT_CCM_INTERVAL(x) (((x)&0x07))
+#define CFM_EXTRACT_CCM_INTERVAL(x) ((x)&0x07)
 
 #define CFM_CCM_MD_FORMAT_8021 0
 #define CFM_CCM_MD_FORMAT_NONE 1
@@ -110,14 +106,14 @@ static const struct tok cfm_ma_nameformat_values[] = {
 };
 
 struct cfm_lbm_t {
-    uint8_t transaction_id[4];
+    nd_uint32_t transaction_id;
 };
 
 struct cfm_ltm_t {
-    uint8_t transaction_id[4];
-    uint8_t ttl;
-    uint8_t original_mac[ETHER_ADDR_LEN];
-    uint8_t target_mac[ETHER_ADDR_LEN];
+    nd_uint32_t transaction_id;
+    nd_uint8_t  ttl;
+    nd_mac48 original_mac;
+    nd_mac48 target_mac;
 };
 
 static const struct tok cfm_ltm_flag_values[] = {
@@ -126,9 +122,9 @@ static const struct tok cfm_ltm_flag_values[] = {
 };
 
 struct cfm_ltr_t {
-    uint8_t transaction_id[4];
-    uint8_t ttl;
-    uint8_t replay_action;
+    nd_uint32_t transaction_id;
+    nd_uint8_t  ttl;
+    nd_uint8_t  replay_action;
 };
 
 static const struct tok cfm_ltr_flag_values[] = {
@@ -172,8 +168,8 @@ static const struct tok cfm_tlv_values[] = {
  */
 
 struct cfm_tlv_header_t {
-    uint8_t type;
-    uint8_t length[2];
+    nd_uint8_t  type;
+    nd_uint16_t length;
 };
 
 /* FIXME define TLV formats */
@@ -217,46 +213,46 @@ static const struct tok cfm_tlv_senderid_chassisid_values[] = {
 
 static int
 cfm_network_addr_print(netdissect_options *ndo,
-                       register const u_char *tptr, const u_int length)
+                       const u_char *tptr, const u_int length)
 {
     u_int network_addr_type;
     u_int hexdump =  FALSE;
 
     /*
-     * Although AFIs are typically 2 octects wide,
+     * Although AFIs are typically 2 octets wide,
      * 802.1ab specifies that this field width
      * is only one octet.
      */
     if (length < 1) {
-        ND_PRINT((ndo, "\n\t  Network Address Type (invalid, no data"));
+        ND_PRINT("\n\t  Network Address Type (invalid, no data");
         return hexdump;
     }
     /* The calling function must make any due ND_TCHECK calls. */
-    network_addr_type = EXTRACT_U_1(tptr);
-    ND_PRINT((ndo, "\n\t  Network Address Type %s (%u)",
+    network_addr_type = GET_U_1(tptr);
+    ND_PRINT("\n\t  Network Address Type %s (%u)",
            tok2str(af_values, "Unknown", network_addr_type),
-           network_addr_type));
+           network_addr_type);
 
     /*
      * Resolve the passed in Address.
      */
     switch(network_addr_type) {
-    case AFNUM_INET:
+    case AFNUM_IP:
         if (length != 1 + 4) {
-            ND_PRINT((ndo, "(invalid IPv4 address length %u)", length - 1));
+            ND_PRINT("(invalid IPv4 address length %u)", length - 1);
             hexdump = TRUE;
             break;
         }
-        ND_PRINT((ndo, ", %s", ipaddr_string(ndo, tptr + 1)));
+        ND_PRINT(", %s", GET_IPADDR_STRING(tptr + 1));
         break;
 
-    case AFNUM_INET6:
+    case AFNUM_IP6:
         if (length != 1 + 16) {
-            ND_PRINT((ndo, "(invalid IPv6 address length %u)", length - 1));
+            ND_PRINT("(invalid IPv6 address length %u)", length - 1);
             hexdump = TRUE;
             break;
         }
-        ND_PRINT((ndo, ", %s", ip6addr_string(ndo, tptr + 1)));
+        ND_PRINT(", %s", GET_IP6ADDR_STRING(tptr + 1));
         break;
 
     default:
@@ -269,9 +265,10 @@ cfm_network_addr_print(netdissect_options *ndo,
 
 void
 cfm_print(netdissect_options *ndo,
-          register const u_char *pptr, register u_int length)
+          const u_char *pptr, u_int length)
 {
     const struct cfm_common_header_t *cfm_common_header;
+    uint8_t mdlevel_version, opcode, flags, first_tlv_offset;
     const struct cfm_tlv_header_t *cfm_tlv_header;
     const uint8_t *tptr, *tlv_ptr;
     const uint8_t *namesp;
@@ -290,26 +287,29 @@ cfm_print(netdissect_options *ndo,
         const struct cfm_ltr_t *cfm_ltr;
     } msg_ptr;
 
+    ndo->ndo_protocol = "cfm";
     tptr=pptr;
     cfm_common_header = (const struct cfm_common_header_t *)pptr;
     if (length < sizeof(*cfm_common_header))
         goto tooshort;
-    ND_TCHECK(*cfm_common_header);
+    ND_TCHECK_SIZE(cfm_common_header);
 
     /*
      * Sanity checking of the header.
      */
-    if (CFM_EXTRACT_VERSION(cfm_common_header->mdlevel_version) != CFM_VERSION) {
-       ND_PRINT((ndo, "CFMv%u not supported, length %u",
-               CFM_EXTRACT_VERSION(cfm_common_header->mdlevel_version), length));
+    mdlevel_version = GET_U_1(cfm_common_header->mdlevel_version);
+    if (CFM_EXTRACT_VERSION(mdlevel_version) != CFM_VERSION) {
+       ND_PRINT("CFMv%u not supported, length %u",
+               CFM_EXTRACT_VERSION(mdlevel_version), length);
        return;
     }
 
-    ND_PRINT((ndo, "CFMv%u %s, MD Level %u, length %u",
-           CFM_EXTRACT_VERSION(cfm_common_header->mdlevel_version),
-           tok2str(cfm_opcode_values, "unknown (%u)", cfm_common_header->opcode),
-           CFM_EXTRACT_MD_LEVEL(cfm_common_header->mdlevel_version),
-           length));
+    opcode = GET_U_1(cfm_common_header->opcode);
+    ND_PRINT("CFMv%u %s, MD Level %u, length %u",
+           CFM_EXTRACT_VERSION(mdlevel_version),
+           tok2str(cfm_opcode_values, "unknown (%u)", opcode),
+           CFM_EXTRACT_MD_LEVEL(mdlevel_version),
+           length);
 
     /*
      * In non-verbose mode just print the opcode and md-level.
@@ -318,7 +318,9 @@ cfm_print(netdissect_options *ndo,
         return;
     }
 
-    ND_PRINT((ndo, "\n\tFirst TLV offset %u", cfm_common_header->first_tlv_offset));
+    flags = GET_U_1(cfm_common_header->flags);
+    first_tlv_offset = GET_U_1(cfm_common_header->first_tlv_offset);
+    ND_PRINT("\n\tFirst TLV offset %u", first_tlv_offset);
 
     tptr += sizeof(struct cfm_common_header_t);
     tlen = length - sizeof(struct cfm_common_header_t);
@@ -326,43 +328,43 @@ cfm_print(netdissect_options *ndo,
     /*
      * Sanity check the first TLV offset.
      */
-    if (cfm_common_header->first_tlv_offset > tlen) {
-        ND_PRINT((ndo, " (too large, must be <= %u)", tlen));
+    if (first_tlv_offset > tlen) {
+        ND_PRINT(" (too large, must be <= %u)", tlen);
         return;
     }
 
-    switch (cfm_common_header->opcode) {
+    switch (opcode) {
     case CFM_OPCODE_CCM:
         msg_ptr.cfm_ccm = (const struct cfm_ccm_t *)tptr;
-        if (cfm_common_header->first_tlv_offset < sizeof(*msg_ptr.cfm_ccm)) {
-            ND_PRINT((ndo, " (too small 1, must be >= %lu)",
-                     (unsigned long) sizeof(*msg_ptr.cfm_ccm)));
+        if (first_tlv_offset < sizeof(*msg_ptr.cfm_ccm)) {
+            ND_PRINT(" (too small 1, must be >= %zu)",
+                     sizeof(*msg_ptr.cfm_ccm));
             return;
         }
         if (tlen < sizeof(*msg_ptr.cfm_ccm))
             goto tooshort;
-        ND_TCHECK(*msg_ptr.cfm_ccm);
+        ND_TCHECK_SIZE(msg_ptr.cfm_ccm);
 
-        ccm_interval = CFM_EXTRACT_CCM_INTERVAL(cfm_common_header->flags);
-        ND_PRINT((ndo, ", Flags [CCM Interval %u%s]",
+        ccm_interval = CFM_EXTRACT_CCM_INTERVAL(flags);
+        ND_PRINT(", Flags [CCM Interval %u%s]",
                ccm_interval,
-               cfm_common_header->flags & CFM_CCM_RDI_FLAG ?
-               ", RDI" : ""));
+               flags & CFM_CCM_RDI_FLAG ?
+               ", RDI" : "");
 
         /*
          * Resolve the CCM interval field.
          */
         if (ccm_interval) {
-            ND_PRINT((ndo, "\n\t  CCM Interval %.3fs"
+            ND_PRINT("\n\t  CCM Interval %.3fs"
                    ", min CCM Lifetime %.3fs, max CCM Lifetime %.3fs",
                    ccm_interval_base[ccm_interval],
                    ccm_interval_base[ccm_interval] * CCM_INTERVAL_MIN_MULTIPLIER,
-                   ccm_interval_base[ccm_interval] * CCM_INTERVAL_MAX_MULTIPLIER));
+                   ccm_interval_base[ccm_interval] * CCM_INTERVAL_MAX_MULTIPLIER);
         }
 
-        ND_PRINT((ndo, "\n\t  Sequence Number 0x%08x, MA-End-Point-ID 0x%04x",
-               EXTRACT_BE_U_4(msg_ptr.cfm_ccm->sequence),
-               EXTRACT_BE_U_2(msg_ptr.cfm_ccm->ma_epi)));
+        ND_PRINT("\n\t  Sequence Number 0x%08x, MA-End-Point-ID 0x%04x",
+               GET_BE_U_4(msg_ptr.cfm_ccm->sequence),
+               GET_BE_U_2(msg_ptr.cfm_ccm->ma_epi));
 
         namesp = msg_ptr.cfm_ccm->names;
         names_data_remaining = sizeof(msg_ptr.cfm_ccm->names);
@@ -370,42 +372,41 @@ cfm_print(netdissect_options *ndo,
         /*
          * Resolve the MD fields.
          */
-        md_nameformat = *namesp;
+        md_nameformat = GET_U_1(namesp);
         namesp++;
         names_data_remaining--;  /* We know this is != 0 */
         if (md_nameformat != CFM_CCM_MD_FORMAT_NONE) {
-            md_namelength = *namesp;
+            md_namelength = GET_U_1(namesp);
             namesp++;
             names_data_remaining--; /* We know this is !=0 */
-            ND_PRINT((ndo, "\n\t  MD Name Format %s (%u), MD Name length %u",
+            ND_PRINT("\n\t  MD Name Format %s (%u), MD Name length %u",
                    tok2str(cfm_md_nameformat_values, "Unknown",
                            md_nameformat),
                    md_nameformat,
-                   md_namelength));
+                   md_namelength);
 
             /*
              * -3 for the MA short name format and length and one byte
              * of MA short name.
              */
             if (md_namelength > names_data_remaining - 3) {
-                ND_PRINT((ndo, " (too large, must be <= %u)", names_data_remaining - 2));
+                ND_PRINT(" (too large, must be <= %u)", names_data_remaining - 2);
                 return;
             }
 
             md_name = namesp;
-            ND_PRINT((ndo, "\n\t  MD Name: "));
+            ND_PRINT("\n\t  MD Name: ");
             switch (md_nameformat) {
             case CFM_CCM_MD_FORMAT_DNS:
             case CFM_CCM_MD_FORMAT_CHAR:
-                safeputs(ndo, md_name, md_namelength);
+                nd_printjnp(ndo, md_name, md_namelength);
                 break;
 
             case CFM_CCM_MD_FORMAT_MAC:
-                if (md_namelength == 6) {
-                    ND_PRINT((ndo, "\n\t  MAC %s", etheraddr_string(ndo,
-                               md_name)));
+                if (md_namelength == MAC48_LEN) {
+                    ND_PRINT("\n\t  MAC %s", GET_MAC48_STRING(md_name));
                 } else {
-                    ND_PRINT((ndo, "\n\t  MAC (length invalid)"));
+                    ND_PRINT("\n\t  MAC (length invalid)");
                 }
                 break;
 
@@ -418,38 +419,38 @@ cfm_print(netdissect_options *ndo,
             namesp += md_namelength;
             names_data_remaining -= md_namelength;
         } else {
-            ND_PRINT((ndo, "\n\t  MD Name Format %s (%u)",
+            ND_PRINT("\n\t  MD Name Format %s (%u)",
                    tok2str(cfm_md_nameformat_values, "Unknown",
                            md_nameformat),
-                   md_nameformat));
+                   md_nameformat);
         }
 
 
         /*
          * Resolve the MA fields.
          */
-        ma_nameformat = *namesp;
+        ma_nameformat = GET_U_1(namesp);
         namesp++;
         names_data_remaining--; /* We know this is != 0 */
-        ma_namelength = *namesp;
+        ma_namelength = GET_U_1(namesp);
         namesp++;
         names_data_remaining--; /* We know this is != 0 */
-        ND_PRINT((ndo, "\n\t  MA Name-Format %s (%u), MA name length %u",
+        ND_PRINT("\n\t  MA Name-Format %s (%u), MA name length %u",
                tok2str(cfm_ma_nameformat_values, "Unknown",
                        ma_nameformat),
                ma_nameformat,
-               ma_namelength));
+               ma_namelength);
 
         if (ma_namelength > names_data_remaining) {
-            ND_PRINT((ndo, " (too large, must be <= %u)", names_data_remaining));
+            ND_PRINT(" (too large, must be <= %u)", names_data_remaining);
             return;
         }
 
         ma_name = namesp;
-        ND_PRINT((ndo, "\n\t  MA Name: "));
+        ND_PRINT("\n\t  MA Name: ");
         switch (ma_nameformat) {
         case CFM_CCM_MA_FORMAT_CHAR:
-            safeputs(ndo, ma_name, ma_namelength);
+            nd_printjnp(ndo, ma_name, ma_namelength);
             break;
 
             /* FIXME add printers for those MA formats - hexdump for now */
@@ -464,50 +465,50 @@ cfm_print(netdissect_options *ndo,
 
     case CFM_OPCODE_LTM:
         msg_ptr.cfm_ltm = (const struct cfm_ltm_t *)tptr;
-        if (cfm_common_header->first_tlv_offset < sizeof(*msg_ptr.cfm_ltm)) {
-            ND_PRINT((ndo, " (too small 4, must be >= %lu)",
-                     (unsigned long) sizeof(*msg_ptr.cfm_ltm)));
+        if (first_tlv_offset < sizeof(*msg_ptr.cfm_ltm)) {
+            ND_PRINT(" (too small 4, must be >= %zu)",
+                     sizeof(*msg_ptr.cfm_ltm));
             return;
         }
         if (tlen < sizeof(*msg_ptr.cfm_ltm))
             goto tooshort;
-        ND_TCHECK(*msg_ptr.cfm_ltm);
+        ND_TCHECK_SIZE(msg_ptr.cfm_ltm);
 
-        ND_PRINT((ndo, ", Flags [%s]",
-               bittok2str(cfm_ltm_flag_values, "none", cfm_common_header->flags)));
+        ND_PRINT(", Flags [%s]",
+               bittok2str(cfm_ltm_flag_values, "none", flags));
 
-        ND_PRINT((ndo, "\n\t  Transaction-ID 0x%08x, ttl %u",
-               EXTRACT_BE_U_4(msg_ptr.cfm_ltm->transaction_id),
-               msg_ptr.cfm_ltm->ttl));
+        ND_PRINT("\n\t  Transaction-ID 0x%08x, ttl %u",
+               GET_BE_U_4(msg_ptr.cfm_ltm->transaction_id),
+               GET_U_1(msg_ptr.cfm_ltm->ttl));
 
-        ND_PRINT((ndo, "\n\t  Original-MAC %s, Target-MAC %s",
-               etheraddr_string(ndo, msg_ptr.cfm_ltm->original_mac),
-               etheraddr_string(ndo, msg_ptr.cfm_ltm->target_mac)));
+        ND_PRINT("\n\t  Original-MAC %s, Target-MAC %s",
+               GET_MAC48_STRING(msg_ptr.cfm_ltm->original_mac),
+               GET_MAC48_STRING(msg_ptr.cfm_ltm->target_mac));
         break;
 
     case CFM_OPCODE_LTR:
         msg_ptr.cfm_ltr = (const struct cfm_ltr_t *)tptr;
-        if (cfm_common_header->first_tlv_offset < sizeof(*msg_ptr.cfm_ltr)) {
-            ND_PRINT((ndo, " (too small 5, must be >= %lu)",
-                     (unsigned long) sizeof(*msg_ptr.cfm_ltr)));
+        if (first_tlv_offset < sizeof(*msg_ptr.cfm_ltr)) {
+            ND_PRINT(" (too small 5, must be >= %zu)",
+                     sizeof(*msg_ptr.cfm_ltr));
             return;
         }
         if (tlen < sizeof(*msg_ptr.cfm_ltr))
             goto tooshort;
-        ND_TCHECK(*msg_ptr.cfm_ltr);
+        ND_TCHECK_SIZE(msg_ptr.cfm_ltr);
 
-        ND_PRINT((ndo, ", Flags [%s]",
-               bittok2str(cfm_ltr_flag_values, "none", cfm_common_header->flags)));
+        ND_PRINT(", Flags [%s]",
+               bittok2str(cfm_ltr_flag_values, "none", flags));
 
-        ND_PRINT((ndo, "\n\t  Transaction-ID 0x%08x, ttl %u",
-               EXTRACT_BE_U_4(msg_ptr.cfm_ltr->transaction_id),
-               msg_ptr.cfm_ltr->ttl));
+        ND_PRINT("\n\t  Transaction-ID 0x%08x, ttl %u",
+               GET_BE_U_4(msg_ptr.cfm_ltr->transaction_id),
+               GET_U_1(msg_ptr.cfm_ltr->ttl));
 
-        ND_PRINT((ndo, "\n\t  Replay-Action %s (%u)",
+        ND_PRINT("\n\t  Replay-Action %s (%u)",
                tok2str(cfm_ltr_replay_action_values,
                        "Unknown",
-                       msg_ptr.cfm_ltr->replay_action),
-               msg_ptr.cfm_ltr->replay_action));
+                       GET_U_1(msg_ptr.cfm_ltr->replay_action)),
+               GET_U_1(msg_ptr.cfm_ltr->replay_action));
         break;
 
         /*
@@ -518,23 +519,22 @@ cfm_print(netdissect_options *ndo,
     case CFM_OPCODE_LBM:
     default:
         print_unknown_data(ndo, tptr, "\n\t  ",
-                           tlen -  cfm_common_header->first_tlv_offset);
+                           tlen -  first_tlv_offset);
         break;
     }
 
-    tptr += cfm_common_header->first_tlv_offset;
-    tlen -= cfm_common_header->first_tlv_offset;
+    tptr += first_tlv_offset;
+    tlen -= first_tlv_offset;
 
-    while (tlen > 0) {
+    while (tlen != 0) {
         cfm_tlv_header = (const struct cfm_tlv_header_t *)tptr;
 
         /* Enough to read the tlv type ? */
-        ND_TCHECK_1(tptr);
-        cfm_tlv_type=cfm_tlv_header->type;
+        cfm_tlv_type = GET_U_1(cfm_tlv_header->type);
 
-        ND_PRINT((ndo, "\n\t%s TLV (0x%02x)",
+        ND_PRINT("\n\t%s TLV (0x%02x)",
                tok2str(cfm_tlv_values, "Unknown", cfm_tlv_type),
-               cfm_tlv_type));
+               cfm_tlv_type);
 
         if (cfm_tlv_type == CFM_TLV_END) {
             /* Length is "Not present if the Type field is 0." */
@@ -544,10 +544,10 @@ cfm_print(netdissect_options *ndo,
         /* do we have the full tlv header ? */
         if (tlen < sizeof(struct cfm_tlv_header_t))
             goto tooshort;
-        ND_TCHECK2(*tptr, sizeof(struct cfm_tlv_header_t));
-        cfm_tlv_len=EXTRACT_BE_U_2(&cfm_tlv_header->length);
+        ND_TCHECK_LEN(tptr, sizeof(struct cfm_tlv_header_t));
+        cfm_tlv_len=GET_BE_U_2(cfm_tlv_header->length);
 
-        ND_PRINT((ndo, ", length %u", cfm_tlv_len));
+        ND_PRINT(", length %u", cfm_tlv_len);
 
         tptr += sizeof(struct cfm_tlv_header_t);
         tlen -= sizeof(struct cfm_tlv_header_t);
@@ -556,39 +556,39 @@ cfm_print(netdissect_options *ndo,
         /* do we have the full tlv ? */
         if (tlen < cfm_tlv_len)
             goto tooshort;
-        ND_TCHECK2(*tptr, cfm_tlv_len);
+        ND_TCHECK_LEN(tptr, cfm_tlv_len);
         hexdump = FALSE;
 
         switch(cfm_tlv_type) {
         case CFM_TLV_PORT_STATUS:
             if (cfm_tlv_len < 1) {
-                ND_PRINT((ndo, " (too short, must be >= 1)"));
+                ND_PRINT(" (too short, must be >= 1)");
                 return;
             }
-            ND_PRINT((ndo, ", Status: %s (%u)",
-                   tok2str(cfm_tlv_port_status_values, "Unknown", EXTRACT_U_1(tptr)),
-                   EXTRACT_U_1(tptr)));
+            ND_PRINT(", Status: %s (%u)",
+                   tok2str(cfm_tlv_port_status_values, "Unknown", GET_U_1(tptr)),
+                   GET_U_1(tptr));
             break;
 
         case CFM_TLV_INTERFACE_STATUS:
             if (cfm_tlv_len < 1) {
-                ND_PRINT((ndo, " (too short, must be >= 1)"));
+                ND_PRINT(" (too short, must be >= 1)");
                 return;
             }
-            ND_PRINT((ndo, ", Status: %s (%u)",
-                   tok2str(cfm_tlv_interface_status_values, "Unknown", EXTRACT_U_1(tptr)),
-                   EXTRACT_U_1(tptr)));
+            ND_PRINT(", Status: %s (%u)",
+                   tok2str(cfm_tlv_interface_status_values, "Unknown", GET_U_1(tptr)),
+                   GET_U_1(tptr));
             break;
 
         case CFM_TLV_PRIVATE:
             if (cfm_tlv_len < 4) {
-                ND_PRINT((ndo, " (too short, must be >= 4)"));
+                ND_PRINT(" (too short, must be >= 4)");
                 return;
             }
-            ND_PRINT((ndo, ", Vendor: %s (%u), Sub-Type %u",
-                   tok2str(oui_values,"Unknown", EXTRACT_BE_U_3(tptr)),
-                   EXTRACT_BE_U_3(tptr),
-                   EXTRACT_U_1(tptr + 3)));
+            ND_PRINT(", Vendor: %s (%u), Sub-Type %u",
+                   tok2str(oui_values,"Unknown", GET_BE_U_3(tptr)),
+                   GET_BE_U_3(tptr),
+                   GET_U_1(tptr + 3));
             hexdump = TRUE;
             break;
 
@@ -598,7 +598,7 @@ cfm_print(netdissect_options *ndo,
             u_int mgmt_addr_length;
 
             if (cfm_tlv_len < 1) {
-                ND_PRINT((ndo, " (too short, must be >= 1)"));
+                ND_PRINT(" (too short, must be >= 1)");
                 goto next_tlv;
             }
 
@@ -606,7 +606,7 @@ cfm_print(netdissect_options *ndo,
              * Get the Chassis ID length and check it.
              * IEEE 802.1Q-2014 Section 21.5.3.1
              */
-            chassis_id_length = EXTRACT_U_1(tptr);
+            chassis_id_length = GET_U_1(tptr);
             tptr++;
             tlen--;
             cfm_tlv_len--;
@@ -618,32 +618,32 @@ cfm_print(netdissect_options *ndo,
                  * IEEE 802.1AB-2016 Section 8.5.2.2: chassis ID subtype
                  */
                 if (cfm_tlv_len < 1) {
-                    ND_PRINT((ndo, "\n\t  (TLV too short)"));
+                    ND_PRINT("\n\t  (TLV too short)");
                     goto next_tlv;
                 }
-                chassis_id_type = EXTRACT_U_1(tptr);
+                chassis_id_type = GET_U_1(tptr);
                 cfm_tlv_len--;
-                ND_PRINT((ndo, "\n\t  Chassis-ID Type %s (%u), Chassis-ID length %u",
+                ND_PRINT("\n\t  Chassis-ID Type %s (%u), Chassis-ID length %u",
                        tok2str(cfm_tlv_senderid_chassisid_values,
                                "Unknown",
                                chassis_id_type),
                        chassis_id_type,
-                       chassis_id_length));
+                       chassis_id_length);
 
                 if (cfm_tlv_len < chassis_id_length) {
-                    ND_PRINT((ndo, "\n\t  (TLV too short)"));
+                    ND_PRINT("\n\t  (TLV too short)");
                     goto next_tlv;
                 }
 
                 /* IEEE 802.1Q-2014 Section 21.5.3.3: Chassis ID */
                 switch (chassis_id_type) {
                 case CFM_CHASSIS_ID_MAC_ADDRESS:
-                    if (chassis_id_length != ETHER_ADDR_LEN) {
-                        ND_PRINT((ndo, " (invalid MAC address length)"));
+                    if (chassis_id_length != MAC48_LEN) {
+                        ND_PRINT(" (invalid MAC address length)");
                         hexdump = TRUE;
                         break;
                     }
-                    ND_PRINT((ndo, "\n\t  MAC %s", etheraddr_string(ndo, tptr + 1)));
+                    ND_PRINT("\n\t  MAC %s", GET_MAC48_STRING(tptr + 1));
                     break;
 
                 case CFM_CHASSIS_ID_NETWORK_ADDRESS:
@@ -655,7 +655,7 @@ cfm_print(netdissect_options *ndo,
                 case CFM_CHASSIS_ID_LOCAL:
                 case CFM_CHASSIS_ID_CHASSIS_COMPONENT:
                 case CFM_CHASSIS_ID_PORT_COMPONENT:
-                    safeputs(ndo, tptr + 1, chassis_id_length);
+                    nd_printjnp(ndo, tptr + 1, chassis_id_length);
                     break;
 
                 default:
@@ -680,15 +680,15 @@ cfm_print(netdissect_options *ndo,
             }
 
             /* Here mgmt_addr_length stands for the management domain length. */
-            mgmt_addr_length = EXTRACT_U_1(tptr);
+            mgmt_addr_length = GET_U_1(tptr);
             tptr++;
             tlen--;
             cfm_tlv_len--;
-            ND_PRINT((ndo, "\n\t  Management Address Domain Length %u", mgmt_addr_length));
+            ND_PRINT("\n\t  Management Address Domain Length %u", mgmt_addr_length);
             if (mgmt_addr_length) {
                 /* IEEE 802.1Q-2014 Section 21.5.3.5: Management Address Domain */
                 if (cfm_tlv_len < mgmt_addr_length) {
-                    ND_PRINT((ndo, "\n\t  (TLV too short)"));
+                    ND_PRINT("\n\t  (TLV too short)");
                     goto next_tlv;
                 }
                 cfm_tlv_len -= mgmt_addr_length;
@@ -704,21 +704,21 @@ cfm_print(netdissect_options *ndo,
                  * This field is present if Management Address Domain Length is not 0.
                  */
                 if (cfm_tlv_len < 1) {
-                    ND_PRINT((ndo, " (Management Address Length is missing)"));
+                    ND_PRINT(" (Management Address Length is missing)");
                     hexdump = TRUE;
                     break;
                 }
 
                 /* Here mgmt_addr_length stands for the management address length. */
-                mgmt_addr_length = EXTRACT_U_1(tptr);
+                mgmt_addr_length = GET_U_1(tptr);
                 tptr++;
                 tlen--;
                 cfm_tlv_len--;
-                ND_PRINT((ndo, "\n\t  Management Address Length %u", mgmt_addr_length));
+                ND_PRINT("\n\t  Management Address Length %u", mgmt_addr_length);
                 if (mgmt_addr_length) {
                     /* IEEE 802.1Q-2014 Section 21.5.3.7: Management Address */
                     if (cfm_tlv_len < mgmt_addr_length) {
-                        ND_PRINT((ndo, "\n\t  (TLV too short)"));
+                        ND_PRINT("\n\t  (TLV too short)");
                         return;
                     }
                     cfm_tlv_len -= mgmt_addr_length;
@@ -756,9 +756,9 @@ next_tlv:
     return;
 
 tooshort:
-    ND_PRINT((ndo, "\n\t\t packet is too short"));
+    ND_PRINT("\n\t\t packet is too short");
     return;
 
 trunc:
-    ND_PRINT((ndo, "\n\t\t packet exceeded snapshot"));
+    nd_print_trunc(ndo);
 }