1 | #include <stdio.h> |
---|
2 | #include <stdint.h> |
---|
3 | #include <dlfcn.h> |
---|
4 | #include <map> |
---|
5 | #include "tracedump.h" |
---|
6 | #include <netinet/in.h> |
---|
7 | #include <assert.h> |
---|
8 | |
---|
9 | /* SCTP decoding by Sam Jansen, 31/08/2004 |
---|
10 | * |
---|
11 | * Based on RFC 2960 - Stream Control Transmission Protocol |
---|
12 | */ |
---|
13 | |
---|
14 | struct sctp_common_hdr |
---|
15 | { |
---|
16 | uint16_t src_port, dst_port; |
---|
17 | uint32_t verification_tag; |
---|
18 | uint32_t checksum; |
---|
19 | } __attribute__((__packed__)); |
---|
20 | |
---|
21 | struct sctp_chunk_hdr |
---|
22 | { |
---|
23 | uint8_t type; |
---|
24 | uint8_t flags; |
---|
25 | uint16_t length; |
---|
26 | } __attribute__((__packed__)); |
---|
27 | |
---|
28 | static char *sctp_type_to_str(uint8_t type) |
---|
29 | { |
---|
30 | switch(type) |
---|
31 | { |
---|
32 | case 0: return "DATA"; |
---|
33 | case 1: return "INIT"; |
---|
34 | case 2: return "INIT ACK"; |
---|
35 | case 3: return "SACK"; |
---|
36 | case 4: return "HEARTBEAT"; |
---|
37 | case 5: return "HEARTBEAT ACK"; |
---|
38 | case 6: return "ABORT"; |
---|
39 | case 7: return "SHUTDOWN"; |
---|
40 | case 8: return "SHUTDOWN ACK"; |
---|
41 | case 9: return "ERROR"; |
---|
42 | case 10: return "COOKIE ECHO"; |
---|
43 | case 11: return "COOKIE ACK"; |
---|
44 | case 12: return "Reserved for ECNE"; |
---|
45 | case 13: return "Reserved for CWR"; |
---|
46 | case 14: return "SHUTDOWN COMPLETE"; |
---|
47 | case 63: |
---|
48 | case 127: |
---|
49 | case 191: |
---|
50 | case 255: return "IETF-defined Chunk Extensions"; |
---|
51 | }; |
---|
52 | |
---|
53 | return "reserved by IETF"; |
---|
54 | } |
---|
55 | |
---|
56 | extern "C" |
---|
57 | void decode(int link_type,char *packet,int len) |
---|
58 | { |
---|
59 | struct sctp_common_hdr *hdr; |
---|
60 | struct sctp_chunk_hdr *chunk; |
---|
61 | int chunk_num = 1; |
---|
62 | |
---|
63 | if(len < (signed)sizeof(struct sctp_common_hdr)) { |
---|
64 | printf("SCTP: packet too short!\n"); |
---|
65 | return; |
---|
66 | } |
---|
67 | |
---|
68 | hdr = (struct sctp_common_hdr *)packet; |
---|
69 | |
---|
70 | printf("SCTP: Header Src port %u Dst port %u\n", |
---|
71 | ntohs(hdr->src_port), ntohs(hdr->dst_port)); |
---|
72 | printf("SCTP: Verification tag %u Checksum %u\n", |
---|
73 | ntohl(hdr->verification_tag), ntohl(hdr->checksum)); |
---|
74 | |
---|
75 | len -= sizeof(struct sctp_common_hdr); |
---|
76 | packet += sizeof(struct sctp_common_hdr); |
---|
77 | |
---|
78 | while(len > 0) { |
---|
79 | chunk = (struct sctp_chunk_hdr *)packet; |
---|
80 | |
---|
81 | chunk->length = ntohs(chunk->length); |
---|
82 | |
---|
83 | printf("SCTP: Chunk %d Type %s Flags %u Len %u\n", |
---|
84 | chunk_num++, |
---|
85 | sctp_type_to_str(chunk->type), chunk->flags, chunk->length); |
---|
86 | |
---|
87 | //packet += sizeof(struct sctp_chunk_hdr); |
---|
88 | //len -= sizeof(struct sctp_chunk_hdr); |
---|
89 | |
---|
90 | if(chunk->length == 0) { |
---|
91 | printf("SCTP: Invalid chunk length, aborting.\n"); |
---|
92 | break; |
---|
93 | } |
---|
94 | |
---|
95 | packet += chunk->length; |
---|
96 | len -= chunk->length; |
---|
97 | } |
---|
98 | printf("\n"); |
---|
99 | } |
---|