]> mj.ucw.cz Git - netgrind.git/commitdiff
Support grinding of multiple dump files at once.
authorMartin Mares <mj@ucw.cz>
Thu, 19 Jun 2003 09:51:55 +0000 (09:51 +0000)
committerMartin Mares <mj@ucw.cz>
Thu, 19 Jun 2003 09:51:55 +0000 (09:51 +0000)
netgrind/netgrind.c

index 233d293f49772060dbcecab99f09ede73e47af0a..49850a70b0aea4f6d30ce07b60f0b62652035bd9 100644 (file)
@@ -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 [<switches>] <capture-file>\n\
+  fprintf(stderr, "Usage: netgrind [<switches>] <capture-files>\n\
 \n\
 -a             TCP: Record arrival times instead of processing times\n\
 -c <count>     Stop after processing <count> 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;
 }