2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2009, 2010 Daniel Borkmann.
4 * Copyright 2018 Markus Amend
5 * Subject to the GPL, version 2.
10 #include <netinet/in.h> /* for ntohs() */
22 #if defined(__LITTLE_ENDIAN_BITFIELD)
23 __extension__
uint32_t x
:1,
27 #elif defined (__BIG_ENDIAN_BITFIELD)
28 __extension__
uint32_t res
:3,
33 # error "Please fix <asm/byteorder.h>"
47 struct ack_extsubhdr
{
53 static char* dccp_pkt_type(uint8_t type
) {
55 case 0: return "Request";
56 case 1: return "Response";
57 case 2: return "Data";
59 case 4: return "DataAck";
60 case 5: return "CloseReq";
61 case 6: return "Close";
62 case 7: return "Reset";
63 case 8: return "Sync";
64 case 9: return "SyncAck";
65 case 10 ... 15: return "Reserved";
70 static void dccp(struct pkt_buff
*pkt
)
72 struct dccphdr
*dccp
= (struct dccphdr
*) pkt_pull(pkt
, sizeof(*dccp
));
73 struct dccpexthdr
*dccpext
= NULL
;
74 struct ack_subhdr
*ack
= NULL
;
75 struct ack_extsubhdr
*ackext
= NULL
;
84 used_hdr
+= sizeof(*dccp
);
86 seqnr
= (uint64_t) ntohl(dccp
->sqnr
);
88 /* check for extended sequence number */
90 dccpext
= (struct dccpexthdr
*) pkt_pull(pkt
, sizeof(*dccpext
));
94 used_hdr
+= sizeof(*dccpext
);
95 seqnr
= (((uint64_t) seqnr
)<<24) | ntohl(dccpext
->seqnr_low
);
98 /* check for ack header */
99 if (dccp
->type
== 1 || (dccp
->type
>= 2 && dccp
->type
<= 9)) {
101 /* Extended ack header */
102 ackext
= (struct ack_extsubhdr
*) pkt_pull(pkt
, sizeof(*ackext
));
106 used_hdr
+= sizeof(*ackext
);
107 acknr
= (((uint64_t) ntohs(ackext
->acknr_high
))<<32) |
108 ntohl(ackext
->acknr_low
);
110 /* standard ack header */
111 ack
= (struct ack_subhdr
*) pkt_pull(pkt
, sizeof(*ack
));
115 used_hdr
+= sizeof(*ack
);
116 acknr
= ntohl((uint32_t) ack
->acknr_low
);
120 src
= ntohs(dccp
->source
);
121 dest
= ntohs(dccp
->dest
);
124 tprintf("Port (%u", src
);
125 tprintf(" => %u", dest
);
127 tprintf("Header Len (%u Bytes), ", dccp
->data_offs
* 4);
128 tprintf("Type: %s, ", dccp_pkt_type((uint8_t) dccp
->type
));
129 tprintf("Seqnr:%lu", seqnr
);
131 tprintf(", AckNr:%lu", acknr
);
135 static void dccp_less(struct pkt_buff
*pkt
)
137 struct dccphdr
*dccp
= (struct dccphdr
*) pkt_pull(pkt
, sizeof(*dccp
));
143 src
= ntohs(dccp
->source
);
144 dest
= ntohs(dccp
->dest
);
146 tprintf(" DCCP %u", src
);
147 tprintf("/%u", dest
);
150 struct protocol dccp_ops
= {
153 .print_less
= dccp_less
,