Changeset 258c1fb
- Timestamp:
- 08/24/04 13:25:38 (17 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:
- 882ff88a
- Parents:
- 505c421
- Location:
- examples/tracedump
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/tracedump/Makefile
r505c421 r258c1fb 5 5 CXXFLAGS=-g -Wall $(INCLUDES) -rdynamic 6 6 LDFLAGS=-L/usr/local/wand/lib 7 LDLIBS=-ltrace -ldl 7 LDLIBS=-ltrace -ldl -lpcap -lz 8 8 LINK_LAYERS=$(addsuffix .so,$(basename $(wildcard link_*.cc))) 9 9 ETH_LAYERS=$(addsuffix .so,$(basename $(wildcard eth_*.cc))) … … 12 12 PLUGINS=$(LINK_LAYERS) $(ETH_LAYERS) $(IP_LAYERS) $(TCP_LAYERS) 13 13 14 all: tracedump $(PLUGINS) asn1-test 14 all: tracedump $(PLUGINS) asn1-test links 15 15 16 16 tracedump: tracedump.cc tracedump-libtrace.o tracedump-lib.o … … 25 25 asn1-test: CXXFLAGS+=-DTEST 26 26 asn1-test: asn1.cc 27 $(CXX) $(CXXFLAGS) $^ -o $@ 28 29 links: links.txt 30 ./make_links 27 31 28 32 clean: … … 32 36 cp *.so $(LIBDIR) 33 37 34 .PHONY: clean all 38 .PHONY: clean all links 35 39 -
examples/tracedump/asn1.cc
rd2e3359 r258c1fb 9 9 #endif 10 10 #include "asn1.h" 11 #include <boost/format.hpp> 11 12 12 13 … … 44 45 }; 45 46 46 void ASN_data:: toString(void) {47 void ASN_data::display(void) { 47 48 printf(" ASN: %s %s 0x%x\n", 48 49 ASN_type_class_t_names[(int)type.getClass()], … … 77 78 printf("\n"); 78 79 } 79 }; // toString 80 }; // display 81 80 82 ASN_data::~ASN_data() {}; 81 83 84 std::string ASN_data::toString(void) { 85 return std::string("Unknown"); 86 }; 82 87 83 88 bool ASN::eof(void) const { … … 93 98 return *buffer.begin()!=0; 94 99 } 95 void toString(void) const {100 void display(void) const { 96 101 printf(" ASN: Bool:\t%s\n",getValue() 97 102 ?"True": … … 113 118 return val; 114 119 } 115 void toString(void) {120 void display(void) { 116 121 printf(" ASN: Int:\t0x"); 117 122 // Yeah, this is a dirty trick … … 125 130 }; 126 131 132 // Type 3 -- Bitstring 133 class ASN_bitstring : public ASN_data { 134 public: 135 ASN_bitstring(ASN_type t,uint64_t l) : ASN_data(t,l) {}; 136 void display(void) { 137 printf(" DEBUG: %i bytes\n",buffer.size()); 138 printf(" ASN: Bitstring:\t0b"); 139 buffer_t::const_iterator i=buffer.begin(); 140 //int bits=*i; 141 i++; 142 for( ; 143 i!=buffer.end(); 144 i++) { 145 for (int j=0;j<7;j++) { 146 if (*i & (1<<(7-j))) { 147 printf("1"); 148 } 149 else { 150 printf("0"); 151 } 152 } 153 printf(" "); 154 } 155 printf("\n"); 156 } 157 }; 127 158 // Types - Simple Strings 128 159 class ASN_string : public ASN_data { … … 138 169 return s; 139 170 } 140 void toString(void) {171 void display(void) { 141 172 printf(" ASN: String:\t%s\n",getValue().c_str()); 142 173 } … … 146 177 public: 147 178 ASN_null(ASN_type t,uint64_t l) : ASN_data(t,l) {}; 148 void toString(void) { printf(" ASN: NULL\n"); } 149 }; 150 151 // Abstract Container for sets and sequences 152 class ASN_container : public ASN_data { 153 private: 154 std::vector<ASN_data *> subencodings; 155 public: 156 typedef std::vector<ASN_data *>::const_iterator const_iterator; 157 ASN_container(ASN_type t,uint64_t l) : ASN_data(t,l) {}; 158 void parse() { 159 ASN n; 160 n.feed(buffer,len); 161 while (!n.eof()) { 162 subencodings.push_back(n.getEncoding()); 163 } 164 }; 165 const_iterator begin(void) { return (const_iterator)subencodings.begin(); } 166 const_iterator end(void) { return (const_iterator)subencodings.end(); } 167 }; 168 169 // Type 16 - Sequence 170 class ASN_sequence : public ASN_container { 171 public: 172 ASN_sequence(ASN_type t,uint64_t l) : ASN_container(t,l) {}; 173 void toString(void) { 174 printf(" ASN: Sequence begin\n"); 175 for(const_iterator i=begin(); 176 i!=end(); 177 i++) 178 (*i)->toString(); 179 printf(" ASN: Sequence end\n"); 180 } 181 }; 182 // Type 17 - Set 183 class ASN_set : public ASN_container { 184 public: 185 ASN_set(ASN_type t,uint64_t l) : ASN_container(t,l) {}; 186 void toString(void) { 187 printf(" ASN: Set begin\n"); 188 for(const_iterator i=begin(); 189 i!=end(); 190 i++) 191 (*i)->toString(); 192 printf(" ASN: Set end\n"); 193 } 179 void display(void) { printf(" ASN: NULL\n"); } 194 180 }; 195 181 … … 217 203 oid.push_back(decodeInt()); 218 204 }; 219 void toString(void) {205 void display(void) { 220 206 printf(" ASN: OID"); 221 207 for(std::vector<uint64_t>::const_iterator i=oid.begin(); … … 226 212 printf("\n"); 227 213 }; 214 std::string toString(void) { 215 std::string ret; 216 for(std::vector<uint64_t>::const_iterator i=oid.begin(); 217 i!=oid.end(); 218 i++) { 219 ret+=(boost::format(" %i") % *i).str(); 220 } 221 return ret; 222 } 223 }; 224 225 226 // Abstract Container for sets and sequences 227 class ASN_container : public ASN_data { 228 protected: 229 std::vector<ASN_data *> subencodings; 230 public: 231 typedef std::vector<ASN_data *>::const_iterator const_iterator; 232 ASN_container(ASN_type t,uint64_t l) : ASN_data(t,l) {}; 233 void parse() { 234 ASN n; 235 n.feed(buffer,len); 236 while (!n.eof()) { 237 subencodings.push_back(n.getEncoding()); 238 } 239 }; 240 const_iterator begin(void) { return (const_iterator)subencodings.begin(); } 241 const_iterator end(void) { return (const_iterator)subencodings.end(); } 242 }; 243 244 // Type 16 - Sequence 245 class ASN_sequence : public ASN_container { 246 public: 247 ASN_sequence(ASN_type t,uint64_t l) : ASN_container(t,l) {}; 248 void display(void) { 249 if (subencodings.size()==2 250 &&subencodings[0]->type.getTag() == 6) { 251 printf(" ASN: Sequence OID (%s)\n",subencodings[0]->toString().c_str()); 252 subencodings[1]->display(); 253 return; 254 } 255 256 printf(" ASN: Sequence begin (%i items)\n",subencodings.size()); 257 for(const_iterator i=begin(); 258 i!=end(); 259 i++) 260 (*i)->display(); 261 printf(" ASN: Sequence end\n"); 262 } 263 }; 264 // Type 17 - Set 265 class ASN_set : public ASN_container { 266 public: 267 ASN_set(ASN_type t,uint64_t l) : ASN_container(t,l) {}; 268 void display(void) { 269 if (subencodings.size()==1) { 270 printf(" ASN: Single item set\n"); 271 subencodings[0]->display(); 272 return; 273 } 274 printf(" ASN: Set begin\n"); 275 for(const_iterator i=begin(); 276 i!=end(); 277 i++) 278 (*i)->display(); 279 printf(" ASN: Set end\n"); 280 } 228 281 }; 229 282 … … 268 321 uint64_t l=getLength(); 269 322 ASN_data *ret; 270 switch(t.getTag()) { 271 case 1: 272 ret=new ASN_bool(t,l); 273 break; 274 case 2: 275 ret=new ASN_int(t,l); 276 break; 277 case 5: 278 ret=new ASN_null(t,l); 279 break; 280 case 6: 281 ret=new ASN_oid(t,l); 282 break; 283 case 16: 284 ret=new ASN_sequence(t,l); 285 break; 286 case 17: 287 ret=new ASN_set(t,l); 288 break; 289 case 18: 290 case 19: 291 case 20: 292 case 21: 293 case 22: 294 case 25: 295 case 26: 296 case 27: 297 ret=new ASN_string(t,l); 323 switch(t.getClass()) { 324 case Universal: 325 switch(t.getTag()) { 326 case 1: 327 ret=new ASN_bool(t,l); 328 break; 329 case 2: 330 ret=new ASN_int(t,l); 331 break; 332 case 3: 333 ret=new ASN_bitstring(t,l); 334 break; 335 case 5: 336 ret=new ASN_null(t,l); 337 break; 338 case 6: 339 ret=new ASN_oid(t,l); 340 break; 341 case 16: 342 ret=new ASN_sequence(t,l); 343 break; 344 case 17: 345 ret=new ASN_set(t,l); 346 break; 347 case 18: 348 case 19: 349 case 20: 350 case 21: 351 case 22: 352 case 25: 353 case 26: 354 case 27: 355 ret=new ASN_string(t,l); 356 break; 357 default: 358 ret=new ASN_data(t,l); 359 break; 360 } 298 361 break; 299 362 default: … … 334 397 asn->feed(buffer,size); 335 398 336 ASN_data *data= asn->getEncoding(); 337 338 data->toString(); 339 data->toString(); 399 while(!asn->eof()) { 400 ASN_data *data= asn->getEncoding(); 401 402 data->display(); 403 } 340 404 341 405 return 0; -
examples/tracedump/asn1.h
rd2e3359 r258c1fb 32 32 virtual void parse(void); 33 33 34 virtual void toString(void); 34 virtual void display(void); 35 virtual std::string toString(void); 35 36 virtual ~ASN_data(); 36 37 }; -
examples/tracedump/eth_2048.cc
rd907ff5 r258c1fb 31 31 } 32 32 DISPLAY(tos," TOS %02x") 33 DISPLAY (tot_len," Total Length %i")33 DISPLAYS(tot_len," Total Length %i") 34 34 printf("\n IP:"); 35 35 DISPLAY(id," Id %i"); -
examples/tracedump/ip_6.cc
r5d6ebe1 r258c1fb 32 32 switch(*type) { 33 33 case 0: 34 printf(" DEBUG: End of options\n");35 34 return 0; 36 35 case 1: 37 printf(" DEBUG: NOP\n");38 36 (*ptr)++; 39 37 (*len)--; 40 38 return 1; 41 39 default: 42 printf(" DEBUG: Type %i len %i\n",43 *type,*(*ptr+1));44 40 *optlen = *(*ptr+1); 45 assert(*optlen> 0);41 assert(*optlen>=2); 46 42 (*len)-=*optlen; 47 43 (*data)=(*ptr+2); 48 (*ptr)+=*optlen ;44 (*ptr)+=*optlen+2; 49 45 if (*len<0) 50 46 return 0; … … 82 78 DISPLAYS(urg_ptr," Urgent %i"); 83 79 unsigned char *pkt = (unsigned char*)packet+sizeof(*tcp); 84 int plen = (len-sizeof *tcp) <? (tcp->doff*4 );80 int plen = (len-sizeof *tcp) <? (tcp->doff*4-sizeof *tcp); 85 81 unsigned char type,optlen,*data; 86 82 while(get_next_option(&pkt,&plen,&type,&optlen,&data)) { … … 94 90 break; 95 91 case 2: 96 printf("MSS %i",hton l(*(uint32_t *)(data)));92 printf("MSS %i",htons(*(uint32_t *)(data))); 97 93 break; 98 94 case 3: -
examples/tracedump/tcp_1720.cc
rd2e3359 r258c1fb 30 30 return; 31 31 asn.feed(packet,len); 32 asn.getEncoding()->toString(); 32 while (!asn.eof()) 33 asn.getEncoding()->display(); 33 34 return; 34 35 } -
examples/tracedump/tracedump-lib.cc
r505c421 r258c1fb 17 17 static std::map<std::string,std::map<uint16_t,decode_t> > decoders; 18 18 19 #define WIDTH 16 20 19 21 static void generic_decode(uint16_t type,char *packet, int len) { 20 22 int i; … … 23 25 int j; 24 26 printf("\n "); 25 for(j=0;j< 8;j++) {27 for(j=0;j<WIDTH;j++) { 26 28 if (i+j<len) 27 29 printf(" %02x",(unsigned char)packet[i+j]); … … 30 32 } 31 33 printf(" "); 32 for(j=0;j< 8;j++) {34 for(j=0;j<WIDTH;j++) { 33 35 if (i+j<len) 34 36 if (isprint((unsigned char)packet[i+j])) … … 39 41 printf(" "); 40 42 } 41 if (i+ 8>len)43 if (i+WIDTH>len) 42 44 break; 43 45 else 44 i+= 8;46 i+=WIDTH; 45 47 } 46 48 printf("\n");
Note: See TracChangeset
for help on using the changeset viewer.