@@ -463,45 +463,29 @@ int main (int argc, char** argv)
463
463
i64 count = 0 ;
464
464
for (int i = 0 ; !lstop ; i ++ )
465
465
{
466
- begin_loop :
467
466
ch_log_debug1 ("\n%i ######\n" , i );
468
467
469
- /* Check all the FD in case we've read everything */
470
- ch_log_debug1 ("Checking for EOF\n" );
471
- bool all_eof = true;
472
- for (int i = 0 ; i < rd_buffs_count ; i ++ ){
473
- all_eof &= pcap_buff_eof (& rd_buffs [i ]);
474
- }
475
- if (all_eof ){
476
- ch_log_info ("All files empty, exiting now\n" );
477
- break ;
478
- }
479
-
468
+ int32_t eof_buffs = 0 ;
480
469
ch_log_debug1 ("Looking for minimum timestamp index on %i buffers\n" ,
481
470
rd_buffs_count );
482
471
/* Find the read buffer with the earliest timestamp */
483
472
int64_t min_idx = 0 ;
484
473
for (int buff_idx = 0 ; buff_idx < rd_buffs_count ; buff_idx ++ ){
485
- if (pcap_buff_eof (& rd_buffs [buff_idx ])){
486
- if (min_idx == buff_idx ){
487
- min_idx = buff_idx + 1 ;
488
- }
489
- continue ;
490
- }
491
-
492
- pkt_info = pcap_buff_next_packet (& rd_buffs [buff_idx ]);
474
+ pkt_info = pcap_buff_get_info (& rd_buffs [buff_idx ]);
493
475
const char * cur_filename = pcap_buff_get_filename (& rd_buffs [buff_idx ]);
494
476
const uint64_t pkt_idx = rd_buffs [buff_idx ].idx ;
495
477
496
478
switch (pkt_info ){
497
479
case PKT_PADDING :
498
480
ch_log_debug1 ("Skipping over packet %i (buffer %i) because len=0\n" , pkt_idx , buff_idx );
481
+ pcap_buff_next_packet (& rd_buffs [buff_idx ]);
499
482
dropped_padding ++ ;
500
483
buff_idx -- ;
501
484
continue ;
502
485
case PKT_RUNT :
503
486
if (options .skip_runts ){
504
487
ch_log_debug1 ("Skipping over runt frame %i (buffer %i) \n" , pkt_idx , buff_idx );
488
+ pcap_buff_next_packet (& rd_buffs [buff_idx ]);
505
489
dropped_runts ++ ;
506
490
buff_idx -- ;
507
491
continue ;
@@ -510,17 +494,23 @@ int main (int argc, char** argv)
510
494
case PKT_ERROR :
511
495
ch_log_debug1 ("Skipping over damaged packet %i (buffer %i) because flags = 0x%02x\n" ,
512
496
pkt_idx , buff_idx , rd_buffs [buff_idx ].ftr -> flags );
497
+ pcap_buff_next_packet (& rd_buffs [buff_idx ]);
513
498
dropped_errors ++ ;
514
499
buff_idx -- ;
515
500
continue ;
516
501
case PKT_EOF :
517
502
ch_log_debug1 ("End of file \"%s\"\n" , cur_filename );
518
- goto begin_loop ;
519
- break ;
503
+ eof_buffs ++ ;
504
+
505
+ /* All buffers are EOF, exit main loop. */
506
+ if (eof_buffs == rd_buffs_count ){
507
+ goto extract_done ;
508
+ }
509
+ continue ;
520
510
case PKT_OVER_SNAPLEN :
521
511
ch_log_fatal ("Packet with index %d (%s) does not comply with snaplen: %d (data len is %d)\n" ,
522
512
pkt_idx , cur_filename , rd_buffs [buff_idx ].snaplen , rd_buffs [buff_idx ].hdr -> len );
523
- case PKT_SNAPPED :
513
+ case PKT_SNAPPED : // Fall through
524
514
if (options .verbose ){
525
515
ch_log_warn ("Packet has been snapped shorter (%d) than it's wire length (%d) [%s].\n" ,
526
516
rd_buffs [buff_idx ].hdr -> caplen , rd_buffs [buff_idx ].hdr -> len , cur_filename );
@@ -602,10 +592,12 @@ int main (int argc, char** argv)
602
592
603
593
packets_total ++ ;
604
594
count ++ ;
595
+ pcap_buff_next_packet (& rd_buffs [min_idx ]);
605
596
if (options .max_count && count >= options .max_count ){
606
597
break ;
607
598
}
608
599
}
600
+ extract_done :
609
601
610
602
ch_log_info ("Finished writing %li packets total (Runts=%li, Errors=%li, Padding=%li). Closing\n" , packets_total , dropped_runts , dropped_errors , dropped_padding );
611
603
0 commit comments