Changeset abc66e7
- Timestamp:
- 05/18/06 11:57:14 (15 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:
- 003cb8a
- Parents:
- cd7eec7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libpacketdump/libpacketdump.cc
r3b8a5ef rabc66e7 46 46 #include <ctype.h> 47 47 #include "libpacketdump.h" 48 extern "C"{ 49 #include "parser/parser.h" 50 } 48 51 49 typedef void (*decode_t)(uint16_t type,char *packet,int len); 52 enum decode_style_t { 53 DECODE_NORMAL, 54 DECODE_PARSER 55 }; 56 57 typedef void (*decode_norm_t)(uint16_t type,char *packet,int len); 58 typedef void (*decode_parser_t)(uint16_t type,char *packet,int len, element_t* el); 59 60 typedef union decode_funcs { 61 decode_norm_t decode_n; 62 decode_parser_t decode_p; 63 } decode_funcs_t; 64 65 typedef struct decoder { 66 enum decode_style_t style; 67 decode_funcs_t *func; 68 element_t *el; // make a union of structs with all args in it for all funcs? 69 } decode_t; 70 50 71 51 72 static std::map<std::string,std::map<uint16_t,decode_t> > decoders; … … 102 123 { 103 124 std::string sname(proto_name); 125 126 // if we haven't worked out how to decode this type yet, load the 127 // appropriate files to do so 104 128 if (decoders[sname].find(type)==decoders[sname].end()) { 105 129 void *hdl; 106 130 char name[1024]; 131 decode_funcs_t *func = new decode_funcs_t; 132 decode_t dec; 107 133 snprintf(name,sizeof(name),"%s/%s_%i.so",DIRNAME,sname.c_str(),type); 108 134 hdl = dlopen(name,RTLD_LAZY); 109 if (!hdl) 110 decoders[sname][type]=generic_decode; 111 else { 135 if (!hdl) { 136 // if there is no shared library, try a protocol file 137 snprintf(name,sizeof(name),"%s/%s_%i.protocol", 138 DIRNAME,sname.c_str(),type); 139 hdl = parse_protocol_file(name); 140 141 if(!hdl) 142 { 143 // no protocol file either, use a generic one 144 func->decode_n = generic_decode; 145 dec.style = DECODE_NORMAL; 146 dec.el = NULL; 147 } else { 148 // use the protocol file 149 func->decode_p = decode_protocol_file; 150 dec.style = DECODE_PARSER; 151 dec.el = (element_t*)hdl; 152 } 153 } else { 112 154 void *s=dlsym(hdl,"decode"); 113 155 if (!s) { 114 decoders[sname][type]=generic_decode; 156 // the shared library doesnt have a decode func 157 // TODO should try the protocol file now 158 func->decode_n = generic_decode; 159 dec.style = DECODE_NORMAL; 160 dec.el = NULL; 115 161 } 116 162 else 117 decoders[sname][type]=(decode_t)s; 163 { 164 // use the shared library 165 func->decode_n = (decode_norm_t)s; 166 dec.style = DECODE_NORMAL; 167 dec.el = NULL; 168 } 118 169 } 170 dec.func = func; 171 decoders[sname][type] = dec; 119 172 } 120 decoders[sname][type](type,packet,len); 173 174 // decode using the appropriate function 175 switch(decoders[sname][type].style) 176 { 177 case DECODE_NORMAL: 178 decoders[sname][type].func->decode_n(type,packet,len); 179 break; 180 181 case DECODE_PARSER: 182 decoders[sname][type].func->decode_p(type,packet,len, 183 decoders[sname][type].el); 184 break; 185 186 }; 121 187 } 122 123
Note: See TracChangeset
for help on using the changeset viewer.