]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-pgm.c
Add EXTRACT_ calls.
[tcpdump] / print-pgm.c
index 0d5685d9e42abdcf10d1c2c558d2ff51d4413748..1cf9bd20dd8f8a01c9c685f9a35004f61e19b678 100644 (file)
@@ -13,6 +13,8 @@
  * Original code by Andy Heffernan ([email protected])
  */
 
+/* \summary: Pragmatic General Multicast (PGM) printer */
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -142,16 +144,16 @@ typedef enum _pgm_type {
 
 void
 pgm_print(netdissect_options *ndo,
-          register const u_char *bp, register u_int length,
-          register const u_char *bp2)
+          const u_char *bp, u_int length,
+          const u_char *bp2)
 {
-       register const struct pgm_header *pgm;
-       register const struct ip *ip;
-       register char ch;
+       const struct pgm_header *pgm;
+       const struct ip *ip;
+       char ch;
        uint16_t sport, dport;
        u_int nla_afnum;
        char nla_buf[INET6_ADDRSTRLEN];
-       register const struct ip6_hdr *ip6;
+       const struct ip6_hdr *ip6;
        uint8_t opt_type, opt_len;
        uint32_t seq, opts_len, len, offset;
 
@@ -167,20 +169,19 @@ pgm_print(netdissect_options *ndo,
                        ND_PRINT((ndo, "%s > %s: [|pgm]",
                                ip6addr_string(ndo, &ip6->ip6_src),
                                ip6addr_string(ndo, &ip6->ip6_dst)));
-                       return;
                } else {
                        ND_PRINT((ndo, "%s > %s: [|pgm]",
                                ipaddr_string(ndo, &ip->ip_src),
                                ipaddr_string(ndo, &ip->ip_dst)));
-                       return;
                }
+               return;
        }
 
