1 | /* |
---|
2 | * |
---|
3 | * Copyright (c) 2007-2016 The University of Waikato, Hamilton, New Zealand. |
---|
4 | * All rights reserved. |
---|
5 | * |
---|
6 | * This file is part of libtrace. |
---|
7 | * |
---|
8 | * This code has been developed by the University of Waikato WAND |
---|
9 | * research group. For further information please see http://www.wand.net.nz/ |
---|
10 | * |
---|
11 | * libtrace is free software; you can redistribute it and/or modify |
---|
12 | * it under the terms of the GNU Lesser General Public License as published by |
---|
13 | * the Free Software Foundation; either version 3 of the License, or |
---|
14 | * (at your option) any later version. |
---|
15 | * |
---|
16 | * libtrace is distributed in the hope that it will be useful, |
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
19 | * GNU Lesser General Public License for more details. |
---|
20 | * |
---|
21 | * You should have received a copy of the GNU Lesser General Public License |
---|
22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
23 | * |
---|
24 | * |
---|
25 | */ |
---|
26 | /* DCCP */ |
---|
27 | #include <stdio.h> |
---|
28 | #include <inttypes.h> |
---|
29 | #include <dlfcn.h> |
---|
30 | #include "libpacketdump.h" |
---|
31 | #include <netinet/tcp.h> |
---|
32 | #include <netinet/in.h> |
---|
33 | |
---|
34 | struct dccphdr { |
---|
35 | uint16_t source; |
---|
36 | uint16_t dest; |
---|
37 | uint8_t type:4; |
---|
38 | uint8_t ccval:4; |
---|
39 | uint32_t seq:24; |
---|
40 | uint8_t doff; |
---|
41 | uint8_t ndp:4; |
---|
42 | uint8_t cslen:4; |
---|
43 | uint16_t check; |
---|
44 | }; |
---|
45 | |
---|
46 | static char *dccp_types[]={ |
---|
47 | "DCCP-Request packet", |
---|
48 | "DCCP-Response packet", |
---|
49 | "DCCP-Data packet", |
---|
50 | "DCCP-Ack packet", |
---|
51 | "DCCP-DataAck packet", |
---|
52 | "DCCP-CloseReq packet", |
---|
53 | "DCCP-Close packet", |
---|
54 | "DCCP-Reset packet", |
---|
55 | "DCCP-Move packet", |
---|
56 | }; |
---|
57 | |
---|
58 | DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len) |
---|
59 | { |
---|
60 | struct dccphdr *dccp = (struct dccphdr*)packet; |
---|
61 | DISPLAYS(dccp, source," DCCP: Source %i"); |
---|
62 | DISPLAYS(dccp, dest," Dest %i"); |
---|
63 | if (len>4) { |
---|
64 | printf("\n DCCP: Type %i",dccp->type); |
---|
65 | if (dccp->type<sizeof(dccp_types)) { |
---|
66 | printf(" (%s)\n",dccp_types[dccp->type]); |
---|
67 | } else { |
---|
68 | printf(" (Unknown)\n"); |
---|
69 | } |
---|
70 | printf(" DCCP: CcVal %i\n",dccp->ccval); |
---|
71 | } |
---|
72 | else { |
---|
73 | printf("\n"); |
---|
74 | return; |
---|
75 | } |
---|
76 | if (len>7) |
---|
77 | printf(" DCCP: Seq %u\n",dccp->seq); // htonwhat? |
---|
78 | else |
---|
79 | return; |
---|
80 | DISPLAY(dccp, doff," DCCP: Dataoff: %i\n"); |
---|
81 | if (len>9) |
---|
82 | printf(" DCCP: NDP %i CsLen: %i\n",dccp->ndp,dccp->cslen); |
---|
83 | else { |
---|
84 | return; |
---|
85 | } |
---|
86 | /* Should this be byteswapped??? */ |
---|
87 | DISPLAY(dccp, check," DCCP: Checksum: %i\n"); |
---|
88 | if (htons(dccp->source) < htons(dccp->dest)) |
---|
89 | decode_next(packet+dccp->doff*4,len-dccp->doff*4,"dccp",htons(dccp->source)); |
---|
90 | else |
---|
91 | decode_next(packet+dccp->doff*4,len-dccp->doff*4,"dccp",htons(dccp->dest)); |
---|
92 | return; |
---|
93 | } |
---|