]>
The Tcpdump Group git mirrors - tcpdump/blob - print-sctp.c
1 /* Copyright (c) 2001 NETLAB, Temple University
2 * Copyright (c) 2001 Protocol Engineering Lab, University of Delaware
4 * Jerry Heinz <gheinz@astro.temple.edu>
5 * John Fiore <jfiore@joda.cis.temple.edu>
6 * Armando L. Caro Jr. <acaro@cis.udel.edu>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor of the Laboratory may be used
20 * to endorse or promote products derived from this software without
21 * specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 static const char rcsid
[] =
38 "@(#) $Header: /tcpdump/master/tcpdump/print-sctp.c,v 1.8 2002-04-25 04:45:59 guy Exp $ (NETLAB/PEL)";
45 #include <sys/param.h>
47 #include <sys/socket.h>
50 #include "sctpHeader.h"
51 #include "sctpConstants.h"
54 #include <netinet/in.h>
59 #include "interface.h"
60 #include "addrtoname.h"
61 #include "extract.h" /* must come after interface.h */
67 void sctp_print(const u_char
*bp
, /* beginning of sctp packet */
68 const u_char
*bp2
, /* beginning of enclosing */
69 u_int sctpPacketLength
) /* ip packet */
71 const struct sctpHeader
*sctpPktHdr
;
74 const struct ip6_hdr
*ip6
;
77 const void *endPacketPtr
;
78 u_short sourcePort
, destPort
;
80 const struct sctpChunkDesc
*chunkDescPtr
;
81 const void *nextChunk
;
83 sctpPktHdr
= (const struct sctpHeader
*) bp
;
84 endPacketPtr
= (const u_char
*)sctpPktHdr
+sctpPacketLength
;
86 if( (u_long
) endPacketPtr
> (u_long
) snapend
)
87 endPacketPtr
= (const void *) snapend
;
88 ip
= (struct ip
*)bp2
;
91 ip6
= (const struct ip6_hdr
*)bp2
;
95 cp
= (const u_char
*)(sctpPktHdr
+ 1);
102 if (sctpPacketLength
< sizeof(struct sctpHeader
))
104 (void)printf("truncated-sctp - %ld bytes missing!",
105 (long)sctpPacketLength
-sizeof(struct sctpHeader
));
109 /* sctpPacketLength -= sizeof(struct sctpHeader); packet length */
110 /* is now only as long as the payload */
112 sourcePort
= ntohs(sctpPktHdr
->source
);
113 destPort
= ntohs(sctpPktHdr
->destination
);
117 if (ip6
->ip6_nxt
== IPPROTO_SCTP
) {
118 (void)printf("%s.%d > %s.%d: sctp",
119 ip6addr_string(&ip6
->ip6_src
),
121 ip6addr_string(&ip6
->ip6_dst
),
124 (void)printf("%d > %d: sctp",
125 sourcePort
, destPort
);
130 if (ip
->ip_p
== IPPROTO_SCTP
) {
131 (void)printf("%s.%d > %s.%d: sctp",
132 ipaddr_string(&ip
->ip_src
),
134 ipaddr_string(&ip
->ip_dst
),
137 (void)printf("%d > %d: sctp",
138 sourcePort
, destPort
);
146 /* cycle through all chunks, printing information on each one */
148 chunkDescPtr
= (const struct sctpChunkDesc
*)
149 ((const u_char
*) sctpPktHdr
+ sizeof(struct sctpHeader
));
150 chunkDescPtr
!= NULL
&&
152 ((const u_char
*) chunkDescPtr
+ sizeof(struct sctpChunkDesc
))
155 chunkDescPtr
= (const struct sctpChunkDesc
*) nextChunk
, chunkCount
++)
158 const u_char
*chunkEnd
;
160 chunkEnd
= ((const u_char
*)chunkDescPtr
+ ntohs(chunkDescPtr
->chunkLength
));
162 align
=ntohs(chunkDescPtr
->chunkLength
) % 4;
166 nextChunk
= (const void *) (chunkEnd
+ align
);
168 printf("\n\t%d) ", chunkCount
+1);
169 switch (chunkDescPtr
->chunkID
)
173 const struct sctpDataPart
*dataHdrPtr
;
177 if ((chunkDescPtr
->chunkFlg
& SCTP_DATA_UNORDERED
)
178 == SCTP_DATA_UNORDERED
)
181 if ((chunkDescPtr
->chunkFlg
& SCTP_DATA_FIRST_FRAG
)
182 == SCTP_DATA_FIRST_FRAG
)
185 if ((chunkDescPtr
->chunkFlg
& SCTP_DATA_LAST_FRAG
)
186 == SCTP_DATA_LAST_FRAG
)
189 if( ((chunkDescPtr
->chunkFlg
& SCTP_DATA_UNORDERED
)
190 == SCTP_DATA_UNORDERED
)
192 ((chunkDescPtr
->chunkFlg
& SCTP_DATA_FIRST_FRAG
)
193 == SCTP_DATA_FIRST_FRAG
)
195 ((chunkDescPtr
->chunkFlg
& SCTP_DATA_LAST_FRAG
)
196 == SCTP_DATA_LAST_FRAG
) )
199 dataHdrPtr
=(const struct sctpDataPart
*)(chunkDescPtr
+1);
201 printf("[TSN: %u] ", (u_int32_t
)ntohl(dataHdrPtr
->TSN
));
202 printf("[SID: %u] ", ntohs(dataHdrPtr
->streamId
));
203 printf("[SSEQ %u] ", ntohs(dataHdrPtr
->sequence
));
204 printf("[PPID 0x%x] ", (u_int32_t
)ntohl(dataHdrPtr
->payloadtype
));
207 if (vflag
) /* if verbose output is specified */
208 { /* at the command line */
209 const u_char
*payloadPtr
;
213 if (!xflag
&& !qflag
) {
214 payloadPtr
= (const u_char
*) (++dataHdrPtr
);
216 default_print(payloadPtr
,
217 htons(chunkDescPtr
->chunkLength
)-1 -
218 sizeof(struct sctpDataPart
)-sizeof(struct sctpChunkDesc
));
224 case SCTP_INITIATION
:
226 const struct sctpInitiation
*init
;
229 init
=(const struct sctpInitiation
*)(chunkDescPtr
+1);
230 printf("[init tag: %u] ", (u_int32_t
)ntohl(init
->initTag
));
231 printf("[rwnd: %u] ", (u_int32_t
)ntohl(init
->rcvWindowCredit
));
232 printf("[OS: %u] ", ntohs(init
->NumPreopenStreams
));
233 printf("[MIS: %u] ", ntohs(init
->MaxInboundStreams
));
234 printf("[init TSN: %u] ", (u_int32_t
)ntohl(init
->initialTSN
));
236 #if(0) /* ALC you can add code for optional params here */
237 if( (init
+1) < chunkEnd
)
238 printf(" @@@@@ UNFINISHED @@@@@@%s\n",
239 "Optional params present, but not printed.");
243 case SCTP_INITIATION_ACK
:
245 const struct sctpInitiation
*init
;
247 printf("[INIT ACK] ");
248 init
=(const struct sctpInitiation
*)(chunkDescPtr
+1);
249 printf("[init tag: %u] ", (u_int32_t
)ntohl(init
->initTag
));
250 printf("[rwnd: %u] ", (u_int32_t
)ntohl(init
->rcvWindowCredit
));
251 printf("[OS: %u] ", ntohs(init
->NumPreopenStreams
));
252 printf("[MIS: %u] ", ntohs(init
->MaxInboundStreams
));
253 printf("[init TSN: %u] ", (u_int32_t
)ntohl(init
->initialTSN
));
255 #if(0) /* ALC you can add code for optional params here */
256 if( (init
+1) < chunkEnd
)
257 printf(" @@@@@ UNFINISHED @@@@@@%s\n",
258 "Optional params present, but not printed.");
262 case SCTP_SELECTIVE_ACK
:
264 const struct sctpSelectiveAck
*sack
;
265 const struct sctpSelectiveFrag
*frag
;
267 const u_long
*dupTSN
;
270 sack
=(const struct sctpSelectiveAck
*)(chunkDescPtr
+1);
271 printf("[cum ack %u] ", (u_int32_t
)ntohl(sack
->highestConseqTSN
));
272 printf("[a_rwnd %u] ", (u_int32_t
)ntohl(sack
->updatedRwnd
));
273 printf("[#gap acks %u] ", ntohs(sack
->numberOfdesc
));
274 printf("[#dup tsns %u] ", ntohs(sack
->numDupTsns
));
278 for (frag
= ( (const struct sctpSelectiveFrag
*)
279 ((const struct sctpSelectiveAck
*) sack
+1)),
281 (const void *)frag
< nextChunk
&& fragNo
< ntohs(sack
->numberOfdesc
);
283 printf("\n\t\t[gap ack block #%d: start = %u, end = %u] ",
285 (u_int32_t
)(ntohl(sack
->highestConseqTSN
) + ntohs(frag
->fragmentStart
)),
286 (u_int32_t
)(ntohl(sack
->highestConseqTSN
) + ntohs(frag
->fragmentEnd
)));
289 /* print duplicate TSNs */
290 for (dupTSN
= (const u_long
*)frag
, tsnNo
=0;
291 (const void *) dupTSN
< nextChunk
&& tsnNo
<ntohs(sack
->numDupTsns
);
293 printf("\n\t\t[dup TSN #%u: %u] ", tsnNo
+1,
294 (u_int32_t
)ntohl(*dupTSN
));
298 case SCTP_HEARTBEAT_REQUEST
:
300 const struct sctpHBsender
*hb
;
302 hb
=(const struct sctpHBsender
*)chunkDescPtr
;
308 case SCTP_HEARTBEAT_ACK
:
311 case SCTP_ABORT_ASSOCIATION
:
315 printf("[SHUTDOWN] ");
317 case SCTP_SHUTDOWN_ACK
:
318 printf("[SHUTDOWN ACK] ");
320 case SCTP_OPERATION_ERR
:
323 case SCTP_COOKIE_ECHO
:
324 printf("[COOKIE ECHO] ");
326 case SCTP_COOKIE_ACK
:
327 printf("[COOKIE ACK] ");
330 printf("[ECN ECHO] ");
333 printf("[ECN CWR] ");
335 case SCTP_SHUTDOWN_COMPLETE
:
336 printf("[SHUTDOWN COMPLETE] ");
338 case SCTP_FORWARD_CUM_TSN
:
339 printf("[FOR CUM TSN] ");
341 case SCTP_RELIABLE_CNTL
:
342 printf("[REL CTRL] ");
344 case SCTP_RELIABLE_CNTL_ACK
:
345 printf("[REL CTRL ACK] ");
348 printf("[Unknown chunk type: 0x%x]", chunkDescPtr
->chunkID
);