-       sport = EXTRACT_16BITS(&pgm->pgm_sport);
-       dport = EXTRACT_16BITS(&pgm->pgm_dport);
+       sport = EXTRACT_BE_U_2(&pgm->pgm_sport);
+       dport = EXTRACT_BE_U_2(&pgm->pgm_dport);
 
        if (ip6) {
-               if (ip6->ip6_nxt == IPPROTO_PGM) {
+               if (EXTRACT_U_1(ip6->ip6_nxt) == IPPROTO_PGM) {
                        ND_PRINT((ndo, "%s.%s > %s.%s: ",
                                ip6addr_string(ndo, &ip6->ip6_src),
                                tcpport_string(ndo, sport),
@@ -191,7 +192,7 @@ pgm_print(netdissect_options *ndo,
                                tcpport_string(ndo, sport), tcpport_string(ndo, dport)));
                }
        } else {
-               if (ip->ip_p == IPPROTO_PGM) {
+               if (EXTRACT_U_1(ip->ip_p) == IPPROTO_PGM) {
                        ND_PRINT((ndo, "%s.%s > %s.%s: ",
                                ipaddr_string(ndo, &ip->ip_src),
                                tcpport_string(ndo, sport),
@@ -205,7 +206,7 @@ pgm_print(netdissect_options *ndo,
 
        ND_TCHECK(*pgm);
 
-        ND_PRINT((ndo, "PGM, length %u", EXTRACT_16BITS(&pgm->pgm_length)));
+        ND_PRINT((ndo, "PGM, length %u", EXTRACT_BE_U_2(&pgm->pgm_length)));
 
         if (!ndo->ndo_vflag)
             return;
@@ -225,14 +226,14 @@ pgm_print(netdissect_options *ndo,
            ND_TCHECK(*spm);
            bp = (const u_char *) (spm + 1);
 
-           switch (EXTRACT_16BITS(&spm->pgms_nla_afi)) {
+           switch (EXTRACT_BE_U_2(&spm->pgms_nla_afi)) {
            case AFNUM_INET:
-               ND_TCHECK2(*bp, sizeof(struct in_addr));
+               ND_TCHECK_LEN(bp, sizeof(struct in_addr));
                addrtostr(bp, nla_buf, sizeof(nla_buf));
                bp += sizeof(struct in_addr);
                break;
            case AFNUM_INET6:
-               ND_TCHECK2(*bp, sizeof(struct in6_addr));
+               ND_TCHECK_LEN(bp, sizeof(struct in6_addr));
                addrtostr6(bp, nla_buf, sizeof(nla_buf));
                bp += sizeof(struct in6_addr);
                break;
@@ -242,10 +243,10 @@ pgm_print(netdissect_options *ndo,
            }
 
            ND_PRINT((ndo, "SPM seq %u trail %u lead %u nla %s",
-                        EXTRACT_32BITS(&spm->pgms_seq),
-                         EXTRACT_32BITS(&spm->pgms_trailseq),
-                        EXTRACT_32BITS(&spm->pgms_leadseq),
-                         nla_buf));
+                        EXTRACT_BE_U_4(&spm->pgms_seq),
+                        EXTRACT_BE_U_4(&spm->pgms_trailseq),
+                        EXTRACT_BE_U_4(&spm->pgms_leadseq),
+                        nla_buf));
            break;
        }
 
@@ -255,8 +256,8 @@ pgm_print(netdissect_options *ndo,
            poll_msg = (const struct pgm_poll *)(pgm + 1);
            ND_TCHECK(*poll_msg);
            ND_PRINT((ndo, "POLL seq %u round %u",
-                        EXTRACT_32BITS(&poll_msg->pgmp_seq),
-                         EXTRACT_16BITS(&poll_msg->pgmp_round)));
+                        EXTRACT_BE_U_4(&poll_msg->pgmp_seq),
+                        EXTRACT_BE_U_2(&poll_msg->pgmp_round)));
            bp = (const u_char *) (poll_msg + 1);
            break;
        }
@@ -268,14 +269,14 @@ pgm_print(netdissect_options *ndo,
            ND_TCHECK(*polr);
            bp = (const u_char *) (polr + 1);
 
-           switch (EXTRACT_16BITS(&polr->pgmp_nla_afi)) {
+           switch (EXTRACT_BE_U_2(&polr->pgmp_nla_afi)) {
            case AFNUM_INET:
-               ND_TCHECK2(*bp, sizeof(struct in_addr));
+               ND_TCHECK_LEN(bp, sizeof(struct in_addr));
                addrtostr(bp, nla_buf, sizeof(nla_buf));
                bp += sizeof(struct in_addr);
                break;
            case AFNUM_INET6:
-               ND_TCHECK2(*bp, sizeof(struct in6_addr));
+               ND_TCHECK_LEN(bp, sizeof(struct in6_addr));
                addrtostr6(bp, nla_buf, sizeof(nla_buf));
                bp += sizeof(struct in6_addr);
                break;
@@ -284,21 +285,21 @@ pgm_print(netdissect_options *ndo,
                break;
            }
 
-           ND_TCHECK2(*bp, sizeof(uint32_t));
-           ivl = EXTRACT_32BITS(bp);
+           ND_TCHECK_LEN(bp, sizeof(uint32_t));
+           ivl = EXTRACT_BE_U_4(bp);
            bp += sizeof(uint32_t);
 
-           ND_TCHECK2(*bp, sizeof(uint32_t));
-           rnd = EXTRACT_32BITS(bp);
+           ND_TCHECK_LEN(bp, sizeof(uint32_t));
+           rnd = EXTRACT_BE_U_4(bp);
            bp += sizeof(uint32_t);
 
-           ND_TCHECK2(*bp, sizeof(uint32_t));
-           mask = EXTRACT_32BITS(bp);
+           ND_TCHECK_LEN(bp, sizeof(uint32_t));
+           mask = EXTRACT_BE_U_4(bp);
            bp += sizeof(uint32_t);
 
            ND_PRINT((ndo, "POLR seq %u round %u nla %s ivl %u rnd 0x%08x "
-                        "mask 0x%08x", EXTRACT_32BITS(&polr->pgmp_seq),
-                        EXTRACT_16BITS(&polr->pgmp_round), nla_buf, ivl, rnd, mask));
+                        "mask 0x%08x", EXTRACT_BE_U_4(&polr->pgmp_seq),
+                        EXTRACT_BE_U_2(&polr->pgmp_round), nla_buf, ivl, rnd, mask));
            break;
        }
        case PGM_ODATA: {
@@ -307,8 +308,8 @@ pgm_print(netdissect_options *ndo,
            odata = (const struct pgm_data *)(pgm + 1);
            ND_TCHECK(*odata);
            ND_PRINT((ndo, "ODATA trail %u seq %u",
-                        EXTRACT_32BITS(&odata->pgmd_trailseq),
-                        EXTRACT_32BITS(&odata->pgmd_seq)));
+                        EXTRACT_BE_U_4(&odata->pgmd_trailseq),
+                        EXTRACT_BE_U_4(&odata->pgmd_seq)));
            bp = (const u_char *) (odata + 1);
            break;
        }
@@ -319,8 +320,8 @@ pgm_print(netdissect_options *ndo,
            rdata = (const struct pgm_data *)(pgm + 1);
            ND_TCHECK(*rdata);
            ND_PRINT((ndo, "RDATA trail %u seq %u",
-                        EXTRACT_32BITS(&rdata->pgmd_trailseq),
-                        EXTRACT_32BITS(&rdata->pgmd_seq)));
+                        EXTRACT_BE_U_4(&rdata->pgmd_trailseq),
+                        EXTRACT_BE_U_4(&rdata->pgmd_seq)));
            bp = (const u_char *) (rdata + 1);
            break;
        }
@@ -339,14 +340,14 @@ pgm_print(netdissect_options *ndo,
             * Skip past the source, saving info along the way
             * and stopping if we don't have enough.
             */
-           switch (EXTRACT_16BITS(&nak->pgmn_source_afi)) {
+           switch (EXTRACT_BE_U_2(&nak->pgmn_source_afi)) {
            case AFNUM_INET:
-               ND_TCHECK2(*bp, sizeof(struct in_addr));
+               ND_TCHECK_LEN(bp, sizeof(struct in_addr));
                addrtostr(bp, source_buf, sizeof(source_buf));
                bp += sizeof(struct in_addr);
                break;
            case AFNUM_INET6:
-               ND_TCHECK2(*bp, sizeof(struct in6_addr));
+               ND_TCHECK_LEN(bp, sizeof(struct in6_addr));
                addrtostr6(bp, source_buf, sizeof(source_buf));
                bp += sizeof(struct in6_addr);
                break;
@@ -360,14 +361,15 @@ pgm_print(netdissect_options *ndo,
             * and stopping if we don't have enough.
             */
            bp += (2 * sizeof(uint16_t));
-           switch (EXTRACT_16BITS(bp)) {
+           ND_TCHECK_2(bp);
+           switch (EXTRACT_BE_U_2(bp)) {
            case AFNUM_INET:
-               ND_TCHECK2(*bp, sizeof(struct in_addr));
+               ND_TCHECK_LEN(bp, sizeof(struct in_addr));
                addrtostr(bp, group_buf, sizeof(group_buf));
                bp += sizeof(struct in_addr);
                break;
            case AFNUM_INET6:
-               ND_TCHECK2(*bp, sizeof(struct in6_addr));
+               ND_TCHECK_LEN(bp, sizeof(struct in6_addr));
                addrtostr6(bp, group_buf, sizeof(group_buf));
                bp += sizeof(struct in6_addr);
                break;
@@ -393,7 +395,7 @@ pgm_print(netdissect_options *ndo,
                     break;
            }
            ND_PRINT((ndo, "(%s -> %s), seq %u",
-                        source_buf, group_buf, EXTRACT_32BITS(&nak->pgmn_seq)));
+                        source_buf, group_buf, EXTRACT_BE_U_4(&nak->pgmn_seq)));
            break;
        }
 
@@ -403,7 +405,7 @@ pgm_print(netdissect_options *ndo,
            ack = (const struct pgm_ack *)(pgm + 1);
            ND_TCHECK(*ack);
            ND_PRINT((ndo, "ACK seq %u",
-                        EXTRACT_32BITS(&ack->pgma_rx_max_seq)));
+                        EXTRACT_BE_U_4(&ack->pgma_rx_max_seq)));
            bp = (const u_char *) (ack + 1);
            break;
        }
@@ -422,7 +424,7 @@ pgm_print(netdissect_options *ndo,
            /*
             * make sure there's enough for the first option header
             */
-           if (!ND_TTEST2(*bp, PGM_MIN_OPT_LEN)) {
+           if (!ND_TTEST_LEN(bp, PGM_MIN_OPT_LEN)) {
                ND_PRINT((ndo, "[|OPT]"));
                return;
            }
@@ -431,22 +433,24 @@ pgm_print(netdissect_options *ndo,
             * That option header MUST be an OPT_LENGTH option
             * (see the first paragraph of section 9.1 in RFC 3208).
             */
-           opt_type = *bp++;
+           opt_type = EXTRACT_U_1(bp);
+           bp++;
            if ((opt_type & PGM_OPT_MASK) != PGM_OPT_LENGTH) {
                ND_PRINT((ndo, "[First option bad, should be PGM_OPT_LENGTH, is %u]", opt_type & PGM_OPT_MASK));
                return;
            }
-           opt_len = *bp++;
+           opt_len = EXTRACT_U_1(bp);
+           bp++;
            if (opt_len != 4) {
                ND_PRINT((ndo, "[Bad OPT_LENGTH option, length %u != 4]", opt_len));
                return;
            }
-           opts_len = EXTRACT_16BITS(bp);
+           opts_len = EXTRACT_BE_U_2(bp);
+           bp += sizeof(uint16_t);
            if (opts_len < 4) {
                ND_PRINT((ndo, "[Bad total option length %u < 4]", opts_len));
                return;
            }
-           bp += sizeof(uint16_t);
            ND_PRINT((ndo, " OPTS LEN %d", opts_len));
            opts_len -= 4;
 
@@ -455,8 +459,14 @@ pgm_print(netdissect_options *ndo,
                    ND_PRINT((ndo, "[Total option length leaves no room for final option]"));
                    return;
                }
-               opt_type = *bp++;
-               opt_len = *bp++;
+               if (!ND_TTEST_2(bp)) {
+                   ND_PRINT((ndo, " [|OPT]"));
+                   return;
+               }
+               opt_type = EXTRACT_U_1(bp);
+               bp++;
+               opt_len = EXTRACT_U_1(bp);
+               bp++;
                if (opt_len < PGM_MIN_OPT_LEN) {
                    ND_PRINT((ndo, "[Bad option, length %u < %u]", opt_len,
                        PGM_MIN_OPT_LEN));
@@ -466,119 +476,137 @@ pgm_print(netdissect_options *ndo,
                    ND_PRINT((ndo, "[Total option length leaves no room for final option]"));
                    return;
                }
-               if (!ND_TTEST2(*bp, opt_len - 2)) {
+               if (!ND_TTEST_LEN(bp, opt_len - 2)) {
                    ND_PRINT((ndo, " [|OPT]"));
                    return;
                }
 
                switch (opt_type & PGM_OPT_MASK) {
                case PGM_OPT_LENGTH:
-                   if (opt_len != 4) {
-                       ND_PRINT((ndo, "[Bad OPT_LENGTH option, length %u != 4]", opt_len));
+#define PGM_OPT_LENGTH_LEN     (2+2)
+                   if (opt_len != PGM_OPT_LENGTH_LEN) {
+                       ND_PRINT((ndo, "[Bad OPT_LENGTH option, length %u != %u]",
+                           opt_len, PGM_OPT_LENGTH_LEN));
                        return;
                    }
-                   ND_PRINT((ndo, " OPTS LEN (extra?) %d", EXTRACT_16BITS(bp)));
-                   bp += sizeof(uint16_t);
-                   opts_len -= 4;
+                   ND_PRINT((ndo, " OPTS LEN (extra?) %d", EXTRACT_BE_U_2(bp)));
+                   bp += 2;
+                   opts_len -= PGM_OPT_LENGTH_LEN;
                    break;
 
                case PGM_OPT_FRAGMENT:
-                   if (opt_len != 16) {
-                       ND_PRINT((ndo, "[Bad OPT_FRAGMENT option, length %u != 16]", opt_len));
+#define PGM_OPT_FRAGMENT_LEN   (2+2+4+4+4)
+                   if (opt_len != PGM_OPT_FRAGMENT_LEN) {
+                       ND_PRINT((ndo, "[Bad OPT_FRAGMENT option, length %u != %u]",
+                           opt_len, PGM_OPT_FRAGMENT_LEN));
                        return;
                    }
                    bp += 2;
-                   seq = EXTRACT_32BITS(bp);
-                   bp += sizeof(uint32_t);
-                   offset = EXTRACT_32BITS(bp);
-                   bp += sizeof(uint32_t);
-                   len = EXTRACT_32BITS(bp);
-                   bp += sizeof(uint32_t);
+                   seq = EXTRACT_BE_U_4(bp);
+                   bp += 4;
+                   offset = EXTRACT_BE_U_4(bp);
+                   bp += 4;
+                   len = EXTRACT_BE_U_4(bp);
+                   bp += 4;
                    ND_PRINT((ndo, " FRAG seq %u off %u len %u", seq, offset, len));
-                   opts_len -= 16;
+                   opts_len -= PGM_OPT_FRAGMENT_LEN;
                    break;
 
                case PGM_OPT_NAK_LIST:
                    bp += 2;
-                   opt_len -= sizeof(uint32_t);        /* option header */
+                   opt_len -= 4;       /* option header */
                    ND_PRINT((ndo, " NAK LIST"));
                    while (opt_len) {
-                       if (opt_len < sizeof(uint32_t)) {
+                       if (opt_len < 4) {
                            ND_PRINT((ndo, "[Option length not a multiple of 4]"));
                            return;
                        }
-                       ND_TCHECK2(*bp, sizeof(uint32_t));
-                       ND_PRINT((ndo, " %u", EXTRACT_32BITS(bp)));
-                       bp += sizeof(uint32_t);
-                       opt_len -= sizeof(uint32_t);
-                       opts_len -= sizeof(uint32_t);
+                       ND_TCHECK_4(bp);
+                       ND_PRINT((ndo, " %u", EXTRACT_BE_U_4(bp)));
+                       bp += 4;
+                       opt_len -= 4;
+                       opts_len -= 4;
                    }
                    break;
 
                case PGM_OPT_JOIN:
-                   if (opt_len != 8) {
-                       ND_PRINT((ndo, "[Bad OPT_JOIN option, length %u != 8]", opt_len));
+#define PGM_OPT_JOIN_LEN       (2+2+4)
+                   if (opt_len != PGM_OPT_JOIN_LEN) {
+                       ND_PRINT((ndo, "[Bad OPT_JOIN option, length %u != %u]",
+                           opt_len, PGM_OPT_JOIN_LEN));
                        return;
                    }
                    bp += 2;
-                   seq = EXTRACT_32BITS(bp);
-                   bp += sizeof(uint32_t);
+                   seq = EXTRACT_BE_U_4(bp);
+                   bp += 4;
                    ND_PRINT((ndo, " JOIN %u", seq));
-                   opts_len -= 8;
+                   opts_len -= PGM_OPT_JOIN_LEN;
                    break;
 
                case PGM_OPT_NAK_BO_IVL:
-                   if (opt_len != 12) {
-                       ND_PRINT((ndo, "[Bad OPT_NAK_BO_IVL option, length %u != 12]", opt_len));
+#define PGM_OPT_NAK_BO_IVL_LEN (2+2+4+4)
+                   if (opt_len != PGM_OPT_NAK_BO_IVL_LEN) {
+                       ND_PRINT((ndo, "[Bad OPT_NAK_BO_IVL option, length %u != %u]",
+                           opt_len, PGM_OPT_NAK_BO_IVL_LEN));
                        return;
                    }
                    bp += 2;
-                   offset = EXTRACT_32BITS(bp);
-                   bp += sizeof(uint32_t);
-                   seq = EXTRACT_32BITS(bp);
-                   bp += sizeof(uint32_t);
+                   offset = EXTRACT_BE_U_4(bp);
+                   bp += 4;
+                   seq = EXTRACT_BE_U_4(bp);
+                   bp += 4;
                    ND_PRINT((ndo, " BACKOFF ivl %u ivlseq %u", offset, seq));
-                   opts_len -= 12;
+                   opts_len -= PGM_OPT_NAK_BO_IVL_LEN;
                    break;
 
                case PGM_OPT_NAK_BO_RNG:
-                   if (opt_len != 12) {
-                       ND_PRINT((ndo, "[Bad OPT_NAK_BO_RNG option, length %u != 12]", opt_len));
+#define PGM_OPT_NAK_BO_RNG_LEN (2+2+4+4)
+                   if (opt_len != PGM_OPT_NAK_BO_RNG_LEN) {
+                       ND_PRINT((ndo, "[Bad OPT_NAK_BO_RNG option, length %u != %u]",
+                           opt_len, PGM_OPT_NAK_BO_RNG_LEN));
                        return;
                    }
                    bp += 2;
-                   offset = EXTRACT_32BITS(bp);
-                   bp += sizeof(uint32_t);
-                   seq = EXTRACT_32BITS(bp);
-                   bp += sizeof(uint32_t);
+                   offset = EXTRACT_BE_U_4(bp);
+                   bp += 4;
+                   seq = EXTRACT_BE_U_4(bp);
+                   bp += 4;
                    ND_PRINT((ndo, " BACKOFF max %u min %u", offset, seq));
-                   opts_len -= 12;
+                   opts_len -= PGM_OPT_NAK_BO_RNG_LEN;
                    break;
 
                case PGM_OPT_REDIRECT:
+#define PGM_OPT_REDIRECT_FIXED_LEN     (2+2+2+2)
+                   if (opt_len < PGM_OPT_REDIRECT_FIXED_LEN) {
+                       ND_PRINT((ndo, "[Bad OPT_REDIRECT option, length %u < %u]",
+                           opt_len, PGM_OPT_REDIRECT_FIXED_LEN));
+                       return;
+                   }
                    bp += 2;
-                   nla_afnum = EXTRACT_16BITS(bp);
-                   bp += (2 * sizeof(uint16_t));
+                   nla_afnum = EXTRACT_BE_U_2(bp);
+                   bp += 2+2;
                    switch (nla_afnum) {
                    case AFNUM_INET:
-                       if (opt_len != 4 + sizeof(struct in_addr)) {
-                           ND_PRINT((ndo, "[Bad OPT_REDIRECT option, length %u != 4 + address size]", opt_len));
+                       if (opt_len != PGM_OPT_REDIRECT_FIXED_LEN + sizeof(struct in_addr)) {
+                           ND_PRINT((ndo, "[Bad OPT_REDIRECT option, length %u != %u + address size]",
+                               opt_len, PGM_OPT_REDIRECT_FIXED_LEN));
                            return;
                        }
-                       ND_TCHECK2(*bp, sizeof(struct in_addr));
+                       ND_TCHECK_LEN(bp, sizeof(struct in_addr));
                        addrtostr(bp, nla_buf, sizeof(nla_buf));
                        bp += sizeof(struct in_addr);
-                       opts_len -= 4 + sizeof(struct in_addr);
+                       opts_len -= PGM_OPT_REDIRECT_FIXED_LEN + sizeof(struct in_addr);
                        break;
                    case AFNUM_INET6:
-                       if (opt_len != 4 + sizeof(struct in6_addr)) {
-                           ND_PRINT((ndo, "[Bad OPT_REDIRECT option, length %u != 4 + address size]", opt_len));
+                       if (opt_len != PGM_OPT_REDIRECT_FIXED_LEN + sizeof(struct in6_addr)) {
+                           ND_PRINT((ndo, "[Bad OPT_REDIRECT option, length %u != %u + address size]",
+                               PGM_OPT_REDIRECT_FIXED_LEN, opt_len));
                            return;
                        }
-                       ND_TCHECK2(*bp, sizeof(struct in6_addr));
+                       ND_TCHECK_LEN(bp, sizeof(struct in6_addr));
                        addrtostr6(bp, nla_buf, sizeof(nla_buf));
                        bp += sizeof(struct in6_addr);
-                       opts_len -= 4 + sizeof(struct in6_addr);
+                       opts_len -= PGM_OPT_REDIRECT_FIXED_LEN + sizeof(struct in6_addr);
                        break;
                    default:
                        goto trunc;
@@ -589,49 +617,57 @@ pgm_print(netdissect_options *ndo,
                    break;
 
                case PGM_OPT_PARITY_PRM:
-                   if (opt_len != 8) {
-                       ND_PRINT((ndo, "[Bad OPT_PARITY_PRM option, length %u != 8]", opt_len));
+#define PGM_OPT_PARITY_PRM_LEN (2+2+4)
+                   if (opt_len != PGM_OPT_PARITY_PRM_LEN) {
+                       ND_PRINT((ndo, "[Bad OPT_PARITY_PRM option, length %u != %u]",
+                           opt_len, PGM_OPT_PARITY_PRM_LEN));
                        return;
                    }
                    bp += 2;
-                   len = EXTRACT_32BITS(bp);
-                   bp += sizeof(uint32_t);
+                   len = EXTRACT_BE_U_4(bp);
+                   bp += 4;
                    ND_PRINT((ndo, " PARITY MAXTGS %u", len));
-                   opts_len -= 8;
+                   opts_len -= PGM_OPT_PARITY_PRM_LEN;
                    break;
 
                case PGM_OPT_PARITY_GRP:
-                   if (opt_len != 8) {
-                       ND_PRINT((ndo, "[Bad OPT_PARITY_GRP option, length %u != 8]", opt_len));
+#define PGM_OPT_PARITY_GRP_LEN (2+2+4)
+                   if (opt_len != PGM_OPT_PARITY_GRP_LEN) {
+                       ND_PRINT((ndo, "[Bad OPT_PARITY_GRP option, length %u != %u]",
+                           opt_len, PGM_OPT_PARITY_GRP_LEN));
                        return;
                    }
                    bp += 2;
-                   seq = EXTRACT_32BITS(bp);
-                   bp += sizeof(uint32_t);
+                   seq = EXTRACT_BE_U_4(bp);
+                   bp += 4;
                    ND_PRINT((ndo, " PARITY GROUP %u", seq));
-                   opts_len -= 8;
+                   opts_len -= PGM_OPT_PARITY_GRP_LEN;
                    break;
 
                case PGM_OPT_CURR_TGSIZE:
-                   if (opt_len != 8) {
-                       ND_PRINT((ndo, "[Bad OPT_CURR_TGSIZE option, length %u != 8]", opt_len));
+#define PGM_OPT_CURR_TGSIZE_LEN        (2+2+4)
+                   if (opt_len != PGM_OPT_CURR_TGSIZE_LEN) {
+                       ND_PRINT((ndo, "[Bad OPT_CURR_TGSIZE option, length %u != %u]",
+                           opt_len, PGM_OPT_CURR_TGSIZE_LEN));
                        return;
                    }
                    bp += 2;
-                   len = EXTRACT_32BITS(bp);
-                   bp += sizeof(uint32_t);
+                   len = EXTRACT_BE_U_4(bp);
+                   bp += 4;
                    ND_PRINT((ndo, " PARITY ATGS %u", len));
-                   opts_len -= 8;
+                   opts_len -= PGM_OPT_CURR_TGSIZE_LEN;
                    break;
 
                case PGM_OPT_NBR_UNREACH:
-                   if (opt_len != 4) {
-                       ND_PRINT((ndo, "[Bad OPT_NBR_UNREACH option, length %u != 4]", opt_len));
+#define PGM_OPT_NBR_UNREACH_LEN        (2+2)
+                   if (opt_len != PGM_OPT_NBR_UNREACH_LEN) {
+                       ND_PRINT((ndo, "[Bad OPT_NBR_UNREACH option, length %u != %u]",
+                           opt_len, PGM_OPT_NBR_UNREACH_LEN));
                        return;
                    }
                    bp += 2;
                    ND_PRINT((ndo, " NBR_UNREACH"));
-                   opts_len -= 4;
+                   opts_len -= PGM_OPT_NBR_UNREACH_LEN;
                    break;
 
                case PGM_OPT_PATH_NLA:
@@ -641,33 +677,39 @@ pgm_print(netdissect_options *ndo,
                    break;
 
                case PGM_OPT_SYN:
-                   if (opt_len != 4) {
-                       ND_PRINT((ndo, "[Bad OPT_SYN option, length %u != 4]", opt_len));
+#define PGM_OPT_SYN_LEN        (2+2)
+                   if (opt_len != PGM_OPT_SYN_LEN) {
+                       ND_PRINT((ndo, "[Bad OPT_SYN option, length %u != %u]",
+                           opt_len, PGM_OPT_SYN_LEN));
                        return;
                    }
                    bp += 2;
                    ND_PRINT((ndo, " SYN"));
-                   opts_len -= 4;
+                   opts_len -= PGM_OPT_SYN_LEN;
                    break;
 
                case PGM_OPT_FIN:
-                   if (opt_len != 4) {
-                       ND_PRINT((ndo, "[Bad OPT_FIN option, length %u != 4]", opt_len));
+#define PGM_OPT_FIN_LEN        (2+2)
+                   if (opt_len != PGM_OPT_FIN_LEN) {
+                       ND_PRINT((ndo, "[Bad OPT_FIN option, length %u != %u]",
+                           opt_len, PGM_OPT_FIN_LEN));
                        return;
                    }
                    bp += 2;
                    ND_PRINT((ndo, " FIN"));
-                   opts_len -= 4;
+                   opts_len -= PGM_OPT_FIN_LEN;
                    break;
 
                case PGM_OPT_RST:
-                   if (opt_len != 4) {
-                       ND_PRINT((ndo, "[Bad OPT_RST option, length %u != 4]", opt_len));
+#define PGM_OPT_RST_LEN        (2+2)
+                   if (opt_len != PGM_OPT_RST_LEN) {
+                       ND_PRINT((ndo, "[Bad OPT_RST option, length %u != %u]",
+                           opt_len, PGM_OPT_RST_LEN));
                        return;
                    }
                    bp += 2;
                    ND_PRINT((ndo, " RST"));
-                   opts_len -= 4;
+                   opts_len -= PGM_OPT_RST_LEN;
                    break;
 
                case PGM_OPT_CR:
@@ -677,41 +719,51 @@ pgm_print(netdissect_options *ndo,
                    break;
 
                case PGM_OPT_CRQST:
-                   if (opt_len != 4) {
-                       ND_PRINT((ndo, "[Bad OPT_CRQST option, length %u != 4]", opt_len));
+#define PGM_OPT_CRQST_LEN      (2+2)
+                   if (opt_len != PGM_OPT_CRQST_LEN) {
+                       ND_PRINT((ndo, "[Bad OPT_CRQST option, length %u != %u]",
+                           opt_len, PGM_OPT_CRQST_LEN));
                        return;
                    }
                    bp += 2;
                    ND_PRINT((ndo, " CRQST"));
-                   opts_len -= 4;
+                   opts_len -= PGM_OPT_CRQST_LEN;
                    break;
 
                case PGM_OPT_PGMCC_DATA:
+#define PGM_OPT_PGMCC_DATA_FIXED_LEN   (2+2+4+2+2)
+                   if (opt_len < PGM_OPT_PGMCC_DATA_FIXED_LEN) {
+                       ND_PRINT((ndo, "[Bad OPT_PGMCC_DATA option, length %u < %u]",
+                           opt_len, PGM_OPT_PGMCC_DATA_FIXED_LEN));
+                       return;
+                   }
                    bp += 2;
-                   offset = EXTRACT_32BITS(bp);
-                   bp += sizeof(uint32_t);
-                   nla_afnum = EXTRACT_16BITS(bp);
-                   bp += (2 * sizeof(uint16_t));
+                   offset = EXTRACT_BE_U_4(bp);
+                   bp += 4;
+                   nla_afnum = EXTRACT_BE_U_2(bp);
+                   bp += 2+2;
                    switch (nla_afnum) {
                    case AFNUM_INET:
-                       if (opt_len != 12 + sizeof(struct in_addr)) {
-                           ND_PRINT((ndo, "[Bad OPT_PGMCC_DATA option, length %u != 12 + address size]", opt_len));
+                       if (opt_len != PGM_OPT_PGMCC_DATA_FIXED_LEN + sizeof(struct in_addr)) {
+                           ND_PRINT((ndo, "[Bad OPT_PGMCC_DATA option, length %u != %u + address size]",
+                               opt_len, PGM_OPT_PGMCC_DATA_FIXED_LEN));
                            return;
                        }
-                       ND_TCHECK2(*bp, sizeof(struct in_addr));
+                       ND_TCHECK_LEN(bp, sizeof(struct in_addr));
                        addrtostr(bp, nla_buf, sizeof(nla_buf));
                        bp += sizeof(struct in_addr);
-                       opts_len -= 12 + sizeof(struct in_addr);
+                       opts_len -= PGM_OPT_PGMCC_DATA_FIXED_LEN + sizeof(struct in_addr);
                        break;
                    case AFNUM_INET6:
-                       if (opt_len != 12 + sizeof(struct in6_addr)) {
-                           ND_PRINT((ndo, "[Bad OPT_PGMCC_DATA option, length %u != 12 + address size]", opt_len));
+                       if (opt_len != PGM_OPT_PGMCC_DATA_FIXED_LEN + sizeof(struct in6_addr)) {
+                           ND_PRINT((ndo, "[Bad OPT_PGMCC_DATA option, length %u != %u + address size]",
+                               opt_len, PGM_OPT_PGMCC_DATA_FIXED_LEN));
                            return;
                        }
-                       ND_TCHECK2(*bp, sizeof(struct in6_addr));
+                       ND_TCHECK_LEN(bp, sizeof(struct in6_addr));
                        addrtostr6(bp, nla_buf, sizeof(nla_buf));
                        bp += sizeof(struct in6_addr);
-                       opts_len -= 12 + sizeof(struct in6_addr);
+                       opts_len -= PGM_OPT_PGMCC_DATA_FIXED_LEN + sizeof(struct in6_addr);
                        break;
                    default:
                        goto trunc;
@@ -722,31 +774,39 @@ pgm_print(netdissect_options *ndo,
                    break;
 
                case PGM_OPT_PGMCC_FEEDBACK:
+#define PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN       (2+2+4+2+2)
+                   if (opt_len < PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN) {
+                       ND_PRINT((ndo, "[Bad PGM_OPT_PGMCC_FEEDBACK option, length %u < %u]",
+                           opt_len, PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN));
+                       return;
+                   }
                    bp += 2;
-                   offset = EXTRACT_32BITS(bp);
-                   bp += sizeof(uint32_t);
-                   nla_afnum = EXTRACT_16BITS(bp);
-                   bp += (2 * sizeof(uint16_t));
+                   offset = EXTRACT_BE_U_4(bp);
+                   bp += 4;
+                   nla_afnum = EXTRACT_BE_U_2(bp);
+                   bp += 2+2;
                    switch (nla_afnum) {
                    case AFNUM_INET:
-                       if (opt_len != 12 + sizeof(struct in_addr)) {
-                           ND_PRINT((ndo, "[Bad OPT_PGMCC_DATA option, length %u != 12 + address size]", opt_len));
+                       if (opt_len != PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN + sizeof(struct in_addr)) {
+                           ND_PRINT((ndo, "[Bad OPT_PGMCC_FEEDBACK option, length %u != %u + address size]",
+                               opt_len, PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN));
                            return;
                        }
-                       ND_TCHECK2(*bp, sizeof(struct in_addr));
+                       ND_TCHECK_LEN(bp, sizeof(struct in_addr));
                        addrtostr(bp, nla_buf, sizeof(nla_buf));
                        bp += sizeof(struct in_addr);
-                       opts_len -= 12 + sizeof(struct in_addr);
+                       opts_len -= PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN + sizeof(struct in_addr);
                        break;
                    case AFNUM_INET6:
-                       if (opt_len != 12 + sizeof(struct in6_addr)) {
-                           ND_PRINT((ndo, "[Bad OPT_PGMCC_DATA option, length %u != 12 + address size]", opt_len));
+                       if (opt_len != PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN + sizeof(struct in6_addr)) {
+                           ND_PRINT((ndo, "[Bad OPT_PGMCC_FEEDBACK option, length %u != %u + address size]",
+                               opt_len, PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN));
                            return;
                        }
-                       ND_TCHECK2(*bp, sizeof(struct in6_addr));
+                       ND_TCHECK_LEN(bp, sizeof(struct in6_addr));
                        addrtostr6(bp, nla_buf, sizeof(nla_buf));
                        bp += sizeof(struct in6_addr);
-                       opts_len -= 12 + sizeof(struct in6_addr);
+                       opts_len -= PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN + sizeof(struct in6_addr);
                        break;
                    default:
                        goto trunc;
@@ -771,7 +831,8 @@ pgm_print(netdissect_options *ndo,
        ND_PRINT((ndo, " [%u]", length));
        if (ndo->ndo_packettype == PT_PGM_ZMTP1 &&
            (pgm->pgm_type == PGM_ODATA || pgm->pgm_type == PGM_RDATA))
-               zmtp1_print_datagram(ndo, bp, EXTRACT_16BITS(&pgm->pgm_length));
+               zmtp1_datagram_print(ndo, bp,
+                                    EXTRACT_BE_U_2(&pgm->pgm_length));
 
        return;