]>
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.1.2.5 2005-12-05 21:48:10 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 int dccp_cksum(const struct ip
*ip
,
64 const struct dccp_hdr
*dh
, u_int len
)
80 phu
.ph
.len
= htons(len
);
81 phu
.ph
.proto
= IPPROTO_DCCP
;
82 memcpy(&phu
.ph
.src
, &ip
->ip_src
.s_addr
, sizeof(u_int32_t
));
84 memcpy(&phu
.ph
.dst
, &ip
->ip_dst
.s_addr
, sizeof(u_int32_t
));
86 phu
.ph
.dst
= ip_finddst(ip
);
89 return in_cksum((u_short
*)dh
, len
, sp
[0]+sp
[1]+sp
[2]+sp
[3]+sp
[4]+sp
[5]);
93 static int dccp6_cksum(const struct ip6_hdr
*ip6
, const struct dccp_hdr
*dh
, u_int len
)
100 struct in6_addr ph_src
;
101 struct in6_addr ph_dst
;
110 memset(&phu
, 0, sizeof(phu
));
111 phu
.ph
.ph_src
= ip6
->ip6_src
;
112 phu
.ph
.ph_dst
= ip6
->ip6_dst
;
113 phu
.ph
.ph_len
= htonl(len
);
114 phu
.ph
.ph_nxt
= IPPROTO_DCCP
;
117 for (i
= 0; i
< sizeof(phu
.pa
) / sizeof(phu
.pa
[0]); i
++)
120 sp
= (const u_int16_t
*)dh
;
122 for (i
= 0; i
< (len
& ~1); i
+= 2)
126 sum
+= htons((*(const u_int8_t
*)sp
) << 8);
129 sum
= (sum
& 0xffff) + (sum
>> 16);
136 static const char *dccp_reset_code(u_int8_t code
)
138 if (code
>= __DCCP_RESET_CODE_LAST
)
140 return dccp_reset_codes
[code
];
143 static u_int64_t
dccp_seqno(const struct dccp_hdr
*dh
)
145 u_int32_t seq_high
= DCCPH_SEQ(dh
);
146 u_int64_t seqno
= EXTRACT_24BITS(&seq_high
) & 0xFFFFFF;
148 if (DCCPH_X(dh
) != 0) {
149 const struct dccp_hdr_ext
*dhx
= (void *)(dh
+ 1);
150 u_int32_t seq_low
= dhx
->dccph_seq_low
;
151 seqno
&= 0x00FFFF; /* clear reserved field */
152 seqno
= (seqno
<< 32) + EXTRACT_32BITS(&seq_low
);
158 static inline unsigned int dccp_basic_hdr_len(const struct dccp_hdr
*dh
)
160 return sizeof(*dh
) + (DCCPH_X(dh
) ? sizeof(struct dccp_hdr_ext
) : 0);
163 static void dccp_print_ack_no(const u_char
*bp
)
165 const struct dccp_hdr
*dh
= (const struct dccp_hdr
*)bp
;
166 const struct dccp_hdr_ack_bits
*dh_ack
=
167 (struct dccp_hdr_ack_bits
*)(bp
+ dccp_basic_hdr_len(dh
));
172 ack_high
= DCCPH_ACK(dh_ack
);
173 ackno
= EXTRACT_24BITS(&ack_high
) & 0xFFFFFF;
175 if (DCCPH_X(dh
) != 0) {
179 ack_low
= dh_ack
->dccph_ack_nr_low
;
181 ackno
&= 0x00FFFF; /* clear reserved field */
182 ackno
= (ackno
<< 32) + EXTRACT_32BITS(&ack_low
);
185 (void)printf("(ack=%" PRIu64
") ", ackno
);
190 static inline unsigned int dccp_packet_hdr_len(const u_int8_t type
)
192 if (type
== DCCP_PKT_DATA
)
194 if (type
== DCCP_PKT_DATAACK
||
195 type
== DCCP_PKT_ACK
||
196 type
== DCCP_PKT_SYNC
||
197 type
== DCCP_PKT_SYNCACK
||
198 type
== DCCP_PKT_CLOSE
||
199 type
== DCCP_PKT_CLOSEREQ
)
200 return sizeof(struct dccp_hdr_ack_bits
);
201 if (type
== DCCP_PKT_REQUEST
)
202 return sizeof(struct dccp_hdr_request
);
203 if (type
== DCCP_PKT_RESPONSE
)
204 return sizeof(struct dccp_hdr_response
);
205 return sizeof(struct dccp_hdr_reset
);
208 static int dccp_print_option(const u_char
*option
);
211 * dccp_print - show dccp packet
212 * @bp - beginning of dccp packet
213 * @data2 - beginning of enclosing
214 * @len - lenght of ip packet
216 void dccp_print(const u_char
*bp
, const u_char
*data2
, u_int len
)
218 const struct dccp_hdr
*dh
;
221 const struct ip6_hdr
*ip6
;
224 u_short sport
, dport
;
228 dh
= (const struct dccp_hdr
*)bp
;
230 ip
= (struct ip
*)data2
;
233 ip6
= (const struct ip6_hdr
*)data2
;
237 cp
= (const u_char
*)(dh
+ 1);
239 printf("[Invalid packet|dccp]");
243 if (len
< sizeof(struct dccp_hdr
)) {
244 printf("truncated-dccp - %ld bytes missing!",
245 (long)len
- sizeof(struct dccp_hdr
));
249 sport
= EXTRACT_16BITS(&dh
->dccph_sport
);
250 dport
= EXTRACT_16BITS(&dh
->dccph_dport
);
251 hlen
= dh
->dccph_doff
* 4;
255 (void)printf("%s.%d > %s.%d: ",
256 ip6addr_string(&ip6
->ip6_src
), sport
,
257 ip6addr_string(&ip6
->ip6_dst
), dport
);
261 (void)printf("%s.%d > %s.%d: ",
262 ipaddr_string(&ip
->ip_src
), sport
,
263 ipaddr_string(&ip
->ip_dst
), dport
);
268 (void)printf(" %d", len
- hlen
);
270 (void)printf("dccp [bad hdr length %u - too long, > %u]",
276 /* other variables in generic header */
278 (void)printf("CCVal %d, CsCov %d, ", DCCPH_CCVAL(dh
), DCCPH_CSCOV(dh
));
281 /* checksum calculation */
284 if (ip6
->ip6_plen
&& vflag
) {
285 u_int16_t sum
, dccp_sum
;
287 sum
= dccp6_cksum(ip6
, dh
, len
);
288 dccp_sum
= EXTRACT_16BITS(&dh
->dccph_checksum
);
289 printf("cksum 0x%04x", dccp_sum
);
291 (void)printf(" (incorrect (-> 0x%04x), ",in_cksum_shouldbe(dccp_sum
, sum
));
293 (void)printf(" (correct), ");
299 u_int16_t sum
, dccp_sum
;
301 sum
= dccp_cksum(ip
, dh
, len
);
302 dccp_sum
= EXTRACT_16BITS(&dh
->dccph_checksum
);
303 printf("cksum 0x%04x", dccp_sum
);
305 (void)printf(" (incorrect (-> 0x%04x), ",in_cksum_shouldbe(dccp_sum
, sum
));
307 (void)printf(" (correct), ");
310 switch (DCCPH_TYPE(dh
)) {
311 case DCCP_PKT_REQUEST
: {
312 struct dccp_hdr_request
*dhr
=
313 (struct dccp_hdr_request
*)(bp
+ dccp_basic_hdr_len(dh
));
315 (void)printf("request (service=%d) ", dhr
->dccph_req_service
);
319 case DCCP_PKT_RESPONSE
: {
320 struct dccp_hdr_response
*dhr
=
321 (struct dccp_hdr_response
*)(bp
+ dccp_basic_hdr_len(dh
));
323 (void)printf("response (service=%d) ", dhr
->dccph_resp_service
);
328 (void)printf("data ");
331 (void)printf("ack ");
335 case DCCP_PKT_DATAACK
: {
336 (void)printf("dataack ");
340 case DCCP_PKT_CLOSEREQ
:
341 (void)printf("closereq ");
345 (void)printf("close ");
348 case DCCP_PKT_RESET
: {
349 struct dccp_hdr_reset
*dhr
=
350 (struct dccp_hdr_reset
*)(bp
+ dccp_basic_hdr_len(dh
));
352 (void)printf("reset (code=%s) ",
353 dccp_reset_code(dhr
->dccph_reset_code
));
358 (void)printf("sync ");
361 case DCCP_PKT_SYNCACK
:
362 (void)printf("syncack ");
366 (void)printf("invalid ");
370 if ((DCCPH_TYPE(dh
) != DCCP_PKT_DATA
) &&
371 (DCCPH_TYPE(dh
) != DCCP_PKT_REQUEST
))
372 dccp_print_ack_no(bp
);
377 (void)printf("seq %" PRIu64
, dccp_seqno(dh
));
379 /* process options */
380 if (hlen
> dccp_basic_hdr_len(dh
) + extlen
){
383 cp
= bp
+ dccp_basic_hdr_len(dh
) + extlen
;
386 hlen
-= dccp_basic_hdr_len(dh
) + extlen
;
389 optlen
= dccp_print_option(cp
);
390 if (!optlen
) goto trunc2
;
391 if (hlen
<= optlen
) break;
405 static int dccp_print_option(const u_char
*option
)
416 optlen
= *(option
+1);
418 printf("Option %d optlen too short",*option
);
423 TCHECK2(*option
,optlen
);
433 printf("slowreceiver");
437 if (*(option
+2) < 10){
438 printf(" %s", dccp_feature_nums
[*(option
+2)]);
439 for (i
= 0; i
< optlen
-3; i
++) printf(" %d", *(option
+3 + i
));
444 if (*(option
+2) < 10){
445 printf(" %s", dccp_feature_nums
[*(option
+2)]);
446 for (i
= 0; i
< optlen
-3; i
++) printf(" %d", *(option
+3 + i
));
451 if (*(option
+2) < 10){
452 printf(" %s", dccp_feature_nums
[*(option
+2)]);
453 for (i
= 0; i
< optlen
-3; i
++) printf(" %d", *(option
+3 + i
));
458 if (*(option
+2) < 10){
459 printf(" %s", dccp_feature_nums
[*(option
+2)]);
460 for (i
= 0; i
< optlen
-3; i
++) printf(" %d", *(option
+3 + i
));
464 printf("initcookie 0x");
465 for (i
= 0; i
< optlen
-2; i
++) printf("%02x", *(option
+2 + i
));
469 for (i
= 0; i
< optlen
-2; i
++) printf(" %d", *(option
+2 + i
));
472 printf("ack_vector0 0x");
473 for (i
= 0; i
< optlen
-2; i
++) printf("%02x", *(option
+2 + i
));
476 printf("ack_vector1 0x");
477 for (i
= 0; i
< optlen
-2; i
++) printf("%02x", *(option
+2 + i
));
480 printf("data_dropped 0x");
481 for (i
= 0; i
< optlen
-2; i
++) printf("%02x", *(option
+2 + i
));
484 ts
= (u_int32_t
*)(option
+ 2);
485 printf("timestamp %u", (u_int32_t
)ntohl(*ts
));
488 ts
= (u_int32_t
*)(option
+ 2);
489 printf("timestamp_echo %u", (u_int32_t
)ntohl(*ts
));
492 printf("elapsed_time ");
494 ts
= (u_int32_t
*)(option
+ 2);
495 printf("%u", (u_int32_t
)ntohl(*ts
));
497 var16
= (u_int16_t
*)(option
+ 2);
498 printf("%u", ntohs(*var16
));
502 printf("data_checksum ");
503 for (i
= 0; i
< optlen
-2; i
++) printf("%02x", *(option
+2 + i
));
506 if (*option
>= 128) {
507 printf("CCID option %d",*option
);
510 var16
= (u_int16_t
*)(option
+ 2);
511 printf(" %u",ntohs(*var16
));
514 var32
= (u_int32_t
*)(option
+ 2);
515 printf(" %u",(u_int32_t
)ntohl(*var32
));
523 printf("unknown_opt %d", *option
);