From: Martin Mares Date: Thu, 19 Jun 2003 09:51:55 +0000 (+0000) Subject: Support grinding of multiple dump files at once. X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=ad2035457cf6e795299ab89d953bb641b201cf2a;p=netgrind.git Support grinding of multiple dump files at once. --- diff --git a/netgrind/netgrind.c b/netgrind/netgrind.c index 233d293..49850a7 100644 --- a/netgrind/netgrind.c +++ b/netgrind/netgrind.c @@ -104,7 +104,7 @@ static void got_pcap_packet(u_char *userdata UNUSED, const struct pcap_pkthdr *h static void usage(void) { - fprintf(stderr, "Usage: netgrind [] \n\ + fprintf(stderr, "Usage: netgrind [] \n\ \n\ -a TCP: Record arrival times instead of processing times\n\ -c Stop after processing packets\n\ @@ -160,24 +160,31 @@ int main(int argc, char **argv) default: usage(); } - if (optind != argc - 1) + if (optind == argc) usage(); tcp_init(); - if (!(pcap = pcap_open_offline(argv[optind], errbuf))) - die("Unable to open %s", errbuf); - dlt = pcap_datalink(pcap); - if (!link_setup_handler(dlt)) - die("Don't know how to handle data link type %d", dlt); - if (filter) + while (optind < argc) { - if (pcap_compile(pcap, &filter_prog, filter, 1, 0) < 0) - die("Error compiling filter: %s", pcap_geterr(pcap)); - pcap_setfilter(pcap, &filter_prog); + fprintf(stderr, "Processing %s...\n", argv[optind]); + if (!(pcap = pcap_open_offline(argv[optind], errbuf))) + die("Unable to open %s", errbuf); + dlt = pcap_datalink(pcap); + if (!link_setup_handler(dlt)) + die("Don't know how to handle data link type %d", dlt); + if (filter) + { + if (pcap_compile(pcap, &filter_prog, filter, 1, 0) < 0) + die("Error compiling filter: %s", pcap_geterr(pcap)); + pcap_setfilter(pcap, &filter_prog); + pcap_freecode(&filter_prog); + } + if (pcap_loop(pcap, max_packets, got_pcap_packet, NULL) < 0) + die("Capture failed: %s", pcap_geterr(pcap)); + pcap_close(pcap); + optind++; } - if (pcap_loop(pcap, max_packets, got_pcap_packet, NULL) < 0) - die("Capture failed: %s", pcap_geterr(pcap)); tcp_cleanup(last_timestamp); printf("# Netgrind statistics:\n"); printf("# Pcap: %Ld(%Ld) in, %Ld(%Ld) incomplete\n", @@ -204,6 +211,5 @@ int main(int argc, char **argv) printf("# Flows: %d total: %d closed, %d reset, %d timed out, %d overlap end, %d corrupted\n", cnt_tcp_flows, cnt_tcp_causes[CAUSE_CLOSE], cnt_tcp_causes[CAUSE_RESET], cnt_tcp_causes[CAUSE_TIMEOUT], cnt_tcp_causes[CAUSE_DOOMSDAY], cnt_tcp_causes[CAUSE_CORRUPT]); - pcap_close(pcap); return 0; }