Skip to content

Commit 5025a36

Browse files
authored
Merge pull request #40 from space-jam-/fix-pcap-extract-unhandled-cases
Fix pcap extract unhandled cases
2 parents 4a73d45 + b5fb24b commit 5025a36

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

tools/exact-pcap-extract.c

+15-2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ static struct
7171
ch_bool allow_duplicates;
7272
ch_bool hpt_trailer;
7373
char* steer_type;
74+
ch_bool verbose;
7475
} options;
7576

7677
enum out_format_type {
@@ -351,6 +352,7 @@ int main (int argc, char** argv)
351352
ch_opt_addbi (CH_OPTION_FLAG, 'D', "allow-duplicates", "Allow duplicate filenames to be used", &options.allow_duplicates, false);
352353
ch_opt_addbi (CH_OPTION_FLAG, 't', "hpt-trailer", "Extract timestamps from Fusion HPT trailers", &options.hpt_trailer, false);
353354
ch_opt_addsi (CH_OPTION_OPTIONAL, 's', "steer", "Steer packets to different files depending on packet contents. Valid values are [hpt, vlan, expcap]", &options.steer_type, NULL);
355+
ch_opt_addbi (CH_OPTION_FLAG, 'v', "verbose", "Printout verbose output.", &options.verbose, false);
354356

355357
ch_opt_parse (argc, argv);
356358

@@ -488,6 +490,9 @@ int main (int argc, char** argv)
488490
}
489491

490492
pkt_info = pcap_buff_next_packet(&rd_buffs[buff_idx]);
493+
const char* cur_filename = pcap_buff_get_filename(&rd_buffs[buff_idx]);
494+
const uint64_t pkt_idx = rd_buffs[buff_idx].idx;
495+
491496
switch(pkt_info){
492497
case PKT_PADDING:
493498
ch_log_debug1("Skipping over packet %i (buffer %i) because len=0\n", pkt_idx, buff_idx);
@@ -504,14 +509,22 @@ int main (int argc, char** argv)
504509
break;
505510
case PKT_ERROR:
506511
ch_log_debug1("Skipping over damaged packet %i (buffer %i) because flags = 0x%02x\n",
507-
pkt_idx, buff_idx, pkt_ftr->flags);
512+
pkt_idx, buff_idx, rd_buffs[buff_idx].ftr->flags);
508513
dropped_errors++;
509514
buff_idx--;
510515
continue;
511516
case PKT_EOF:
512-
ch_log_debug1("End of file \"%s\"\n", pcap_buff_get_filename(&rd_buffs[buff_idx]));
517+
ch_log_debug1("End of file \"%s\"\n", cur_filename);
513518
goto begin_loop;
514519
break;
520+
case PKT_OVER_SNAPLEN:
521+
ch_log_fatal("Packet with index %d (%s) does not comply with snaplen: %d (data len is %d)\n",
522+
pkt_idx, cur_filename, rd_buffs[buff_idx].snaplen, rd_buffs[buff_idx].hdr->len);
523+
case PKT_SNAPPED:
524+
if(options.verbose){
525+
ch_log_warn("Packet has been snapped shorter (%d) than it's wire length (%d) [%s].\n",
526+
rd_buffs[buff_idx].hdr->caplen, rd_buffs[buff_idx].hdr->len, cur_filename);
527+
}
515528
case PKT_OK:
516529
break;
517530
}

0 commit comments

Comments
 (0)