summaryrefslogtreecommitdiff
path: root/capture_opts.c
diff options
context:
space:
mode:
authorUlf Lamping <ulf.lamping@web.de>2006-01-07 01:29:45 +0000
committerUlf Lamping <ulf.lamping@web.de>2006-01-07 01:29:45 +0000
commit15f905102907db3230fd7a5d46d7e336bc800235 (patch)
tree40a784efe21469082f0fa6e98feadfd3f8b432d2 /capture_opts.c
parent76bbd4181b6fbf9184b0c695d5cd8f0d708fa037 (diff)
downloadwireshark-15f905102907db3230fd7a5d46d7e336bc800235.tar.gz
move output_to_pipe flag from tethereal's loop_data into capture_opts, so it can be used by dumpcap (capture_loop.c) as well
svn path=/trunk/; revision=16972
Diffstat (limited to 'capture_opts.c')
-rw-r--r--capture_opts.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/capture_opts.c b/capture_opts.c
index 8e27f4ef85..4b6595fad9 100644
--- a/capture_opts.c
+++ b/capture_opts.c
@@ -45,8 +45,11 @@
#include "capture-pcap-util.h"
#include "capture_ui_utils.h"
+#include <wiretap/file_util.h>
+static gboolean capture_opts_output_to_pipe(const char *save_file);
+
void
capture_opts_init(capture_options *capture_opts, void *cfile)
@@ -89,6 +92,7 @@ capture_opts_init(capture_options *capture_opts, void *cfile)
capture_opts->signal_pipe_fd = -1;
#endif
capture_opts->state = CAPTURE_STOPPED;
+ capture_opts->output_to_pipe = FALSE;
}
@@ -409,6 +413,7 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg,
break;
case 'w': /* Write to capture file xxx */
capture_opts->save_file = g_strdup(optarg);
+ capture_opts->output_to_pipe = capture_opts_output_to_pipe(capture_opts->save_file);
break;
case 'y': /* Set the pcap data link type */
#ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL
@@ -575,4 +580,64 @@ gboolean capture_opts_trim_iface(capture_options *capture_opts, const char *capt
}
+
+#ifndef S_IFIFO
+#define S_IFIFO _S_IFIFO
+#endif
+#ifndef S_ISFIFO
+#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
+#endif
+
+/* copied from filesystem.c */
+static int capture_opts_test_for_fifo(const char *path)
+{
+ struct stat statb;
+
+ if (eth_stat(path, &statb) < 0)
+ return errno;
+
+ if (S_ISFIFO(statb.st_mode))
+ return ESPIPE;
+ else
+ return 0;
+}
+
+static gboolean capture_opts_output_to_pipe(const char *save_file)
+{
+ int err;
+
+ if (save_file != NULL) {
+ /* We're writing to a capture file. */
+ if (strcmp(save_file, "-") == 0) {
+ /* Writing to stdout. */
+ /* XXX - should we check whether it's a pipe? It's arguably
+ silly to do "-w - >output_file" rather than "-w output_file",
+ but by not checking we might be violating the Principle Of
+ Least Astonishment. */
+ return TRUE;
+ } else {
+ /* not a capture file, test for a FIFO (aka named pipe) */
+ err = capture_opts_test_for_fifo(save_file);
+ switch (err) {
+
+ case ENOENT: /* it doesn't exist, so we'll be creating it,
+ and it won't be a FIFO */
+ case 0: /* found it, but it's not a FIFO */
+ break;
+
+ case ESPIPE: /* it is a FIFO */
+ return TRUE;
+ break;
+
+ default: /* couldn't stat it */
+ cmdarg_err("Error testing whether capture file is a pipe: %s",
+ strerror(errno));
+ exit(2);
+ }
+ }
+ }
+
+ return FALSE;
+}
+
#endif /* HAVE_LIBPCAP */