]> The Tcpdump Group git mirrors - tcpdump/blob - print-sctp.c
Eliminate some unused parameters.
[tcpdump] / print-sctp.c
1 /* Copyright (c) 2001 NETLAB, Temple University
2 * Copyright (c) 2001 Protocol Engineering Lab, University of Delaware
3 *
4 * Jerry Heinz <gheinz@astro.temple.edu>
5 * John Fiore <jfiore@joda.cis.temple.edu>
6 * Armando L. Caro Jr. <acaro@cis.udel.edu>
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
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.
18 *
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.
22 *
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
33 * SUCH DAMAGE.
34 */
35
36 #ifndef lint
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)";
39 #endif
40
41 #ifdef HAVE_CONFIG_H
42 #include "config.h"
43 #endif
44
45 #include <sys/param.h>
46 #include <sys/time.h>
47 #include <sys/socket.h>
48
49 #include <unistd.h>
50 #include "sctpHeader.h"
51 #include "sctpConstants.h"
52 #include <assert.h>
53
54 #include <netinet/in.h>
55
56 #include <stdio.h>
57 #include <string.h>
58
59 #include "interface.h"
60 #include "addrtoname.h"
61 #include "extract.h" /* must come after interface.h */
62 #include "ip.h"
63 #ifdef INET6
64 #include "ip6.h"
65 #endif
66
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 */
70 {
71 const struct sctpHeader *sctpPktHdr;
72 const struct ip *ip;
73 #ifdef INET6
74 const struct ip6_hdr *ip6;
75 #endif
76 const u_char *cp;
77 void *endPacketPtr;
78 u_short sourcePort, destPort;
79 int chunkCount;
80 struct sctpChunkDesc *chunkDescPtr;
81 void *nextChunk;
82
83 sctpPktHdr = (struct sctpHeader*) bp;
84 endPacketPtr = ((u_char*)((u_char*)sctpPktHdr+sctpPacketLength));
85
86 if( (u_long) endPacketPtr > (u_long) snapend)
87 endPacketPtr = (void *) snapend;
88 ip = (struct ip *)bp2;
89 #ifdef INET6
90 if (IP_V(ip) == 6)
91 ip6 = (struct ip6_hdr *)bp2;
92 else
93 ip6 = NULL;
94 #endif /*INET6*/
95 cp = (u_char *)(sctpPktHdr + 1);
96 if (cp > snapend)
97 {
98 printf("[|sctp]");
99 return;
100 }
101
102 if (sctpPacketLength < sizeof(struct sctpHeader))
103 {
104 (void)printf("truncated-sctp - %ld bytes missing!",
105 (long)sctpPacketLength-sizeof(struct sctpHeader));
106 return;
107 }
108
109 /* sctpPacketLength -= sizeof(struct sctpHeader); packet length */
110 /* is now only as long as the payload */
111
112 sourcePort = ntohs(sctpPktHdr->source);
113 destPort = ntohs(sctpPktHdr->destination);
114
115 #ifdef INET6
116 if (ip6) {
117 if (ip6->ip6_nxt == IPPROTO_SCTP) {
118 (void)printf("%s.%d > %s.%d: sctp",
119 ip6addr_string(&ip6->ip6_src),
120 sourcePort,
121 ip6addr_string(&ip6->ip6_dst),
122 destPort);
123 } else {
124 (void)printf("%d > %d: sctp",
125 sourcePort, destPort);
126 }
127 } else
128 #endif /*INET6*/
129 {
130 if (ip->ip_p == IPPROTO_SCTP) {
131 (void)printf("%s.%d > %s.%d: sctp",
132 ipaddr_string(&ip->ip_src),
133 sourcePort,
134 ipaddr_string(&ip->ip_dst),
135 destPort);
136 } else {
137 (void)printf("%d > %d: sctp",
138 sourcePort, destPort);
139 }
140 }
141 fflush(stdout);
142
143 if (vflag < 2)
144 return;
145
146 /* cycle through all chunks, printing information on each one */
147 for (chunkCount = 0,
148 chunkDescPtr = (struct sctpChunkDesc *) ( (u_char*) sctpPktHdr +
149 sizeof(struct sctpHeader));
150 chunkDescPtr != NULL &&
151 ( (void *) ((u_char *) chunkDescPtr + sizeof(struct sctpChunkDesc))
152 <= endPacketPtr);
153
154 chunkDescPtr = (struct sctpChunkDesc *) nextChunk, chunkCount++)
155 {
156 u_short align;
157 u_char *chunkEnd;
158
159 chunkEnd = ((u_char*)chunkDescPtr + ntohs(chunkDescPtr->chunkLength));
160
161 align=ntohs(chunkDescPtr->chunkLength) % 4;
162 if (align != 0)
163 align = 4 - align;
164
165 nextChunk = (void *) (chunkEnd + align);
166
167 printf("\n\t%d) ", chunkCount+1);
168 switch (chunkDescPtr->chunkID)
169 {
170 case SCTP_DATA :
171 {
172 struct sctpDataPart *dataHdrPtr;
173
174 printf("[DATA] ");
175
176 if ((chunkDescPtr->chunkFlg & SCTP_DATA_UNORDERED)
177 == SCTP_DATA_UNORDERED)
178 printf("(U)");
179
180 if ((chunkDescPtr->chunkFlg & SCTP_DATA_FIRST_FRAG)
181 == SCTP_DATA_FIRST_FRAG)
182 printf("(B)");
183
184 if ((chunkDescPtr->chunkFlg & SCTP_DATA_LAST_FRAG)
185 == SCTP_DATA_LAST_FRAG)
186 printf("(E)");
187
188 if( ((chunkDescPtr->chunkFlg & SCTP_DATA_UNORDERED)
189 == SCTP_DATA_UNORDERED)
190 ||
191 ((chunkDescPtr->chunkFlg & SCTP_DATA_FIRST_FRAG)
192 == SCTP_DATA_FIRST_FRAG)
193 ||
194 ((chunkDescPtr->chunkFlg & SCTP_DATA_LAST_FRAG)
195 == SCTP_DATA_LAST_FRAG) )
196 printf(" ");
197
198 dataHdrPtr=(struct sctpDataPart*)(chunkDescPtr+1);
199
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));
204 fflush(stdout);
205
206 if (vflag) /* if verbose output is specified */
207 { /* at the command line */
208 char *payloadPtr;
209
210 printf("[Payload: {");
211 fflush(stdout);
212
213 payloadPtr = (char *) (++dataHdrPtr);
214 write(STDOUT_FILENO, payloadPtr,
215 htons(chunkDescPtr->chunkLength)-1 -
216 sizeof(struct sctpDataPart)-sizeof(struct sctpChunkDesc));
217 printf("}] ");
218 fflush(stdout);
219 }
220 break;
221 }
222 case SCTP_INITIATION :
223 {
224 struct sctpInitiation *init;
225
226 printf("[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));
233
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.");
238 #endif
239 break;
240 }
241 case SCTP_INITIATION_ACK :
242 {
243 struct sctpInitiation *init;
244
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));
252
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.");
257 #endif
258 break;
259 }
260 case SCTP_SELECTIVE_ACK:
261 {
262 struct sctpSelectiveAck *sack;
263 struct sctpSelectiveFrag *frag;
264 int fragNo, tsnNo;
265 u_long *dupTSN;
266
267 printf("[SACK] ");
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));
273
274
275 /* print gaps */
276 for (frag = ( (struct sctpSelectiveFrag *)
277 ((struct sctpSelectiveAck *) sack+1)),
278 fragNo=0;
279 (void *)frag < nextChunk && fragNo < ntohs(sack->numberOfdesc);
280 frag++, fragNo++)
281 printf("\n\t\t[gap ack block #%d: start = %u, end = %u] ",
282 fragNo+1,
283 (u_int32_t)(ntohl(sack->highestConseqTSN) + ntohs(frag->fragmentStart)),
284 (u_int32_t)(ntohl(sack->highestConseqTSN) + ntohs(frag->fragmentEnd)));
285
286
287 /* print duplicate TSNs */
288 for (dupTSN = (u_long*)frag, tsnNo=0;
289 (void *) dupTSN < nextChunk && tsnNo<ntohs(sack->numDupTsns);
290 dupTSN++, tsnNo++)
291 printf("\n\t\t[dup TSN #%u: %u] ", tsnNo+1,
292 (u_int32_t)ntohl(*dupTSN));
293
294 break;
295 }
296 case SCTP_HEARTBEAT_REQUEST :
297 {
298 struct sctpHBsender *hb;
299
300 hb=(struct sctpHBsender*)chunkDescPtr;
301
302 printf("[HB REQ] ");
303
304 break;
305 }
306 case SCTP_HEARTBEAT_ACK :
307 printf("[HB ACK] ");
308 break;
309 case SCTP_ABORT_ASSOCIATION :
310 printf("[ABORT] ");
311 break;
312 case SCTP_SHUTDOWN :
313 printf("[SHUTDOWN] ");
314 break;
315 case SCTP_SHUTDOWN_ACK :
316 printf("[SHUTDOWN ACK] ");
317 break;
318 case SCTP_OPERATION_ERR :
319 printf("[OP ERR] ");
320 break;
321 case SCTP_COOKIE_ECHO :
322 printf("[COOKIE ECHO] ");
323 break;
324 case SCTP_COOKIE_ACK :
325 printf("[COOKIE ACK] ");
326 break;
327 case SCTP_ECN_ECHO :
328 printf("[ECN ECHO] ");
329 break;
330 case SCTP_ECN_CWR :
331 printf("[ECN CWR] ");
332 break;
333 case SCTP_SHUTDOWN_COMPLETE :
334 printf("[SHUTDOWN COMPLETE] ");
335 break;
336 case SCTP_FORWARD_CUM_TSN :
337 printf("[FOR CUM TSN] ");
338 break;
339 case SCTP_RELIABLE_CNTL :
340 printf("[REL CTRL] ");
341 break;
342 case SCTP_RELIABLE_CNTL_ACK :
343 printf("[REL CTRL ACK] ");
344 break;
345 default :
346 printf("[Unknown chunk type: 0x%x]", chunkDescPtr->chunkID);
347 return;
348 }
349 }
350 }