]>
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.5 2001-08-01 03:31:55 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
;
78 u_short sourcePort
, destPort
;
80 struct sctpChunkDesc
*chunkDescPtr
;
83 sctpPktHdr
= (struct sctpHeader
*) bp
;
84 endPacketPtr
= ((u_char
*)((u_char
*)sctpPktHdr
+sctpPacketLength
));
86 if( (u_long
) endPacketPtr
> (u_long
) snapend
)
87 endPacketPtr
= (void *) snapend
;
88 ip
= (struct ip
*)bp2
;
91 ip6
= (struct ip6_hdr
*)bp2
;
95 cp
= (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
= (struct sctpChunkDesc
*) ( (u_char
*) sctpPktHdr
+
149 sizeof(struct sctpHeader
));
150 chunkDescPtr
!= NULL
&&
151 ( (void *) ((u_char
*) chunkDescPtr
+ sizeof(struct sctpChunkDesc
))
154 chunkDescPtr
= (struct sctpChunkDesc
*) nextChunk
, chunkCount
++)
159 chunkEnd
= ((u_char
*)chunkDescPtr
+ ntohs(chunkDescPtr
->chunkLength
));
161 align
=ntohs(chunkDescPtr
->chunkLength
) % 4;
165 nextChunk
= (void *) (chunkEnd
+ align
);
167 printf("\n\t%d) ", chunkCount
+1);
168 switch (chunkDescPtr
->chunkID
)
172 struct sctpDataPart
*dataHdrPtr
;
176 if ((chunkDescPtr
->chunkFlg
& SCTP_DATA_UNORDERED
)
177 == SCTP_DATA_UNORDERED
)
180 if ((chunkDescPtr
->chunkFlg
& SCTP_DATA_FIRST_FRAG
)
181 == SCTP_DATA_FIRST_FRAG
)
184 if ((chunkDescPtr
->chunkFlg
& SCTP_DATA_LAST_FRAG
)
185 == SCTP_DATA_LAST_FRAG
)
188 if( ((chunkDescPtr
->chunkFlg
& SCTP_DATA_UNORDERED
)
189 == SCTP_DATA_UNORDERED
)
191 ((chunkDescPtr
->chunkFlg
& SCTP_DATA_FIRST_FRAG
)
192 == SCTP_DATA_FIRST_FRAG
)
194 ((chunkDescPtr
->chunkFlg
& SCTP_DATA_LAST_FRAG
)
195 == SCTP_DATA_LAST_FRAG
) )
198 dataHdrPtr
=(struct sctpDataPart
*)(chunkDescPtr
+1);
200 printf("[TSN: %u] ", (u_int32_t
)ntohl(dataHdrPtr
->TSN
));
201 printf("[SID: %u] ", ntohs(dataHdrPtr
->streamId
));
202 printf("[SSEQ %u] ", ntohs(dataHdrPtr
->sequence
));
203 printf("[PPID 0x%x] ", (u_int32_t
)ntohl(dataHdrPtr
->payloadtype
));
206 if (vflag
) /* if verbose output is specified */
207 { /* at the command line */
210 printf("[Payload: {");
213 payloadPtr
= (char *) (++dataHdrPtr
);
214 write(STDOUT_FILENO
, payloadPtr
,
215 htons(chunkDescPtr
->chunkLength
)-1 -
216 sizeof(struct sctpDataPart
)-sizeof(struct sctpChunkDesc
));
222 case SCTP_INITIATION
:
224 struct sctpInitiation
*init
;
227 init
=(struct sctpInitiation
*)(chunkDescPtr
+1);
228 printf("[init tag: %u] ", (u_int32_t
)ntohl(init
->initTag
));
229 printf("[rwnd: %u] ", (u_int32_t
)ntohl(init
->rcvWindowCredit
));
230 printf("[OS: %u] ", ntohs(init
->NumPreopenStreams
));
231 printf("[MIS: %u] ", ntohs(init
->MaxInboundStreams
));
232 printf("[init TSN: %u] ", (u_int32_t
)ntohl(init
->initialTSN
));
234 #if(0) /* ALC you can add code for optional params here */
235 if( (init
+1) < chunkEnd
)
236 printf(" @@@@@ UNFINISHED @@@@@@%s\n",
237 "Optional params present, but not printed.");
241 case SCTP_INITIATION_ACK
:
243 struct sctpInitiation
*init
;
245 printf("[INIT ACK] ");
246 init
=(struct sctpInitiation
*)(chunkDescPtr
+1);
247 printf("[init tag: %u] ", (u_int32_t
)ntohl(init
->initTag
));
248 printf("[rwnd: %u] ", (u_int32_t
)ntohl(init
->rcvWindowCredit
));
249 printf("[OS: %u] ", ntohs(init
->NumPreopenStreams
));
250 printf("[MIS: %u] ", ntohs(init
->MaxInboundStreams
));
251 printf("[init TSN: %u] ", (u_int32_t
)ntohl(init
->initialTSN
));
253 #if(0) /* ALC you can add code for optional params here */
254 if( (init
+1) < chunkEnd
)
255 printf(" @@@@@ UNFINISHED @@@@@@%s\n",
256 "Optional params present, but not printed.");
260 case SCTP_SELECTIVE_ACK
:
262 struct sctpSelectiveAck
*sack
;
263 struct sctpSelectiveFrag
*frag
;
268 sack
=(struct sctpSelectiveAck
*)(chunkDescPtr
+1);
269 printf("[cum ack %u] ", (u_int32_t
)ntohl(sack
->highestConseqTSN
));
270 printf("[a_rwnd %u] ", (u_int32_t
)ntohl(sack
->updatedRwnd
));
271 printf("[#gap acks %u] ", ntohs(sack
->numberOfdesc
));
272 printf("[#dup tsns %u] ", ntohs(sack
->numDupTsns
));
276 for (frag
= ( (struct sctpSelectiveFrag
*)
277 ((struct sctpSelectiveAck
*) sack
+1)),
279 (void *)frag
< nextChunk
&& fragNo
< ntohs(sack
->numberOfdesc
);
281 printf("\n\t\t[gap ack block #%d: start = %u, end = %u] ",
283 (u_int32_t
)(ntohl(sack
->highestConseqTSN
) + ntohs(frag
->fragmentStart
)),
284 (u_int32_t
)(ntohl(sack
->highestConseqTSN
) + ntohs(frag
->fragmentEnd
)));
287 /* print duplicate TSNs */
288 for (dupTSN
= (u_long
*)frag
, tsnNo
=0;
289 (void *) dupTSN
< nextChunk
&& tsnNo
<ntohs(sack
->numDupTsns
);
291 printf("\n\t\t[dup TSN #%u: %u] ", tsnNo
+1,
292 (u_int32_t
)ntohl(*dupTSN
));
296 case SCTP_HEARTBEAT_REQUEST
:
298 struct sctpHBsender
*hb
;
300 hb
=(struct sctpHBsender
*)chunkDescPtr
;
306 case SCTP_HEARTBEAT_ACK
:
309 case SCTP_ABORT_ASSOCIATION
:
313 printf("[SHUTDOWN] ");
315 case SCTP_SHUTDOWN_ACK
:
316 printf("[SHUTDOWN ACK] ");
318 case SCTP_OPERATION_ERR
:
321 case SCTP_COOKIE_ECHO
:
322 printf("[COOKIE ECHO] ");
324 case SCTP_COOKIE_ACK
:
325 printf("[COOKIE ACK] ");
328 printf("[ECN ECHO] ");
331 printf("[ECN CWR] ");
333 case SCTP_SHUTDOWN_COMPLETE
:
334 printf("[SHUTDOWN COMPLETE] ");
336 case SCTP_FORWARD_CUM_TSN
:
337 printf("[FOR CUM TSN] ");
339 case SCTP_RELIABLE_CNTL
:
340 printf("[REL CTRL] ");
342 case SCTP_RELIABLE_CNTL_ACK
:
343 printf("[REL CTRL ACK] ");
346 printf("[Unknown chunk type: 0x%x]", chunkDescPtr
->chunkID
);