Changeset 1332
- Timestamp:
- 26/03/08 10:45:36 (10 months ago)
- Files:
-
- trunk/lib/format_atmhdr.c (modified) (3 diffs)
- trunk/lib/format_bpf.c (modified) (5 diffs)
- trunk/lib/format_dag24.c (modified) (9 diffs)
- trunk/lib/format_dag25.c (modified) (13 diffs)
- trunk/lib/format_duck.c (modified) (7 diffs)
- trunk/lib/format_erf.c (modified) (6 diffs)
- trunk/lib/format_legacy.c (modified) (12 diffs)
- trunk/lib/format_linux.c (modified) (7 diffs)
- trunk/lib/format_pcap.c (modified) (5 diffs)
- trunk/lib/format_pcapfile.c (modified) (5 diffs)
- trunk/lib/format_rt.c (modified) (7 diffs)
- trunk/lib/format_tsh.c (modified) (6 diffs)
- trunk/lib/libtrace.h.in (modified) (1 diff)
- trunk/lib/libtrace_int.h (modified) (2 diffs)
- trunk/lib/trace.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/format_atmhdr.c
r1303 r1332 56 56 } 57 57 58 static int atmhdr_prepare_packet(libtrace_t *libtrace, 59 libtrace_packet_t *packet, void *buffer, 60 libtrace_rt_types_t rt_type, uint32_t flags) { 61 62 if (packet->buffer != buffer && 63 packet->buf_control == TRACE_CTRL_PACKET) { 64 free(packet->buffer); 65 } 66 67 if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) { 68 packet->buf_control = TRACE_CTRL_PACKET; 69 } else 70 packet->buf_control = TRACE_CTRL_EXTERNAL; 71 72 packet->buffer = buffer; 73 packet->header = buffer; 74 packet->payload = (void*)((char*)packet->buffer + 75 libtrace->format->get_framing_length(packet)); 76 packet->type = rt_type; 77 78 if (libtrace->format_data == NULL) { 79 if (atmhdr_init_input(libtrace)) 80 return -1; 81 } 82 return 0; 83 } 84 58 85 static int atmhdr_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { 59 86 int numbytes; 60 87 void *buffer; 61 88 uint32_t flags = 0; 89 62 90 if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) { 63 packet->buf_control = TRACE_CTRL_PACKET;64 91 packet->buffer=malloc((size_t)LIBTRACE_PACKET_BUFSIZE); 65 92 } 66 93 buffer = packet->buffer; 67 94 flags |= TRACE_PREP_OWN_BUFFER; 95 68 96 packet->type = TRACE_RT_DATA_ATMHDR; 69 97 … … 76 104 } 77 105 78 packet->header = packet->buffer; 79 packet->payload = (void*)((char*)packet->buffer + 80 libtrace->format->get_framing_length(packet)); 81 106 if (atmhdr_prepare_packet(libtrace, packet, buffer, 107 TRACE_RT_DATA_ATMHDR, flags)) { 108 return -1; 109 } 110 111 82 112 return 12; 83 113 } … … 117 147 NULL, /* fin_output */ 118 148 atmhdr_read_packet, /* read_packet */ 119 NULL, /* fin_packet */ 149 atmhdr_prepare_packet, /* prepare_packet */ 150 NULL, /* fin_packet */ 120 151 NULL, /* write_packet */ 121 152 atmhdr_get_link_type, /* get_link_type */ trunk/lib/format_bpf.c
r1321 r1332 206 206 static uint64_t bpf_get_received_packets(libtrace_t *trace) 207 207 { 208 if (trace->format_data == NULL) 209 return (uint64_t)-1; 210 211 if (FORMATIN(trace)->fd == -1) { 212 /* Almost certainly a 'dead' trace so there is no socket 213 * for us to query */ 214 return (uint64_t) -1; 215 } 208 216 /* If we're called with stats_valid == 0, or we're called again 209 217 * then refresh the stats. Don't refresh the stats if we're called … … 221 229 static uint64_t bpf_get_dropped_packets(libtrace_t *trace) 222 230 { 231 if (trace->format_data == NULL) 232 return (uint64_t)-1; 233 234 if (FORMATIN(trace)->fd == -1) { 235 /* Almost certainly a 'dead' trace so there is no socket 236 * for us to query */ 237 return (uint64_t) -1; 238 } 223 239 /* If we're called with stats_valid == 0, or we're called again 224 240 * then refresh the stats. Don't refresh the stats if we're called … … 282 298 } 283 299 300 static int bpf_prepare_packet(libtrace_t *libtrace, libtrace_packet_t *packet, 301 void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) { 302 if (packet->buffer != buffer && 303 packet->buf_control == TRACE_CTRL_PACKET) { 304 free(packet->buffer); 305 } 306 307 if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) { 308 packet->buf_control = TRACE_CTRL_PACKET; 309 } else 310 packet->buf_control = TRACE_CTRL_EXTERNAL; 311 312 313 packet->buffer = buffer; 314 packet->header = buffer; 315 packet->type = rt_type; 316 317 /* Find the payload */ 318 /* TODO: Pcap deals with a padded FDDI linktype here */ 319 packet->payload=(char *)buffer + BPFHDR(packet)->bh_hdrlen; 320 321 if (libtrace->format_data == NULL) { 322 if (bpf_init_input(libtrace)) 323 return -1; 324 } 325 326 return 0; 327 } 328 284 329 static int bpf_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) 285 330 { 331 uint32_t flags = 0; 332 286 333 /* Fill the buffer */ 287 334 if (FORMATIN(libtrace)->remaining<=0) { … … 311 358 if (packet->buf_control == TRACE_CTRL_PACKET) 312 359 free(packet->buffer); 313 packet->buf_control = TRACE_CTRL_EXTERNAL; 314 315 /* Find the bpf header */ 316 packet->header=FORMATIN(libtrace)->bufptr; 317 318 /* Find the payload */ 319 /* TODO: Pcap deals with a padded FDDI linktype here */ 320 packet->payload=FORMATIN(libtrace)->bufptr+BPFHDR(packet)->bh_hdrlen; 360 361 if (bpf_prepare_packet(libtrace, packet, FORMATIN(libtrace)->bufptr, 362 TRACE_RT_DATA_BPF, flags)) { 363 return -1; 364 } 365 321 366 322 367 /* Now deal with any padding */ … … 389 434 NULL, /* fin_output */ 390 435 bpf_read_packet, /* read_packet */ 436 bpf_prepare_packet, /* prepare_packet */ 391 437 NULL, /* fin_packet */ 392 438 NULL, /* write_packet */ trunk/lib/format_dag24.c
r1328 r1332 83 83 }; 84 84 85 static void dag_init_format_data(libtrace_t *libtrace) { 86 libtrace->format_data = (struct dag_format_data_t *) 87 malloc(sizeof(struct dag_format_data_t)); 88 89 DUCK.last_duck = 0; 90 DUCK.duck_freq = 0; 91 DUCK.last_pkt = 0; 92 DUCK.dummy_duck = NULL; 93 FORMAT_DATA->drops = 0; 94 FORMAT_DATA->top = 0; 95 FORMAT_DATA->bottom = 0; 96 FORMAT_DATA->buf = NULL; 97 FORMAT_DATA->fd = -1; 98 FORMAT_DATA->offset = 0; 99 FORMAT_DATA->diff = 0; 100 } 101 85 102 static int dag_available(libtrace_t *libtrace) { 86 103 … … 120 137 } 121 138 122 libtrace->format_data = (struct dag_format_data_t *) 123 malloc(sizeof(struct dag_format_data_t)); 124 FORMAT_DATA->top = 0; 125 FORMAT_DATA->bottom = 0; 139 dag_init_format_data(libtrace); 126 140 if (S_ISCHR(buf.st_mode)) { 127 141 /* DEVICE */ … … 145 159 } 146 160 147 DUCK.last_duck = 0;148 DUCK.duck_freq = 0;149 DUCK.last_pkt = 0;150 DUCK.dummy_duck = NULL;151 FORMAT_DATA->drops = 0;152 161 free(dag_dev_name); 153 162 … … 259 268 } 260 269 261 static void dag_form_packet(dag_record_t *erfptr, libtrace_packet_t *packet) { 270 static int dag_prepare_packet(libtrace_t *libtrace, libtrace_packet_t *packet, 271 void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) { 272 273 dag_record_t *erfptr; 274 if (packet->buffer != buffer && 275 packet->buf_control == TRACE_CTRL_PACKET) { 276 free(packet->buffer); 277 } 278 279 if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) { 280 packet->buf_control = TRACE_CTRL_PACKET; 281 } else 282 packet->buf_control = TRACE_CTRL_EXTERNAL; 283 284 erfptr = (dag_record_t *)packet->buffer; 262 285 packet->buffer = erfptr; 263 286 packet->header = erfptr; 264 packet->type = TRACE_RT_DATA_ERF; 287 packet->type = rt_type; 288 265 289 if (erfptr->flags.rxerror == 1) { 266 290 /* rxerror means the payload is corrupt - drop it … … 273 297 } 274 298 299 if (libtrace->format_data == NULL) { 300 dag_init_format_data(libtrace); 301 } 302 303 DATA(libtrace)->drops += ntohs(erfptr->lctr); 304 305 return 0; 306 275 307 } 276 308 … … 278 310 int numbytes; 279 311 int size = 0; 280 struct timeval tv; 312 uint32_t flags = 0; 313 struct timeval tv; 281 314 dag_record_t *erfptr = NULL; 282 315 … … 307 340 erfptr = dag_get_record(libtrace); 308 341 } while (erfptr == NULL); 309 dag_form_packet(erfptr, packet); 310 tv = trace_get_timeval(packet); 342 343 344 if (dag_prepare_packet(libtrace, packet, erfptr, TRACE_RT_DATA_ERF, 345 flags)) 346 return -1; 347 tv = trace_get_timeval(packet); 311 348 DUCK.last_pkt = tv.tv_sec; 312 DATA(libtrace)->drops += ntohs(erfptr->lctr);313 349 return packet->payload ? htons(erfptr->rlen) : erf_get_framing_length(packet); 314 350 } … … 348 384 static uint64_t dag_get_dropped_packets(libtrace_t *trace) 349 385 { 386 if (!trace->format_data) 387 return (uint64_t)-1; 350 388 return DATA(trace)->drops; 351 389 } … … 377 415 NULL, /* fin_output */ 378 416 dag_read_packet, /* read_packet */ 379 NULL, /* fin_packet */ 417 dag_prepare_packet, /* prepare_packet */ 418 NULL, /* fin_packet */ 380 419 NULL, /* write_packet */ 381 420 erf_get_link_type, /* get_link_type */ trunk/lib/format_dag25.c
r1330 r1332 99 99 struct dag_dev_t *open_dags = NULL; 100 100 101 static void dag_init_format_data(libtrace_t *libtrace) { 102 libtrace->format_data = (struct dag_format_data_t *) 103 malloc(sizeof(struct dag_format_data_t)); 104 DUCK.last_duck = 0; 105 DUCK.duck_freq = 0; 106 DUCK.last_pkt = 0; 107 DUCK.dummy_duck = NULL; 108 FORMAT_DATA->stream_attached = 0; 109 FORMAT_DATA->drops = 0; 110 FORMAT_DATA->device = NULL; 111 FORMAT_DATA->dagstream = 0; 112 FORMAT_DATA->processed = 0; 113 FORMAT_DATA->bottom = NULL; 114 FORMAT_DATA->top = NULL; 115 } 116 101 117 /* NOTE: This function assumes the open_dag_mutex is held by the caller */ 102 118 static struct dag_dev_t *dag_find_open_device(char *dev_name) { … … 187 203 struct dag_dev_t *dag_device = NULL; 188 204 205 dag_init_format_data(libtrace); 189 206 pthread_mutex_lock(&open_dag_mutex); 190 207 if ((scan = strchr(libtrace->uridata,',')) == NULL) { … … 197 214 198 215 199 libtrace->format_data = (struct dag_format_data_t *)200 malloc(sizeof(struct dag_format_data_t));201 216 202 217 /* For now, we don't offer the ability to select the stream */ … … 219 234 } 220 235 221 222 223 DUCK.last_duck = 0;224 DUCK.duck_freq = 0;225 DUCK.last_pkt = 0;226 DUCK.dummy_duck = NULL;227 236 FORMAT_DATA->device = dag_device; 228 FORMAT_DATA->stream_attached = 0;229 FORMAT_DATA->drops = 0;230 237 231 238 pthread_mutex_unlock(&open_dag_mutex); … … 402 409 } 403 410 404 static void dag_form_packet(dag_record_t *erfptr, libtrace_packet_t *packet) { 405 packet->buffer = erfptr; 411 static int dag_prepare_packet(libtrace_t *libtrace, libtrace_packet_t *packet, 412 void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) { 413 414 dag_record_t *erfptr; 415 416 if (packet->buffer != buffer && 417 packet->buf_control == TRACE_CTRL_PACKET) { 418 free(packet->buffer); 419 } 420 421 if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) { 422 packet->buf_control = TRACE_CTRL_PACKET; 423 } else 424 packet->buf_control = TRACE_CTRL_EXTERNAL; 425 426 erfptr = (dag_record_t *)packet->buffer; 427 packet->buffer = erfptr; 406 428 packet->header = erfptr; 407 packet->type = TRACE_RT_DATA_ERF; 408 if (erfptr->flags.rxerror == 1) { 429 packet->type = rt_type; 430 431 if (erfptr->flags.rxerror == 1) { 409 432 /* rxerror means the payload is corrupt - drop it 410 433 * by tweaking rlen */ … … 415 438 + erf_get_framing_length(packet); 416 439 } 417 440 441 if (libtrace->format_data == NULL) { 442 dag_init_format_data(libtrace); 443 } 444 445 /* No loss counter for DSM coloured records - have to use 446 * some other API */ 447 if (erfptr->type == TYPE_DSM_COLOR_ETH) { 448 449 } else { 450 DATA(libtrace)->drops += ntohs(erfptr->lctr); 451 } 452 453 return 0; 418 454 } 419 455 … … 424 460 dag_record_t *erfptr = NULL; 425 461 int numbytes = 0; 462 uint32_t flags = 0; 426 463 427 464 if (DUCK.last_pkt - DUCK.last_duck > DUCK.duck_freq && … … 437 474 438 475 if (packet->buf_control == TRACE_CTRL_PACKET) { 439 packet->buf_control = TRACE_CTRL_EXTERNAL;440 476 free(packet->buffer); 441 477 packet->buffer = 0; … … 452 488 } while (erfptr == NULL); 453 489 454 dag_form_packet(erfptr, packet); 490 //dag_form_packet(erfptr, packet); 491 if (dag_prepare_packet(libtrace, packet, erfptr, TRACE_RT_DATA_ERF, 492 flags)) 493 return -1; 455 494 tv = trace_get_timeval(packet); 456 495 DUCK.last_pkt = tv.tv_sec; 457 496 458 /* No loss counter for DSM coloured records - have to use459 * some other API */460 if (erfptr->type == TYPE_DSM_COLOR_ETH) {461 462 } else {463 DATA(libtrace)->drops += ntohs(erfptr->lctr);464 }465 497 return packet->payload ? htons(erfptr->rlen) : 466 498 erf_get_framing_length(packet); … … 472 504 dag_record_t *erfptr = NULL; 473 505 int numbytes; 506 uint32_t flags = 0; 474 507 475 508 /* Need to call dag_available so that the top pointer will get … … 487 520 return event; 488 521 } 489 dag_form_packet(erfptr, packet); 522 //dag_form_packet(erfptr, packet); 523 if (dag_prepare_packet(trace, packet, erfptr, TRACE_RT_DATA_ERF, 524 flags)) { 525 event.type = TRACE_EVENT_TERMINATE; 526 return event; 527 } 528 529 490 530 event.size = trace_get_capture_length(packet) + trace_get_framing_length(packet); 491 531 if (trace->filter) { … … 509 549 510 550 static uint64_t dag_get_dropped_packets(libtrace_t *trace) { 551 if (trace->format_data == NULL) 552 return (uint64_t)-1; 511 553 return DATA(trace)->drops; 512 554 } … … 538 580 NULL, /* fin_output */ 539 581 dag_read_packet, /* read_packet */ 540 NULL, /* fin_packet */ 582 dag_prepare_packet, /* prepare_packet */ 583 NULL, /* fin_packet */ 541 584 NULL, /* write_packet */ 542 585 erf_get_link_type, /* get_link_type */ trunk/lib/format_duck.c
r1319 r1332 133 133 } 134 134 135 static int duck_prepare_packet(libtrace_t *libtrace, libtrace_packet_t *packet, 136 void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) { 137 138 if (packet->buffer != buffer && 139 packet->buf_control == TRACE_CTRL_PACKET) { 140 free(packet->buffer); 141 } 142 143 if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) { 144 packet->buf_control = TRACE_CTRL_PACKET; 145 } else 146 packet->buf_control = TRACE_CTRL_EXTERNAL; 147 148 149 packet->buffer = buffer; 150 packet->header = NULL; 151 packet->payload = buffer; 152 packet->type = rt_type; 153 154 if (libtrace->format_data == NULL) { 155 if (duck_init_input(libtrace)) 156 return -1; 157 } 158 159 return 0; 160 } 161 135 162 static int duck_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { 136 163 … … 138 165 uint32_t version = 0; 139 166 unsigned int duck_size; 167 uint32_t flags = 0; 140 168 141 169 if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) { 142 170 packet->buffer = malloc((size_t)LIBTRACE_PACKET_BUFSIZE); 143 packet->buf_control = TRACE_CTRL_PACKET;144 171 if (!packet->buffer) { 145 172 trace_set_err(libtrace, errno, … … 149 176 } 150 177 178 flags |= TRACE_PREP_OWN_BUFFER; 179 151 180 if (INPUT->dag_version == 0) { 152 181 /* Read in the duck version from the start of the trace */ … … 164 193 165 194 166 packet->header = 0;167 packet->payload = packet->buffer;168 169 195 if (INPUT->dag_version == TRACE_RT_DUCK_2_4) { 170 196 duck_size = sizeof(duck2_4_t); … … 180 206 } 181 207 182 if ((numbytes = libtrace_io_read(INPUT->file, packet-> payload,208 if ((numbytes = libtrace_io_read(INPUT->file, packet->buffer, 183 209 (size_t)duck_size)) != (int)duck_size) { 184 210 if (numbytes == -1) { … … 194 220 } 195 221 222 if (duck_prepare_packet(libtrace, packet, packet->buffer, packet->type, 223 flags)) 224 return -1; 225 196 226 return numbytes; 197 227 } … … 284 314 duck_fin_output, /* fin_output */ 285 315 duck_read_packet, /* read_packet */ 286 NULL, /* fin_packet */ 316 duck_prepare_packet, /* prepare_packet */ 317 NULL, /* fin_packet */ 287 318 duck_write_packet, /* write_packet */ 288 319 duck_get_link_type, /* get_link_type */ trunk/lib/format_erf.c
r1331 r1332 342 342 } 343 343 344 static int erf_prepare_packet(libtrace_t *libtrace, libtrace_packet_t *packet, 345 void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) { 346 347 dag_record_t *erfptr; 348 349 if (packet->buffer != buffer && 350 packet->buf_control == TRACE_CTRL_PACKET) { 351 free(packet->buffer); 352 } 353 354 if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) { 355 packet->buf_control = TRACE_CTRL_PACKET; 356 } else 357 packet->buf_control = TRACE_CTRL_EXTERNAL; 358 359 360 packet->type = rt_type; 361 packet->buffer = buffer; 362 packet->header = buffer; 363 erfptr = (dag_record_t *)packet->buffer; 364 if (erfptr->flags.rxerror == 1) { 365 packet->payload = NULL; 366 /* XXX: Do we want to do this? We never used to do this 367 368 erfptr->rlen = htons(erf_get_framing_length(packet)); 369 */ 370 } else { 371 packet->payload = (char*)packet->buffer + erf_get_framing_length(packet); 372 } 373 374 if (libtrace->format_data == NULL) { 375 /* Allocates the format_data structure */ 376 if (erf_init_input(libtrace)) 377 return -1; 378 } 379 380 /* Check for loss */ 381 if (erfptr->type == TYPE_DSM_COLOR_ETH) { 382 /* No idea how we get this yet */ 383 384 } else { 385 DATA(libtrace)->drops += ntohs(erfptr->lctr); 386 } 387 388 return 0; 389 } 344 390 345 391 static int erf_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { … … 348 394 void *buffer2 = packet->buffer; 349 395 unsigned int rlen; 350 396 uint32_t flags = 0; 397 398 351 399 if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) { 352 400 packet->buffer = malloc((size_t)LIBTRACE_PACKET_BUFSIZE); 353 packet->buf_control = TRACE_CTRL_PACKET;354 401 if (!packet->buffer) { 355 402 trace_set_err(libtrace, errno, … … 359 406 } 360 407 361 362 363 packet->header = packet->buffer; 364 packet->type = TRACE_RT_DATA_ERF; 365 408 flags |= TRACE_PREP_OWN_BUFFER; 409 366 410 if ((numbytes=libtrace_io_read(INPUT.file, 367 411 packet->buffer, … … 403 447 return -1; 404 448 } 405 if (((dag_record_t *)packet->buffer)->flags.rxerror == 1) { 406 packet->payload = NULL; 407 } else { 408 packet->payload = (char*)packet->buffer + erf_get_framing_length(packet); 409 } 449 450 if (erf_prepare_packet(libtrace, packet, packet->buffer, TRACE_RT_DATA_ERF, flags)) 451 return -1; 452 410 453 return rlen; 411 454 } … … 637 680 static uint64_t erf_get_dropped_packets(libtrace_t *trace) 638 681 { 682 if (trace->format_data == NULL) 683 return (uint64_t)-1; 639 684 return DATA(trace)->drops; 640 685 } … … 678 723 erf_fin_output, /* fin_output */ 679 724 erf_read_packet, /* read_packet */ 725 erf_prepare_packet, /* prepare_packet */ 680 726 NULL, /* fin_packet */ 681 727 erf_write_packet, /* write_packet */ trunk/lib/format_legacy.c
r1319 r1332 69 69 }; 70 70 71 static void legacy_init_format_data(libtrace_t *libtrace) { 72 libtrace->format_data = malloc(sizeof(struct legacy_format_data_t)); 73 74 DATA(libtrace)->input.file = NULL; 75 DATA(libtrace)->ts_high = 0; 76 DATA(libtrace)->ts_old = 0; 77 DATA(libtrace)->starttime = 0; 78 } 79 71 80 static int legacyeth_get_framing_length(const libtrace_packet_t *packet UNUSED) 72 81 { … … 91 100 static int erf_init_input(libtrace_t *libtrace) 92 101 { 93 libtrace->format_data = malloc(sizeof(struct legacy_format_data_t)); 94 95 DATA(libtrace)->input.file = NULL; 102 legacy_init_format_data(libtrace); 96 103 97 104 return 0; … … 136 143 regmatch_t match; 137 144 138 libtrace->format_data = malloc(sizeof(struct legacy_format_data_t)); 139 140 DATA(libtrace)->input.file = NULL; 141 145 146 legacy_init_format_data(libtrace); 142 147 if((retval = regcomp(®, "[0-9]{8}-[0-9]{6}", REG_EXTENDED)) != 0) { 143 148 trace_set_err(libtrace, errno, "Failed to compile regex"); … … 149 154 } 150 155 DATA(libtrace)->starttime = trtime(&filename[match.rm_so]); 151 DATA(libtrace)->ts_high = 0;152 DATA(libtrace)->ts_old = 0;153 156 return 0; 154 157 } … … 173 176 } 174 177 178 static int legacy_prepare_packet(libtrace_t *libtrace, 179 libtrace_packet_t *packet, void *buffer, 180 libtrace_rt_types_t rt_type, uint32_t flags) { 181 182 if (packet->buffer != buffer && 183 packet->buf_control == TRACE_CTRL_PACKET) { 184 free(packet->buffer); 185 } 186 187 if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) { 188 packet->buf_control = TRACE_CTRL_PACKET; 189 } else 190 packet->buf_control = TRACE_CTRL_EXTERNAL; 191 192 193 packet->buffer = buffer; 194 packet->header = buffer; 195 packet->type = rt_type; 196 packet->payload = (void*)((char*)packet->buffer + 197 libtrace->format->get_framing_length(packet)); 198 199 200 if (libtrace->format_data == NULL) { 201 legacy_init_format_data(libtrace); 202 } 203 return 0; 204 } 205 175 206 static int legacy_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { 176 207 int numbytes; 177 208 void *buffer; 178 209 uint32_t flags = 0; 210 179 211 if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) { 180 packet->buf_control = TRACE_CTRL_PACKET;181 212 packet->buffer=malloc((size_t)LIBTRACE_PACKET_BUFSIZE); 182 213 } 214 flags |= TRACE_PREP_OWN_BUFFER; 183 215 buffer = packet->buffer; 184 216 … … 215 247 } 216 248 217 packet->header = packet->buffer; 218 packet->payload = (void*)((char*)packet->buffer + 219 libtrace->format->get_framing_length(packet)); 249 if (legacy_prepare_packet(libtrace, packet, packet->buffer, 250 packet->type, flags)) { 251 return -1; 252 } 220 253 221 254 return 64; … … 231 264 void *buffer; 232 265 char *data_ptr; 266 uint32_t flags = 0; 233 267 234 268 if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) { 235 packet->buf_control = TRACE_CTRL_PACKET;236 269 packet->buffer=malloc((size_t)LIBTRACE_PACKET_BUFSIZE); 237 270 } 271 flags |= TRACE_PREP_OWN_BUFFER; 272 238 273 buffer = packet->buffer; 239 240 274 packet->type = TRACE_RT_DATA_LEGACY_NZIX; 241 275 … … 263 297 memmove(data_ptr + 2, data_ptr, 26); 264 298 265 packet->header = packet->buffer; 266 packet->payload = (void*)((char*)packet->buffer + 267 libtrace->format->get_framing_length(packet)); 299 if (legacy_prepare_packet(libtrace, packet, packet->buffer, 300 packet->type, flags)) { 301 return -1; 302 } 268 303 return 68; 269 304 } … … 432 467 NULL, /* fin_output */ 433 468 legacy_read_packet, /* read_packet */ 469 legacy_prepare_packet, /* prepare_packet */ 434 470 NULL, /* fin_packet */ 435 471 NULL, /* write_packet */ … … 471 507 NULL, /* fin_output */ 472 508 legacy_read_packet, /* read_packet */ 509 legacy_prepare_packet, /* prepare_packet */ 473 510 NULL, /* fin_packet */ 474 511 NULL, /* write_packet */ … … 510 547 NULL, /* fin_output */ 511 548 legacy_read_packet, /* read_packet */ 549 legacy_prepare_packet, /* prepare_packet */ 512 550 NULL, /* fin_packet */ 513 551 NULL, /* write_packet */ … … 549 587 NULL, /* fin_output */ 550 588 legacynzix_read_packet, /* read_packet */ 589 legacy_prepare_packet, /* prepare_packet */ 551 590 NULL, /* fin_packet */ 552 591 NULL, /* write_packet */ trunk/lib/format_linux.c
r1321 r1332 331 331 } 332 332 333 static int linuxnative_prepare_packet(libtrace_t *libtrace, 334 libtrace_packet_t *packet, void *buffer, 335 libtrace_rt_types_t rt_type, uint32_t flags) { 336 337 if (packet->buffer != buffer && 338 packet->buf_control == TRACE_CTRL_PACKET) { 339 free(packet->buffer); 340 } 341 342 if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) { 343 packet->buf_control = TRACE_CTRL_PACKET; 344 } else 345 packet->buf_control = TRACE_CTRL_EXTERNAL; 346 347 348 packet->buffer = buffer; 349 packet->header = buffer; 350 packet->payload = (char *)buffer + 351 sizeof(struct libtrace_linuxnative_header); 352 packet->type = rt_type; 353 354 if (libtrace->format_data == NULL) { 355 if (linuxnative_init_input(libtrace)) 356 return -1; 357 } 358 return 0; 359 360 } 361 333 362 #define LIBTRACE_MIN(a,b) ((a)<(b) ? (a) : (b)) 334 363 … … 344 373 socklen_t socklen; 345 374 int snaplen; 346 375 uint32_t flags = 0; 376 347 377 if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) { 348 378 packet->buffer = malloc((size_t)LIBTRACE_PACKET_BUFSIZE); 349 packet->buf_control = TRACE_CTRL_PACKET;350 } 351 352 packet->header = packet->buffer;379 } 380 381 flags |= TRACE_PREP_OWN_BUFFER; 382 353 383 packet->type = TRACE_RT_DATA_LINUX_NATIVE; 354 packet->payload = (char*)packet->buffer+sizeof(*hdr);355 384 356 385 hdr=(struct libtrace_linuxnative_header*)packet->buffer; … … 398 427 perror("ioctl(SIOCGSTAMP)"); 399 428 429 if (linuxnative_prepare_packet(libtrace, packet, packet->buffer, 430 packet->type, flags)) 431 return -1; 432 400 433 return hdr->wirelen+sizeof(*hdr); 401 434 } … … 490 523 491 524 static int linuxnative_get_fd(const libtrace_t *trace) { 525 if (trace->format_data == NULL) 526 return -1; 492 527 return FORMAT(trace->format_data)->fd; 493 528 } … … 506 541 /* Number of packets that past filtering */ 507 542 static uint64_t linuxnative_get_captured_packets(libtrace_t *trace) { 543 if (trace->format_data == NULL) 544 return UINT64_MAX; 545 if (FORMAT(trace->format_data)->fd == -1) { 546 /* This is probably a 'dead' trace so obviously we can't query 547 * the socket for capture counts, can we? */ 548 return UINT64_MAX; 549 } 550 508 551 if ((FORMAT(trace->format_data)->stats_valid & 1) 509 552 || FORMAT(trace->format_data)->stats_valid == 0) { … … 524 567 */ 525 568 static uint64_t linuxnative_get_dropped_packets(libtrace_t *trace) { 569 if (trace->format_data == NULL) 570 return UINT64_MAX; 571 if (FORMAT(trace->format_data)->fd == -1) { 572 /* This is probably
