--- flowd-reader.c	2008-04-23 11:54:26.000000000 +1000
+++ flowd-reader.stats.c	2011-12-07 12:55:38.000000000 +1000
@@ -50,6 +50,7 @@
 	fprintf(stderr, "  -o path  Write binary log to path (use with -f)\n");
 	fprintf(stderr, "  -v       Display all available flow information\n");
 	fprintf(stderr, "  -c       Return CSV output compatible with flow-import\n");
+        fprintf(stderr, "  -s       Display a summary. Includes totals for flows, packets and bytes\n");
 	fprintf(stderr, "  -U       Report times in UTC rather than local time\n");
 	fprintf(stderr, "  -h       Display this help\n");
 }
@@ -87,6 +88,10 @@
 	u_int32_t disp_mask;
 	struct flowd_config filter_config;
 	struct store_v2_header hdr_v2;
+        
+        int showstats = 0;
+        uint64_t totalBytes4 = 0, totalFlows4 = 0, totalPackets4 = 0;
+        uint64_t totalBytes6 = 0, totalFlows6 = 0, totalPackets6 = 0;
 
 	utc = verbose = debug = read_legacy = csv = 0;
 	ofile = ffile = NULL;
@@ -96,7 +101,7 @@
 
 	bzero(&filter_config, sizeof(filter_config));
 
-	while ((ch = getopt(argc, argv, "H:LUdf:ho:qvc")) != -1) {
+	while ((ch = getopt(argc, argv, "H:LUdf:ho:qvcs")) != -1) {
 		switch (ch) {
 		case 'h':
 			usage();
@@ -130,7 +135,10 @@
 		case 'v':
 			verbose = 1;
 			break;
-		case 'c':
+                case 's':
+                        showstats = 1;
+                        break;
+                case 'c':
 			csv = 1;
 			break;
 		default:
@@ -222,11 +230,31 @@
 			if (ffile != NULL && filter_flow(&flow,
 			    &filter_config.filter_list) == FF_ACTION_DISCARD)
 				continue;
+                        
 			if (csv) {
 				store_format_flow_flowtools_csv(&flow, buf,
 				    sizeof(buf), utc, disp_mask, 0);
 				printf("%s\n", buf);
 			}
+                        else if(showstats == 1)
+                        {
+                            switch (flow.src_addr.af)
+                            {
+                                case AF_INET:
+                                    
+                                        totalBytes4+= store_ntohll(flow.octets.flow_octets);
+                                        totalPackets4+= store_ntohll(flow.packets.flow_packets);
+                                        totalFlows4++;
+                                    
+                                    break;
+                                case AF_INET6:
+                                        totalBytes6+= store_ntohll(flow.octets.flow_octets);
+                                        totalPackets6+= store_ntohll(flow.packets.flow_packets);
+                                        totalFlows6++;
+                                    break;
+                            }
+
+                        }
 			else if (verbose >= 0) {
 				store_format_flow(&flow, buf, sizeof(buf), 
 				    utc, disp_mask, 0);
@@ -246,6 +274,21 @@
 
 	if (ffile != NULL && debug)
 		dump_config(&filter_config, "final", 1);
+        
+        if(showstats == 1)
+        {
+            printf("\nFlow Statistics\n\n");
+            
+            printf("IPv4\n");
+            printf("Total Flows   : %llu\n", totalFlows4);
+            printf("Total Bytes   : %llu\n", totalBytes4);
+            printf("Total Packets : %llu\n\n", totalPackets4);
+            
+            printf("IPv6\n");
+            printf("Total Flows   : %llu\n", totalFlows6);
+            printf("Total Bytes   : %llu\n", totalBytes6);
+            printf("Total Packets : %llu\n\n", totalPackets6);
+        }
 
 	return (0);
 }
