]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-sctp.c
Make 1-element arrays for fields that may repeat.
[tcpdump] / print-sctp.c
index 70738e66185be5283808c58a520675c9b9343f4b..66d4884913105b832d34257338c8f2fec7282890 100644 (file)
@@ -490,10 +490,11 @@ static inline int isForCES_port(u_short Port)
        return 0;
 }
 
-void sctp_print(netdissect_options *ndo,
-                const u_char *bp,        /* beginning of sctp packet */
-                const u_char *bp2,       /* beginning of enclosing */
-                u_int sctpPacketLength)  /* ip packet */
+void
+sctp_print(netdissect_options *ndo,
+           const u_char *bp,        /* beginning of sctp packet */
+           const u_char *bp2,       /* beginning of enclosing */
+           u_int sctpPacketLength)  /* ip packet */
 {
   u_int sctpPacketLengthRemaining;
   const struct sctpHeader *sctpPktHdr;
@@ -515,8 +516,8 @@ void sctp_print(netdissect_options *ndo,
   ND_TCHECK(*sctpPktHdr);
   sctpPacketLengthRemaining = sctpPacketLength;
 
-  sourcePort = EXTRACT_16BITS(&sctpPktHdr->source);
-  destPort = EXTRACT_16BITS(&sctpPktHdr->destination);
+  sourcePort = EXTRACT_BE_U_2(&sctpPktHdr->source);
+  destPort = EXTRACT_BE_U_2(&sctpPktHdr->destination);
 
   ip = (const struct ip *)bp2;
   if (IP_V(ip) == 6)
@@ -569,7 +570,7 @@ void sctp_print(netdissect_options *ndo,
         break;
       }
       ND_TCHECK(*chunkDescPtr);
-      chunkLength = EXTRACT_16BITS(&chunkDescPtr->chunkLength);
+      chunkLength = EXTRACT_BE_U_2(&chunkDescPtr->chunkLength);
       if (chunkLength < sizeof(*chunkDescPtr)) {
         ND_PRINT((ndo, "%s%d) [Bad chunk length %u, < size of chunk descriptor]", sep, chunkCount+1, chunkLength));
         break;
@@ -585,7 +586,7 @@ void sctp_print(netdissect_options *ndo,
         break;
       }
 
-      ND_TCHECK2(*bp, chunkLength);
+      ND_TCHECK_LEN(bp, chunkLength);
 
       bp += sizeof(*chunkDescPtr);
       sctpPacketLengthRemaining -= sizeof(*chunkDescPtr);
@@ -630,10 +631,10 @@ void sctp_print(netdissect_options *ndo,
            }
            dataHdrPtr=(const struct sctpDataPart*)bp;
 
-           ppid = EXTRACT_32BITS(&dataHdrPtr->payloadtype);
-           ND_PRINT((ndo, "[TSN: %u] ", EXTRACT_32BITS(&dataHdrPtr->TSN)));
-           ND_PRINT((ndo, "[SID: %u] ", EXTRACT_16BITS(&dataHdrPtr->streamId)));
-           ND_PRINT((ndo, "[SSEQ %u] ", EXTRACT_16BITS(&dataHdrPtr->sequence)));
+           ppid = EXTRACT_BE_U_4(&dataHdrPtr->payloadtype);
+           ND_PRINT((ndo, "[TSN: %u] ", EXTRACT_BE_U_4(&dataHdrPtr->TSN)));
+           ND_PRINT((ndo, "[SID: %u] ", EXTRACT_BE_U_2(&dataHdrPtr->streamId)));
+           ND_PRINT((ndo, "[SSEQ %u] ", EXTRACT_BE_U_2(&dataHdrPtr->sequence)));
            ND_PRINT((ndo, "[PPID %s] ",
                    tok2str(PayloadProto_idents, "0x%x", ppid)));
 
@@ -684,16 +685,16 @@ void sctp_print(netdissect_options *ndo,
                return;
            }
            init=(const struct sctpInitiation*)bp;
-           ND_PRINT((ndo, "[init tag: %u] ", EXTRACT_32BITS(&init->initTag)));
-           ND_PRINT((ndo, "[rwnd: %u] ", EXTRACT_32BITS(&init->rcvWindowCredit)));
-           ND_PRINT((ndo, "[OS: %u] ", EXTRACT_16BITS(&init->NumPreopenStreams)));
-           ND_PRINT((ndo, "[MIS: %u] ", EXTRACT_16BITS(&init->MaxInboundStreams)));
-           ND_PRINT((ndo, "[init TSN: %u] ", EXTRACT_32BITS(&init->initialTSN)));
+           ND_PRINT((ndo, "[init tag: %u] ", EXTRACT_BE_U_4(&init->initTag)));
+           ND_PRINT((ndo, "[rwnd: %u] ", EXTRACT_BE_U_4(&init->rcvWindowCredit)));
+           ND_PRINT((ndo, "[OS: %u] ", EXTRACT_BE_U_2(&init->NumPreopenStreams)));
+           ND_PRINT((ndo, "[MIS: %u] ", EXTRACT_BE_U_2(&init->MaxInboundStreams)));
+           ND_PRINT((ndo, "[init TSN: %u] ", EXTRACT_BE_U_4(&init->initialTSN)));
            bp += sizeof(*init);
            sctpPacketLengthRemaining -= sizeof(*init);
            chunkLengthRemaining -= sizeof(*init);
 
-#if(0) /* ALC you can add code for optional params here */
+#if 0 /* ALC you can add code for optional params here */
            if( chunkLengthRemaining != 0 )
              ND_PRINT((ndo, " @@@@@ UNFINISHED @@@@@@%s\n",
                     "Optional params present, but not printed."));
@@ -712,16 +713,16 @@ void sctp_print(netdissect_options *ndo,
                return;
            }
            init=(const struct sctpInitiation*)bp;
-           ND_PRINT((ndo, "[init tag: %u] ", EXTRACT_32BITS(&init->initTag)));
-           ND_PRINT((ndo, "[rwnd: %u] ", EXTRACT_32BITS(&init->rcvWindowCredit)));
-           ND_PRINT((ndo, "[OS: %u] ", EXTRACT_16BITS(&init->NumPreopenStreams)));
-           ND_PRINT((ndo, "[MIS: %u] ", EXTRACT_16BITS(&init->MaxInboundStreams)));
-           ND_PRINT((ndo, "[init TSN: %u] ", EXTRACT_32BITS(&init->initialTSN)));
+           ND_PRINT((ndo, "[init tag: %u] ", EXTRACT_BE_U_4(&init->initTag)));
+           ND_PRINT((ndo, "[rwnd: %u] ", EXTRACT_BE_U_4(&init->rcvWindowCredit)));
+           ND_PRINT((ndo, "[OS: %u] ", EXTRACT_BE_U_2(&init->NumPreopenStreams)));
+           ND_PRINT((ndo, "[MIS: %u] ", EXTRACT_BE_U_2(&init->MaxInboundStreams)));
+           ND_PRINT((ndo, "[init TSN: %u] ", EXTRACT_BE_U_4(&init->initialTSN)));
             bp += sizeof(*init);
             sctpPacketLengthRemaining -= sizeof(*init);
             chunkLengthRemaining -= sizeof(*init);
 
-#if(0) /* ALC you can add code for optional params here */
+#if 0 /* ALC you can add code for optional params here */
            if( chunkLengthRemaining != 0 )
              ND_PRINT((ndo, " @@@@@ UNFINISHED @@@@@@%s\n",
                     "Optional params present, but not printed."));
@@ -743,10 +744,10 @@ void sctp_print(netdissect_options *ndo,
              return;
            }
            sack=(const struct sctpSelectiveAck*)bp;
-           ND_PRINT((ndo, "[cum ack %u] ", EXTRACT_32BITS(&sack->highestConseqTSN)));
-           ND_PRINT((ndo, "[a_rwnd %u] ", EXTRACT_32BITS(&sack->updatedRwnd)));
-           ND_PRINT((ndo, "[#gap acks %u] ", EXTRACT_16BITS(&sack->numberOfdesc)));
-           ND_PRINT((ndo, "[#dup tsns %u] ", EXTRACT_16BITS(&sack->numDupTsns)));
+           ND_PRINT((ndo, "[cum ack %u] ", EXTRACT_BE_U_4(&sack->highestConseqTSN)));
+           ND_PRINT((ndo, "[a_rwnd %u] ", EXTRACT_BE_U_4(&sack->updatedRwnd)));
+           ND_PRINT((ndo, "[#gap acks %u] ", EXTRACT_BE_U_2(&sack->numberOfdesc)));
+           ND_PRINT((ndo, "[#dup tsns %u] ", EXTRACT_BE_U_2(&sack->numDupTsns)));
             bp += sizeof(*sack);
            sctpPacketLengthRemaining -= sizeof(*sack);
             chunkLengthRemaining -= sizeof(*sack);
@@ -754,7 +755,7 @@ void sctp_print(netdissect_options *ndo,
 
            /* print gaps */
            for (fragNo=0;
-                chunkLengthRemaining != 0 && fragNo < EXTRACT_16BITS(&sack->numberOfdesc);
+                chunkLengthRemaining != 0 && fragNo < EXTRACT_BE_U_2(&sack->numberOfdesc);
                 bp += sizeof(*frag), sctpPacketLengthRemaining -= sizeof(*frag), chunkLengthRemaining -= sizeof(*frag), fragNo++) {
              if (chunkLengthRemaining < sizeof(*frag)) {
                ND_PRINT((ndo, "bogus chunk length %u]", chunkLength));
@@ -763,13 +764,13 @@ void sctp_print(netdissect_options *ndo,
              frag = (const struct sctpSelectiveFrag *)bp;
              ND_PRINT((ndo, "\n\t\t[gap ack block #%d: start = %u, end = %u] ",
                     fragNo+1,
-                    EXTRACT_32BITS(&sack->highestConseqTSN) + EXTRACT_16BITS(&frag->fragmentStart),
-                    EXTRACT_32BITS(&sack->highestConseqTSN) + EXTRACT_16BITS(&frag->fragmentEnd)));
+                    EXTRACT_BE_U_4(&sack->highestConseqTSN) + EXTRACT_BE_U_2(&frag->fragmentStart),
+                    EXTRACT_BE_U_4(&sack->highestConseqTSN) + EXTRACT_BE_U_2(&frag->fragmentEnd)));
            }
 
            /* print duplicate TSNs */
            for (tsnNo=0;
-                chunkLengthRemaining != 0 && tsnNo<EXTRACT_16BITS(&sack->numDupTsns);
+                chunkLengthRemaining != 0 && tsnNo<EXTRACT_BE_U_2(&sack->numDupTsns);
                 bp += 4, sctpPacketLengthRemaining -= 4, chunkLengthRemaining -= 4, tsnNo++) {
              if (chunkLengthRemaining < 4) {
                ND_PRINT((ndo, "bogus chunk length %u]", chunkLength));
@@ -777,7 +778,7 @@ void sctp_print(netdissect_options *ndo,
              }
               dupTSN = (const u_char *)bp;
              ND_PRINT((ndo, "\n\t\t[dup TSN #%u: %u] ", tsnNo+1,
-               EXTRACT_32BITS(dupTSN)));
+               EXTRACT_BE_U_4(dupTSN)));
            }
            break;
          }
@@ -805,7 +806,7 @@ void sctp_print(netdissect_options *ndo,
         * Fail if the alignment padding isn't in the captured data.
         * Otherwise, skip it.
         */
-       ND_TCHECK2(*bp, align);
+       ND_TCHECK_LEN(bp, align);
        bp += align;
        sctpPacketLengthRemaining -= align;
       }