No warranty, of course, use at will.
diff -ru pcaputils-0.8/doc/pcapdump.docbook pcaputils-AFNIC/doc/pcapdump.docbook
--- pcaputils-0.8/doc/pcapdump.docbook	2009-05-10 01:10:01.000000000 +0200
+++ pcaputils-AFNIC/doc/pcapdump.docbook	2009-09-17 14:48:58.000000000 +0200
@@ -101,6 +101,14 @@
       </varlistentry>
 
       <varlistentry>
+        <term><option>-k </option><replaceable>command</replaceable></term>
+        <listitem>
+	    <para>When closing the pcap capture file, runs the <replaceable>command<replaceable>, with
+	    the file name as an argument.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
         <term><option>-C </option><replaceable>config file</replaceable></term>
         <listitem>
           <para>File to read configuration variables from. Instead of passing configuration through the command line, a file can be used to specify values for the <option>bpf</option>, <option>device</option>, <option>filefmt</option>, <option>group</option>, <option>interval</option>, <option>mode</option>, <option>owner</option>, <option>promisc</option>, and <option>snaplen</option> options (not all need to be specified; defaults will be used otherwise). See /usr/share/doc/pcaputils/examples/pcapdump/eth0 for an example.</para>
diff -ru pcaputils-0.8/src/pcapdump.c pcaputils-AFNIC/src/pcapdump.c
--- pcaputils-0.8/src/pcapdump.c	2009-05-10 01:10:01.000000000 +0200
+++ pcaputils-AFNIC/src/pcapdump.c	2009-09-17 14:40:47.000000000 +0200
@@ -61,6 +61,7 @@
 	{ 'g', "group",         CONFIG_STR, {}, "root",  "output file owning group" },
 	{ 'm', "mode",          CONFIG_OCT, {}, "0600",  "output file mode" },
 	{ 't', "interval",      CONFIG_DEC, {}, "86400", "output file rotation interval" },
+	{ 'k', "kick",       CONFIG_STR, {}, NULL,    "program to kick in after file rotation" },
 	{ 'T', "duration",	CONFIG_DEC, {}, NULL,    "capture duration in seconds" },
 	{ 'c', "count",         CONFIG_DEC, {}, NULL,    "packet count limit" },
 	{ 'H', "headersonly",   CONFIG_BOOL,{}, "0",     "dump headers only" },
@@ -174,6 +175,7 @@
 	pa.dev = cfgopt_get_str_dup(cfg, "device");
 	pa.bpf_string = cfgopt_get_str_dup(cfg, "bpf");
 	pcapdump_filefmt = cfgopt_get_str_dup(cfg, "filefmt");
+	pa.kickin = cfgopt_get_str_dup(cfg, "kick");
 
 	pa.promisc = cfgopt_get_bool(cfg, "promisc");
 	pa.snaplen = cfgopt_get_num(cfg, "snaplen");
@@ -294,8 +296,9 @@
 }
 
 static void reset_dump(void){
-	if(pa.dumper)
-		pcapnet_close_dump(&pa);
+    if(pa.dumper) {
+	  pcapnet_close_dump(&pa);
+	}
 	char *fname;
 	CALLOC(fname, FNAME_MAXLEN);
 
@@ -315,6 +318,7 @@
 		cfgopt_get_str(cfg, "owner"),
 		cfgopt_get_str(cfg, "group")
 	);
+	pa.fname_out = fname;
 	pcapnet_init_dumpfd(&pa, fd);
 	DEBUG("opened %s", fname);
 }
diff -ru pcaputils-0.8/util/pcapnet.c pcaputils-AFNIC/util/pcapnet.c
--- pcaputils-0.8/util/pcapnet.c	2009-05-10 01:10:01.000000000 +0200
+++ pcaputils-AFNIC/util/pcapnet.c	2009-09-17 14:41:52.000000000 +0200
@@ -39,6 +39,8 @@
 #include "pcapnet.h"
 #include "util.h"
 
+#define KICKIN_MAXLEN 1024
+
 /* functions */
 
 void pcapnet_load_cfg(pcap_args_t *pa, cfgopt_t *cfg){
@@ -409,12 +411,28 @@
 }
 
 void pcapnet_close_dump(pcap_args_t *pa){
+    char *cmd = malloc(KICKIN_MAXLEN);
+	char *dump_name;
 	if(pa->dumper){
-		if(pa->fname_out)
+	  if(pa->fname_out) {
 			DEBUG("closing pcap file %s", pa->fname_out);
-		pcap_dump_flush(pa->dumper);
-		pcap_dump_close(pa->dumper);
-		pa->dumper = NULL;
+			dump_name = strdup(pa->fname_out);
+	  }
+	  else {
+		ERROR("Unknown capture file for the kick-in option");
+	  }
+	  pcap_dump_flush(pa->dumper);
+	  pcap_dump_close(pa->dumper);
+	  pa->dumper = NULL;
+	  if (pa->kickin != NULL) {
+		if (snprintf(cmd, KICKIN_MAXLEN, "%s %s &", pa->kickin, dump_name) <= 0){
+		  ERROR("cannot create the command to kick in");
+		}
+		DEBUG("running \"%s\"", cmd);
+		system(cmd);
+		free(cmd);
+		free(dump_name);
+	  }
 	}
 }
 
diff -ru pcaputils-0.8/util/pcapnet.h pcaputils-AFNIC/util/pcapnet.h
--- pcaputils-0.8/util/pcapnet.h	2009-05-10 01:10:01.000000000 +0200
+++ pcaputils-AFNIC/util/pcapnet.h	2009-09-17 14:48:37.000000000 +0200
@@ -71,6 +71,7 @@
 	int snaplen;
 	int to_ms;
 	pcap_dumper_t *dumper;
+	char *kickin;
 	pcap_t *handle;
 	pcap_t *handle_out;
 } pcap_args_t;

Reply via email to