4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change
on this file since d2e3359 was
d907ff5,
checked in by Perry Lorier <perry@…>, 18 years ago
|
Import tracedump to libtrace
|
-
Property mode set to
100644
|
File size:
1.4 KB
|
Line | |
---|
1 | #include <netinet/ether.h> |
---|
2 | #include <netinet/in.h> |
---|
3 | #include <stdio.h> |
---|
4 | #include <stdint.h> |
---|
5 | #include <dlfcn.h> |
---|
6 | #include <map> |
---|
7 | #include <string> |
---|
8 | #include <ctype.h> |
---|
9 | #include "tracedump.h" |
---|
10 | #define DIRNAME "./" |
---|
11 | |
---|
12 | typedef void (*decode_t)(uint16_t type,char *packet,int len); |
---|
13 | |
---|
14 | static std::map<std::string,std::map<uint16_t,decode_t> > decoders; |
---|
15 | |
---|
16 | static void generic_decode(uint16_t type,char *packet, int len) { |
---|
17 | int i; |
---|
18 | printf(" Unknown Protocol: %i",type); |
---|
19 | for(i=0;i<len; /* Nothing */ ) { |
---|
20 | int j; |
---|
21 | printf("\n "); |
---|
22 | for(j=0;j<8;j++) { |
---|
23 | if (i+j<len) |
---|
24 | printf(" %02x",(unsigned char)packet[i+j]); |
---|
25 | else |
---|
26 | printf(" "); |
---|
27 | } |
---|
28 | printf(" "); |
---|
29 | for(j=0;j<8;j++) { |
---|
30 | if (i+j<len) |
---|
31 | if (isprint((unsigned char)packet[i+j])) |
---|
32 | printf("%c",(unsigned char)packet[i+j]); |
---|
33 | else |
---|
34 | printf("."); |
---|
35 | else |
---|
36 | printf(" "); |
---|
37 | } |
---|
38 | if (i+8>len) |
---|
39 | break; |
---|
40 | else |
---|
41 | i+=8; |
---|
42 | } |
---|
43 | printf("\n"); |
---|
44 | } |
---|
45 | |
---|
46 | void decode_next(char *packet,int len,char *proto_name,int type) |
---|
47 | { |
---|
48 | std::string sname(proto_name); |
---|
49 | if (decoders[sname].find(type)==decoders[sname].end()) { |
---|
50 | void *hdl; |
---|
51 | char name[1024]; |
---|
52 | snprintf(name,sizeof(name),DIRNAME "%s_%i.so",sname.c_str(),type); |
---|
53 | hdl = dlopen(name,RTLD_LAZY); |
---|
54 | if (!hdl) |
---|
55 | decoders[sname][type]=generic_decode; |
---|
56 | else { |
---|
57 | void *s=dlsym(hdl,"decode"); |
---|
58 | if (!s) { |
---|
59 | decoders[sname][type]=generic_decode; |
---|
60 | } |
---|
61 | else |
---|
62 | decoders[sname][type]=(decode_t)s; |
---|
63 | } |
---|
64 | } |
---|
65 | decoders[sname][type](type,packet,len); |
---|
66 | } |
---|
67 | |
---|
Note: See
TracBrowser
for help on using the repository browser.