Changeset 3fb49bc for examples/tracedump
- Timestamp:
- 09/06/04 13:25:39 (18 years ago)
- Branches:
- 4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
- Children:
- 70892e3
- Parents:
- 53de8c0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/tracedump/ip_132.cc
r76b37b0 r3fb49bc 4 4 #include <map> 5 5 #include "tracedump.h" 6 7 #include <sys/socket.h> 6 8 #include <netinet/in.h> 9 #include <arpa/inet.h> 7 10 #include <assert.h> 8 11 … … 23 26 uint8_t type; 24 27 uint8_t flags; 28 uint16_t length; 29 } __attribute__((__packed__)); 30 31 struct sctp_data 32 { 33 uint32_t tsn; 34 uint16_t stream_id; 35 uint16_t stream_seqno; 36 uint32_t payload_proto_id; 37 } __attribute__((__packed__)); 38 39 // The following works for INIT and INIT ACK packets 40 struct sctp_init_ack 41 { 42 uint32_t init_tag; 43 uint32_t rcv_wnd_credit; 44 uint16_t outbound_streams; 45 uint16_t inbound_streams; 46 uint32_t init_tsn; 47 } __attribute__((__packed__)); 48 49 struct sctp_sack 50 { 51 uint32_t tsn_ack; 52 uint32_t a_wnd; 53 uint16_t num_gap_blocks; 54 uint16_t num_dup_tsns; 55 } __attribute__((__packed__)); 56 57 struct sctp_var_param_hdr 58 { 59 uint16_t type; 25 60 uint16_t length; 26 61 } __attribute__((__packed__)); … … 54 89 } 55 90 91 static void parse_options(char *offset, int vlen) 92 { 93 while(vlen > 0) { 94 struct sctp_var_param_hdr *ph = (struct sctp_var_param_hdr *)(offset); 95 char *data = (char *)(ph + 1); 96 97 switch(ntohs(ph->type)) { 98 case 5: 99 { 100 struct in_addr *ia = (struct in_addr *)data; 101 printf(" SCTP: Option IP address %s\n", inet_ntoa(*ia)); 102 } 103 break; 104 case 6: 105 { 106 printf(" SCTP: Option IPv6 address (TODO)\n"); 107 } 108 break; 109 case 7: 110 { 111 printf(" SCTP: Option State cookie\n"); 112 /* // Prolly don't want to print this out :) 113 for(int i = 0; i < ntohs(ph->length) - 8; i++) 114 printf("%02x", data[i]); 115 printf("'\n");*/ 116 } 117 break; 118 case 9: 119 { 120 printf(" SCTP: Option Cookie preservative (TODO)\n"); 121 } 122 break; 123 case 11: 124 { 125 printf(" SCTP: Option Host name %s\n", data); 126 } 127 break; 128 case 12: 129 { 130 uint16_t *p = (uint16_t *)data; 131 int len = ntohs(ph->length) - 132 sizeof(struct sctp_var_param_hdr); 133 134 printf(" SCTP: Option Supported address types "); 135 136 while(len) { 137 printf("%hu ", ntohs(*p)); 138 p++; 139 len -= sizeof(*p); 140 } 141 printf("\n"); 142 } 143 break; 144 default: 145 printf(" SCTP: Option Unknown type=%hu len=%hu\n", 146 ntohs(ph->type), ntohs(ph->length)); 147 } 148 149 vlen -= ntohs(ph->length); 150 offset += ntohs(ph->length); 151 } 152 } 153 56 154 extern "C" 57 155 void decode(int link_type,char *packet,int len) … … 60 158 struct sctp_chunk_hdr *chunk; 61 159 int chunk_num = 1; 62 160 63 161 if(len < (signed)sizeof(struct sctp_common_hdr)) { 64 printf(" SCTP: packet too short!\n");162 printf(" SCTP: packet too short!\n"); 65 163 return; 66 164 } … … 68 166 hdr = (struct sctp_common_hdr *)packet; 69 167 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", 168 printf(" SCTP: Header Src port %hu Dst port %hu Tag %u Csum %u\n", 169 ntohs(hdr->src_port), ntohs(hdr->dst_port), 73 170 ntohl(hdr->verification_tag), ntohl(hdr->checksum)); 74 171 … … 81 178 chunk->length = ntohs(chunk->length); 82 179 83 printf(" SCTP: Chunk %d Type %s Flags %u Len %u\n",180 printf(" SCTP: Chunk %d Type %s Flags %u Len %u\n", 84 181 chunk_num++, 85 182 sctp_type_to_str(chunk->type), chunk->flags, chunk->length); 86 183 87 //packet += sizeof(struct sctp_chunk_hdr);88 //len -= sizeof(struct sctp_chunk_hdr);89 90 184 if(chunk->length == 0) { 91 printf("SCTP: Invalid chunk length, aborting.\n"); 185 printf(" SCTP: Invalid chunk length, aborting.\n\n"); 186 break; 187 } 188 189 switch(chunk->type) { 190 case 0: // DATA 191 { 192 struct sctp_data *data = (struct sctp_data *)(chunk + 1); 193 194 printf(" SCTP: TSN %u Stream ID %hu Stream Seqno %hu " 195 "Payload ID %u\n", 196 ntohl(data->tsn), ntohs(data->stream_id), 197 ntohs(data->stream_seqno), 198 ntohl(data->payload_proto_id)); 199 } 200 break; 201 case 1: // INIT and 202 case 2: // INIT ACK packets have the same structure 203 { 204 // INIT ACK 205 struct sctp_init_ack *ack = (struct sctp_init_ack *) 206 (chunk + 1); 207 208 printf(" SCTP: Tag %u Credit %u Outbound %hu Inbound %hu " 209 "TSN %u\n", 210 ntohl(ack->init_tag), 211 ntohl(ack->rcv_wnd_credit), 212 ntohs(ack->outbound_streams), 213 ntohs(ack->inbound_streams), 214 ntohl(ack->init_tsn)); 215 216 int vlen = chunk->length - (sizeof(struct sctp_init_ack) + 217 sizeof(struct sctp_chunk_hdr) + 218 sizeof(struct sctp_common_hdr) 219 ); 220 parse_options((char *)(ack + 1), vlen); 221 222 } 223 break; 224 case 3: // SACK 225 { 226 struct sctp_sack *sack = (struct sctp_sack *)(chunk + 1); 227 int i; 228 229 printf(" SCTP: Ack %u Wnd %u\n", ntohl(sack->tsn_ack), 230 ntohl(sack->a_wnd)); 231 232 for(i = 0; i < ntohs(sack->num_gap_blocks); i++) { 233 uint16_t *p = (uint16_t *)(sack + 1); 234 p += i * 2; 235 236 printf(" SCTP: Gap ACK Start %hu End %hu\n", 237 ntohs(*p), ntohs(*(p + 1))); 238 } 239 for(i = 0; i < ntohs(sack->num_dup_tsns); i++) { 240 uint32_t *p = (uint32_t *)(sack + 1); 241 p += ntohs(sack->num_gap_blocks) + i; 242 243 printf(" SCTP: Duplicatate TSN %u\n", ntohl(*p)); 244 } 245 } 92 246 break; 93 247 }
Note: See TracChangeset
for help on using the changeset viewer.