]>
The Tcpdump Group git mirrors - tcpdump/blob - print-dccp.c
2 * Copyright (C) Arnaldo Carvalho de Melo 2004
3 * Copyright (C) Ian McDonald 2005
4 * Copyright (C) Yoshifumi Nishida 2005
6 * This software may be distributed either under the terms of the
7 * BSD-style license that accompanies tcpdump or the GNU GPL version 2
11 static const char rcsid
[] _U_
=
12 "@(#) $Header: /tcpdump/master/tcpdump/print-dccp.c,v 1.8 2007-11-09 00:44:09 guy Exp $ (LBL)";
19 #include <tcpdump-stdinc.h>
26 #include "interface.h"
27 #include "addrtoname.h"
28 #include "extract.h" /* must come after interface.h */
35 static const char *dccp_reset_codes
[] = {
50 static const char *dccp_feature_nums
[] = {
59 "minimum checksum coverage",
60 "check data checksum",
63 static inline int dccp_csum_coverage(const struct dccp_hdr
* dh
, u_int len
)
67 if (DCCPH_CSCOV(dh
) == 0)
69 cov
= (dh
->dccph_doff
+ DCCPH_CSCOV(dh
) - 1) * sizeof(u_int32_t
);
70 return (cov
> len
)? len
: cov
;
73 static int dccp_cksum(const struct ip
*ip
,
74 const struct dccp_hdr
*dh
, u_int len
)
76 int cov
= dccp_csum_coverage(dh
, len
);
84 struct cksum_vec vec
[2];
89 ph
.proto
= IPPROTO_DCCP
;
90 memcpy(&ph
.src
, &ip
->ip_src
.s_addr
, sizeof(u_int32_t
));
92 memcpy(&ph
.dst
, &ip
->ip_dst
.s_addr
, sizeof(u_int32_t
));
94 ph
.dst
= ip_finddst(ip
);
96 vec
[0].ptr
= (const u_int8_t
*)(void *)&ph
;
97 vec
[0].len
= sizeof(ph
);
98 vec
[1].ptr
= (const u_int8_t
*)(void *)dh
;
100 return in_cksum(vec
, 2);
104 static int dccp6_cksum(const struct ip6_hdr
*ip6
, const struct dccp_hdr
*dh
, u_int len
)
106 return nextproto6_cksum(ip6
, (const u_int8_t
*)(void *)dh
,
107 dccp_csum_coverage(dh
, len
), IPPROTO_DCCP
);
111 static const char *dccp_reset_code(u_int8_t code
)
113 if (code
>= __DCCP_RESET_CODE_LAST
)
115 return dccp_reset_codes
[code
];
118 static u_int64_t
dccp_seqno(const struct dccp_hdr
*dh
)
120 u_int32_t seq_high
= DCCPH_SEQ(dh
);
121 u_int64_t seqno
= EXTRACT_24BITS(&seq_high
) & 0xFFFFFF;
123 if (DCCPH_X(dh
) != 0) {
124 const struct dccp_hdr_ext
*dhx
= (void *)(dh
+ 1);
125 u_int32_t seq_low
= dhx
->dccph_seq_low
;
126 seqno
&= 0x00FFFF; /* clear reserved field */
127 seqno
= (seqno
<< 32) + EXTRACT_32BITS(&seq_low
);
133 static inline unsigned int dccp_basic_hdr_len(const struct dccp_hdr
*dh
)
135 return sizeof(*dh
) + (DCCPH_X(dh
) ? sizeof(struct dccp_hdr_ext
) : 0);
138 static void dccp_print_ack_no(const u_char
*bp
)
140 const struct dccp_hdr
*dh
= (const struct dccp_hdr
*)bp
;
141 const struct dccp_hdr_ack_bits
*dh_ack
=
142 (struct dccp_hdr_ack_bits
*)(bp
+ dccp_basic_hdr_len(dh
));
147 ack_high
= DCCPH_ACK(dh_ack
);
148 ackno
= EXTRACT_24BITS(&ack_high
) & 0xFFFFFF;
150 if (DCCPH_X(dh
) != 0) {
154 ack_low
= dh_ack
->dccph_ack_nr_low
;
156 ackno
&= 0x00FFFF; /* clear reserved field */
157 ackno
= (ackno
<< 32) + EXTRACT_32BITS(&ack_low
);
160 (void)printf("(ack=%" PRIu64
") ", ackno
);
165 static inline unsigned int dccp_packet_hdr_len(const u_int8_t type
)
167 if (type
== DCCP_PKT_DATA
)
169 if (type
== DCCP_PKT_DATAACK
||
170 type
== DCCP_PKT_ACK
||
171 type
== DCCP_PKT_SYNC
||
172 type
== DCCP_PKT_SYNCACK
||
173 type
== DCCP_PKT_CLOSE
||
174 type
== DCCP_PKT_CLOSEREQ
)
175 return sizeof(struct dccp_hdr_ack_bits
);
176 if (type
== DCCP_PKT_REQUEST
)
177 return sizeof(struct dccp_hdr_request
);
178 if (type
== DCCP_PKT_RESPONSE
)
179 return sizeof(struct dccp_hdr_response
);
180 return sizeof(struct dccp_hdr_reset
);
183 static int dccp_print_option(const u_char
*option
);
186 * dccp_print - show dccp packet
187 * @bp - beginning of dccp packet
188 * @data2 - beginning of enclosing
189 * @len - lenght of ip packet
191 void dccp_print(const u_char
*bp
, const u_char
*data2
, u_int len
)
193 const struct dccp_hdr
*dh
;
196 const struct ip6_hdr
*ip6
;
199 u_short sport
, dport
;
203 dh
= (const struct dccp_hdr
*)bp
;
205 ip
= (struct ip
*)data2
;
208 ip6
= (const struct ip6_hdr
*)data2
;
212 cp
= (const u_char
*)(dh
+ 1);
214 printf("[Invalid packet|dccp]");
218 if (len
< sizeof(struct dccp_hdr
)) {
219 printf("truncated-dccp - %ld bytes missing!",
220 (long)len
- sizeof(struct dccp_hdr
));
224 sport
= EXTRACT_16BITS(&dh
->dccph_sport
);
225 dport
= EXTRACT_16BITS(&dh
->dccph_dport
);
226 hlen
= dh
->dccph_doff
* 4;
230 (void)printf("%s.%d > %s.%d: ",
231 ip6addr_string(&ip6
->ip6_src
), sport
,
232 ip6addr_string(&ip6
->ip6_dst
), dport
);
236 (void)printf("%s.%d > %s.%d: ",
237 ipaddr_string(&ip
->ip_src
), sport
,
238 ipaddr_string(&ip
->ip_dst
), dport
);
243 (void)printf(" %d", len
- hlen
);
245 (void)printf("dccp [bad hdr length %u - too long, > %u]",
251 /* other variables in generic header */
253 (void)printf("CCVal %d, CsCov %d, ", DCCPH_CCVAL(dh
), DCCPH_CSCOV(dh
));
256 /* checksum calculation */
257 if (vflag
&& TTEST2(bp
[0], len
)) {
258 u_int16_t sum
= 0, dccp_sum
;
260 dccp_sum
= EXTRACT_16BITS(&dh
->dccph_checksum
);
261 (void)printf("cksum 0x%04x ", dccp_sum
);
263 sum
= dccp_cksum(ip
, dh
, len
);
265 else if (IP_V(ip
) == 6)
266 sum
= dccp6_cksum(ip6
, dh
, len
);
269 (void)printf("(incorrect -> 0x%04x), ",in_cksum_shouldbe(dccp_sum
, sum
));
271 (void)printf("(correct), ");
274 switch (DCCPH_TYPE(dh
)) {
275 case DCCP_PKT_REQUEST
: {
276 struct dccp_hdr_request
*dhr
=
277 (struct dccp_hdr_request
*)(bp
+ dccp_basic_hdr_len(dh
));
279 (void)printf("request (service=%d) ",
280 EXTRACT_32BITS(&dhr
->dccph_req_service
));
284 case DCCP_PKT_RESPONSE
: {
285 struct dccp_hdr_response
*dhr
=
286 (struct dccp_hdr_response
*)(bp
+ dccp_basic_hdr_len(dh
));
288 (void)printf("response (service=%d) ",
289 EXTRACT_32BITS(&dhr
->dccph_resp_service
));
294 (void)printf("data ");
297 (void)printf("ack ");
301 case DCCP_PKT_DATAACK
: {
302 (void)printf("dataack ");
306 case DCCP_PKT_CLOSEREQ
:
307 (void)printf("closereq ");
311 (void)printf("close ");
314 case DCCP_PKT_RESET
: {
315 struct dccp_hdr_reset
*dhr
=
316 (struct dccp_hdr_reset
*)(bp
+ dccp_basic_hdr_len(dh
));
318 (void)printf("reset (code=%s) ",
319 dccp_reset_code(dhr
->dccph_reset_code
));
324 (void)printf("sync ");
327 case DCCP_PKT_SYNCACK
:
328 (void)printf("syncack ");
332 (void)printf("invalid ");
336 if ((DCCPH_TYPE(dh
) != DCCP_PKT_DATA
) &&
337 (DCCPH_TYPE(dh
) != DCCP_PKT_REQUEST
))
338 dccp_print_ack_no(bp
);
343 (void)printf("seq %" PRIu64
, dccp_seqno(dh
));
345 /* process options */
346 if (hlen
> dccp_basic_hdr_len(dh
) + extlen
){
349 cp
= bp
+ dccp_basic_hdr_len(dh
) + extlen
;
352 hlen
-= dccp_basic_hdr_len(dh
) + extlen
;
355 optlen
= dccp_print_option(cp
);
356 if (!optlen
) goto trunc2
;
357 if (hlen
<= optlen
) break;
371 static int dccp_print_option(const u_char
*option
)
379 optlen
= *(option
+1);
381 printf("Option %d optlen too short",*option
);
386 TCHECK2(*option
,optlen
);
396 printf("slowreceiver");
400 if (*(option
+2) < 10){
401 printf(" %s", dccp_feature_nums
[*(option
+2)]);
402 for (i
= 0; i
< optlen
-3; i
++) printf(" %d", *(option
+3 + i
));
407 if (*(option
+2) < 10){
408 printf(" %s", dccp_feature_nums
[*(option
+2)]);
409 for (i
= 0; i
< optlen
-3; i
++) printf(" %d", *(option
+3 + i
));
414 if (*(option
+2) < 10){
415 printf(" %s", dccp_feature_nums
[*(option
+2)]);
416 for (i
= 0; i
< optlen
-3; i
++) printf(" %d", *(option
+3 + i
));
421 if (*(option
+2) < 10){
422 printf(" %s", dccp_feature_nums
[*(option
+2)]);
423 for (i
= 0; i
< optlen
-3; i
++) printf(" %d", *(option
+3 + i
));
427 printf("initcookie 0x");
428 for (i
= 0; i
< optlen
-2; i
++) printf("%02x", *(option
+2 + i
));
432 for (i
= 0; i
< optlen
-2; i
++) printf(" %d", *(option
+2 + i
));
435 printf("ack_vector0 0x");
436 for (i
= 0; i
< optlen
-2; i
++) printf("%02x", *(option
+2 + i
));
439 printf("ack_vector1 0x");
440 for (i
= 0; i
< optlen
-2; i
++) printf("%02x", *(option
+2 + i
));
443 printf("data_dropped 0x");
444 for (i
= 0; i
< optlen
-2; i
++) printf("%02x", *(option
+2 + i
));
447 printf("timestamp %u", EXTRACT_32BITS(option
+ 2));
450 printf("timestamp_echo %u", EXTRACT_32BITS(option
+ 2));
453 printf("elapsed_time ");
455 printf("%u", EXTRACT_32BITS(option
+ 2));
457 printf("%u", EXTRACT_16BITS(option
+ 2));
460 printf("data_checksum ");
461 for (i
= 0; i
< optlen
-2; i
++) printf("%02x", *(option
+2 + i
));
464 if (*option
>= 128) {
465 printf("CCID option %d",*option
);
468 printf(" %u", EXTRACT_16BITS(option
+ 2));
471 printf(" %u", EXTRACT_32BITS(option
+ 2));
479 printf("unknown_opt %d", *option
);