1 | /* DCCP */ |
---|
2 | #include <stdio.h> |
---|
3 | #include <inttypes.h> |
---|
4 | #include <dlfcn.h> |
---|
5 | #include "libpacketdump.h" |
---|
6 | #include <netinet/tcp.h> |
---|
7 | #include <netinet/in.h> |
---|
8 | |
---|
9 | #define STRUCT dccp |
---|
10 | |
---|
11 | #define SAFE(x) \ |
---|
12 | ((unsigned int)len>=((char*)&STRUCT->x-(char*)STRUCT+sizeof(STRUCT->x))) |
---|
13 | #define DISPLAY_EXP(x,fmt,exp) \ |
---|
14 | if (SAFE(x)) \ |
---|
15 | printf(fmt,exp); \ |
---|
16 | else \ |
---|
17 | return; |
---|
18 | |
---|
19 | #define DISPLAY(x,fmt) DISPLAY_EXP(x,fmt,STRUCT->x) |
---|
20 | |
---|
21 | #define DISPLAYS(x,fmt) DISPLAY_EXP(x,fmt,htons(STRUCT->x)) |
---|
22 | #define DISPLAYL(x,fmt) DISPLAY_EXP(x,fmt,htonl(STRUCT->x)) |
---|
23 | #define DISPLAYIP(x,fmt) DISPLAY_EXP(x,fmt,inet_ntoa(*(struct in_addr*)&STRUCT->x)) |
---|
24 | |
---|
25 | struct dccphdr { |
---|
26 | uint16_t source; |
---|
27 | uint16_t dest; |
---|
28 | uint8_t type:4; |
---|
29 | uint8_t ccval:4; |
---|
30 | uint32_t seq:24; |
---|
31 | uint8_t doff; |
---|
32 | uint8_t ndp:4; |
---|
33 | uint8_t cslen:4; |
---|
34 | uint16_t check; |
---|
35 | }; |
---|
36 | |
---|
37 | static char *dccp_types[]={ |
---|
38 | "DCCP-Request packet", |
---|
39 | "DCCP-Response packet", |
---|
40 | "DCCP-Data packet", |
---|
41 | "DCCP-Ack packet", |
---|
42 | "DCCP-DataAck packet", |
---|
43 | "DCCP-CloseReq packet", |
---|
44 | "DCCP-Close packet", |
---|
45 | "DCCP-Reset packet", |
---|
46 | "DCCP-Move packet", |
---|
47 | }; |
---|
48 | |
---|
49 | int get_next_option(unsigned char **ptr,int *len, |
---|
50 | unsigned char *type, |
---|
51 | unsigned char *optlen, |
---|
52 | unsigned char **data) |
---|
53 | { |
---|
54 | if (*len<=0) |
---|
55 | return 0; |
---|
56 | *type=**ptr; |
---|
57 | switch(*type) { |
---|
58 | case 0: |
---|
59 | return 0; |
---|
60 | case 1: |
---|
61 | (*ptr)++; |
---|
62 | (*len)--; |
---|
63 | return 1; |
---|
64 | default: |
---|
65 | *optlen = *(*ptr+1); |
---|
66 | (*len)-=*optlen; |
---|
67 | (*data)=(*ptr+2); |
---|
68 | (*ptr)+=*optlen; |
---|
69 | if (*len<0) |
---|
70 | return 0; |
---|
71 | return 1; |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | void decode(int link_type,char *packet,int len) |
---|
76 | { |
---|
77 | struct dccphdr *dccp = (struct dccphdr*)packet; |
---|
78 | DISPLAYS(source," DCCP: Source %i"); |
---|
79 | DISPLAYS(dest," Dest %i"); |
---|
80 | if (len>4) { |
---|
81 | printf("\n DCCP: Type %i",dccp->type); |
---|
82 | if (dccp->type<sizeof(dccp_types)) { |
---|
83 | printf(" (%s)\n",dccp_types[dccp->type]); |
---|
84 | } else { |
---|
85 | printf(" (Unknown)\n"); |
---|
86 | } |
---|
87 | printf(" DCCP: CcVal %i\n",dccp->ccval); |
---|
88 | } |
---|
89 | else { |
---|
90 | printf("\n"); |
---|
91 | return; |
---|
92 | } |
---|
93 | if (len>7) |
---|
94 | printf(" DCCP: Seq %u\n",dccp->seq); // htonwhat? |
---|
95 | else |
---|
96 | return; |
---|
97 | DISPLAY(doff," DCCP: Dataoff: %i\n"); |
---|
98 | if (len>9) |
---|
99 | printf(" DCCP: NDP %i CsLen: %i\n",dccp->ndp,dccp->cslen); |
---|
100 | else { |
---|
101 | return; |
---|
102 | } |
---|
103 | DISPLAY(check," DCCP: Checksum: %i\n"); |
---|
104 | if (htons(dccp->source) < htons(dccp->dest)) |
---|
105 | decode_next(packet+dccp->doff*4,len-dccp->doff*4,"dccp",htons(dccp->source)); |
---|
106 | else |
---|
107 | decode_next(packet+dccp->doff*4,len-dccp->doff*4,"dccp",htons(dccp->dest)); |
---|
108 | return; |
---|
109 | } |
---|