Changeset d5879cc
- Timestamp:
- 02/27/06 16:40:19 (16 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:
- 8a8e54b
- Parents:
- ab4cb04
- Location:
- lib
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/fifo.c
rf0d19d4 rd5879cc 247 247 size); 248 248 increment_pointer(fifo,IN,size); 249 buffer +=size;249 buffer = (char*)buffer+size; 250 250 lenleft -= size; 251 251 } -
lib/format_erf.c
rab4cb04 rd5879cc 72 72 #endif 73 73 74 #define DATA(x) ((struct libtrace_format_data_t *)x->format_data) 75 #define DATAOUT(x) ((struct libtrace_format_data_out_t *)x->format_data) 74 #define DATA(x) ((struct erf_format_data_t *)x->format_data) 75 #define DATAOUT(x) ((struct erf_format_data_out_t *)x->format_data) 76 76 77 #define CONNINFO DATA(libtrace)->conn_info 77 78 #define INPUT DATA(libtrace)->input … … 81 82 #endif 82 83 #define OPTIONS DATAOUT(libtrace)->options 83 struct libtrace_format_data_t {84 struct erf_format_data_t { 84 85 union { 85 86 struct { … … 106 107 }; 107 108 108 struct libtrace_format_data_out_t {109 struct erf_format_data_out_t { 109 110 union { 110 111 struct { … … 154 155 if (stat(libtrace->uridata, &buf) == -1) { 155 156 trace_set_err(libtrace,errno,"stat(%s)",libtrace->uridata); 156 return 0;157 return -1; 157 158 } 158 159 if (S_ISCHR(buf.st_mode)) { … … 161 162 trace_set_err(libtrace,errno,"Cannot open DAG %s", 162 163 libtrace->uridata); 163 return 0;164 return -1; 164 165 } 165 166 if((DAG.buf = (void *)dag_mmap(INPUT.fd)) == MAP_FAILED) { 166 167 trace_set_err(libtrace,errno,"Cannot mmap DAG %s", 167 168 libtrace->uridata); 168 return 0;169 return -1; 169 170 } 170 171 if(dag_start(INPUT.fd) < 0) { 171 172 trace_set_err(libtrace,errno,"Cannot start DAG %s", 172 173 libtrace->uridata); 173 return 0;174 return -1; 174 175 } 175 176 } else { 176 177 trace_set_err(libtrace,errno,"Not a valid dag device: %s", 177 178 libtrace->uridata); 178 return 0;179 } 180 return 1;179 return -1; 180 } 181 return 0; 181 182 } 182 183 #endif … … 201 202 static int erf_init_input(struct libtrace_t *libtrace) 202 203 { 203 libtrace->format_data = (struct libtrace_format_data_t *)204 malloc(sizeof(struct libtrace_format_data_t)); 205 204 libtrace->format_data = malloc(sizeof(struct erf_format_data_t)); 205 206 return 0; /* success */ 206 207 } 207 208 … … 213 214 return -1; 214 215 215 return 0; 216 return 0; /* success */ 216 217 } 217 218 218 219 static int rtclient_init_input(struct libtrace_t *libtrace) { 219 220 char *scan; 220 libtrace->format_data = (struct libtrace_format_data_t *) 221 malloc(sizeof(struct libtrace_format_data_t)); 221 libtrace->format_data = malloc(sizeof(struct erf_format_data_t)); 222 222 223 223 … … 241 241 } 242 242 } 243 243 244 return 0; /* success */ 244 245 } 245 246 … … 267 268 trace_set_err(libtrace,errno,"connect(%s)", 268 269 CONNINFO.rt.hostname); 269 return 0;270 } 271 return -1;270 return -1; 271 } 272 return 0; 272 273 } 273 274 274 275 static int erf_init_output(struct libtrace_out_t *libtrace) { 275 libtrace->format_data = (struct libtrace_format_data_out_t *) 276 calloc(1,sizeof(struct libtrace_format_data_out_t)); 276 libtrace->format_data = calloc(1,sizeof(struct erf_format_data_out_t)); 277 277 278 278 OPTIONS.erf.level = 0; -
lib/format_helper.h
r0a6638f rd5879cc 38 38 struct libtrace_eventobj_t trace_event_trace(libtrace_t *trace, libtrace_packet_t *packet); 39 39 40 int trace_bpf_compile(libtrace_filter_t *filter, 41 const libtrace_packet_t *packet); 42 40 43 LIBTRACE_FILE trace_open_file(libtrace_t *libtrace); 41 44 LIBTRACE_FILE trace_open_file_out(libtrace_out_t *libtrace, -
lib/format_pcap.c
rab4cb04 rd5879cc 111 111 DATA(libtrace)->promisc = 0; 112 112 113 return 1;113 return 0; 114 114 } 115 115 … … 124 124 } 125 125 if (DATA(libtrace)->filter) { 126 trace_bpf_compile(DATA(libtrace)->filter); 126 pcap_compile(INPUT.pcap, &DATA(libtrace)->filter->filter, 127 DATA(libtrace)->filter->filterstring, 1, 0); 127 128 if (pcap_setfilter(INPUT.pcap,&DATA(libtrace)->filter->filter) 128 129 == -1) { … … 278 279 } 279 280 280 static int pcap_start_output(libtrace_out_t *libtrace)281 {282 assert(!OUTPUT.trace.dump);283 OUTPUT.trace.dump = pcap_dump_open(OUTPUT.trace.pcap,284 libtrace->uridata);285 fflush((FILE *)OUTPUT.trace.dump);286 }287 288 281 static int pcap_write_packet(libtrace_out_t *libtrace, const libtrace_packet_t *packet) { 289 282 struct pcap_pkthdr pcap_pkt_hdr; … … 293 286 libtrace_to_pcap_dlt(trace_get_link_type(packet)), 294 287 65536); 288 OUTPUT.trace.dump = pcap_dump_open(OUTPUT.trace.pcap, 289 libtrace->uridata); 290 fflush((FILE *)OUTPUT.trace.dump); 295 291 } 296 292 if (libtrace->format == &pcap || … … 457 453 pcap_init_output, /* init_output */ 458 454 NULL, /* config_output */ 459 pcap_start_output,/* start_output */455 NULL, /* start_output */ 460 456 pcap_fin_input, /* fin_input */ 461 457 pcap_fin_output, /* fin_output */ -
lib/libtrace_int.h
rab4cb04 rd5879cc 78 78 79 79 #define RP_BUFSIZE 65536 80 81 struct libtrace_format_data_t;82 80 83 81 struct libtrace_event_t { … … 114 112 struct libtrace_out_t { 115 113 struct libtrace_format_t *format; /**< format driver */ 116 struct libtrace_format_data_out_t *format_data;/**< format data */114 void *format_data; /**< format data */ 117 115 bool started; /**< trace started */ 118 116 libtrace_err_t err; /**< Associated error */ … … 152 150 }; 153 151 152 153 154 154 /** Module definition structure */ 155 /* all of these should return -1, or NULL on failure */ 155 156 struct libtrace_format_t { 156 157 /** the uri name of this module */ -
lib/trace.c
rab4cb04 rd5879cc 158 158 } 159 159 format_list[nformats] = f; 160 /* Now, verify things */ 161 if (format_list[nformats]->init_input) { 162 #define REQUIRE(x) \ 163 if (!format_list[nformats]->x) \ 164 fprintf(stderr,"%s: Input format should provide " #x "\n",format_list[nformats]->name) 165 REQUIRE(read_packet); 166 REQUIRE(start_input); 167 REQUIRE(config_input); 168 REQUIRE(pause_input); 169 REQUIRE(fin_input); 170 REQUIRE(get_link_type); 171 REQUIRE(get_capture_length); 172 REQUIRE(get_wire_length); 173 REQUIRE(get_framing_length); 174 REQUIRE(trace_event); 175 if (!format_list[nformats]->get_erf_timestamp 176 && !format_list[nformats]->get_seconds 177 && !format_list[nformats]->get_timeval) { 178 fprintf(stderr,"%s: A trace format capable of input, should provide at least one of\n" 179 "get_erf_timestamp, get_seconds or trace_timeval\n",format_list[nformats]->name); 180 } 181 #undef REQUIRE 182 } 183 else { 184 #define REQUIRE(x) \ 185 if (format_list[nformats]->x) \ 186 fprintf(stderr,"%s: Non Input format shouldn't need " #x "\n",format_list[nformats]->name) 187 REQUIRE(read_packet); 188 REQUIRE(start_input); 189 REQUIRE(pause_input); 190 REQUIRE(fin_input); 191 REQUIRE(get_link_type); 192 REQUIRE(get_capture_length); 193 REQUIRE(get_wire_length); 194 REQUIRE(get_framing_length); 195 REQUIRE(trace_event); 196 #undef REQUIRE 197 } 198 if (format_list[nformats]->init_output) { 199 #define REQUIRE(x) \ 200 if (!format_list[nformats]->x) \ 201 fprintf(stderr,"%s: Output format should provide " #x "\n",format_list[nformats]->name) 202 REQUIRE(write_packet); 203 REQUIRE(start_output); 204 REQUIRE(config_output); 205 REQUIRE(fin_output); 206 #undef REQUIRE 207 } 208 else { 209 #define REQUIRE(x) \ 210 if (format_list[nformats]->x) \ 211 fprintf(stderr,"%s: Non Output format shouldn't need " #x "\n",format_list[nformats]->name) 212 REQUIRE(write_packet); 213 REQUIRE(start_output); 214 REQUIRE(config_output); 215 REQUIRE(fin_output); 216 #undef REQUIRE 217 } 160 218 nformats++; 161 219 } … … 256 314 257 315 if (libtrace->format->init_input) { 258 if (!libtrace->format->init_input(libtrace)) { 316 int err=libtrace->format->init_input(libtrace); 317 assert (err==-1 || err==0); 318 if (err==-1) { 259 319 /* init_input should call trace_set_err to set 260 320 * the error message … … 615 675 } 616 676 617 /* get a pointer to the link layer618 * @param packet a pointer to a libtrace_packet structure619 *620 * @returns a pointer to the link layer, or NULL if there is no link layer621 *622 * @note you should call trace_get_link_type() to find out what type of link layer this is623 */624 677 void *trace_get_link(const struct libtrace_packet_t *packet) { 625 678 return (void *)packet->payload; … … 1293 1346 if (filter->filterstring && ! filter->flag) { 1294 1347 pcap_t *pcap; 1348 libtrace_linktype_t linktype=trace_get_link_type(packet); 1349 if (linktype==(libtrace_linktype_t)-1) { 1350 trace_set_err(packet->trace,TRACE_ERR_BAD_PACKET, 1351 "Packet has an unknown linktype"); 1352 return -1; 1353 } 1354 if (libtrace_to_pcap_dlt(linktype) == -1) { 1355 trace_set_err(packet->trace,TRACE_ERR_BAD_PACKET, 1356 "Unknown pcap equivilent linktype"); 1357 return -1; 1358 } 1295 1359 pcap=(pcap_t *)pcap_open_dead( 1296 libtrace_to_pcap_dlt( trace_get_link_type(packet)),1360 libtrace_to_pcap_dlt(linktype), 1297 1361 1500); 1298 1362 /* build filter */
Note: See TracChangeset
for help on using the changeset viewer.