aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Lamping <ulf.lamping@web.de>2006-02-17 02:18:48 +0000
committerUlf Lamping <ulf.lamping@web.de>2006-02-17 02:18:48 +0000
commit79053183c54a7e0efc29b656a47deff19f0dee2c (patch)
tree8dd5dd504a3c13ed7cd5cd018bca2736e2bb1467
parent58d9f6c3b1e8ed8cc914e6f3d5af87c3e12a2ff3 (diff)
remove dependencies to pcap.h, so getting an idea what needs to be done by dumpcap in addition to the things already done now
various dumpcap related code cleanup: mainly #include's and capture engine related stuff svn path=/trunk/; revision=17327
-rw-r--r--capture-pcap-util.c16
-rw-r--r--capture-pcap-util.h42
-rw-r--r--capture-wpcap.c4
-rw-r--r--capture.c2
-rw-r--r--capture_loop.c57
-rw-r--r--capture_opts.c19
-rw-r--r--capture_sync.c11
-rw-r--r--capture_sync.h6
-rw-r--r--capture_ui_utils.c3
-rw-r--r--dumpcap.c156
-rw-r--r--gtk/capture_dlg.c5
-rw-r--r--gtk/capture_if_details_dlg.c1
-rw-r--r--gtk/capture_if_dlg.c6
-rw-r--r--gtk/capture_info_dlg.c2
-rw-r--r--gtk/capture_prefs.c5
-rw-r--r--gtk/cfilter_combo_utils.c1
-rw-r--r--gtk/drag_and_drop.c4
-rw-r--r--gtk/main.c1
-rw-r--r--gtk/summary_dlg.c1
-rw-r--r--summary.h1
-rw-r--r--tempfile.c6
-rw-r--r--tethereal.c17
-rw-r--r--version_info.c9
23 files changed, 220 insertions, 155 deletions
diff --git a/capture-pcap-util.c b/capture-pcap-util.c
index db32cfb4c7..c52e8cf95d 100644
--- a/capture-pcap-util.c
+++ b/capture-pcap-util.c
@@ -430,4 +430,20 @@ set_pcap_linktype(pcap_t *pch, char *devname
#endif
}
+
+#ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
+const char *
+linktype_val_to_name(int dlt)
+{
+ return pcap_datalink_val_to_name(dlt);
+}
+#endif
+
+#ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL
+int linktype_name_to_val(const char *linktype)
+{
+ return pcap_datalink_name_to_val(linktype);
+}
+#endif
+
#endif /* HAVE_LIBPCAP */
diff --git a/capture-pcap-util.h b/capture-pcap-util.h
index 1b78718341..0b07e2b274 100644
--- a/capture-pcap-util.h
+++ b/capture-pcap-util.h
@@ -33,6 +33,12 @@ extern "C" {
#include <epan/address.h>
+#include <pcap.h>
+
+/* declaration of pcap_t here, to reduce pcap dependencies */
+/*typedef struct pcap pcap_t;*/
+
+
/*
* XXX - this is also the traditional default snapshot size in
* tcpdump - but, if IPv6 is enabled, it defaults to 96, to get an
@@ -43,27 +49,28 @@ extern "C" {
*/
#define MIN_PACKET_SIZE 68 /* minimum amount of packet data we can read */
-#define MAX_WIN_IF_NAME_LEN 511
+/* XXX - this must be optimized, removing the dependency!!! */
+#define CAPTURE_PCAP_ERRBUF_SIZE PCAP_ERRBUF_SIZE
/*
* The list of interfaces returned by "get_interface_list()" is
* a list of these structures.
*/
typedef struct {
- char *name;
- char *description;
- GSList *ip_addr; /* containing address values */
- gboolean loopback;
+ char *name; /* e.g. "eth0" */
+ char *description; /* from OS, e.g. "Local Area Connection" or NULL */
+ GSList *ip_addr; /* containing address values of if_addr_t */
+ gboolean loopback; /* TRUE if loopback, FALSE otherwise */
} if_info_t;
/*
* An address in the "ip_addr" list.
*/
typedef struct {
- address_type type;
+ address_type type; /* AF_INET or AF_INET6 */
union {
- guint32 ip4_addr;
- guint8 ip6_addr[16];
+ guint32 ip4_addr; /* 4 byte IP V4 address, or */
+ guint8 ip6_addr[16];/* 16 byte IP V6 address */
} ip_addr;
} if_addr_t;
@@ -86,16 +93,27 @@ gchar *cant_get_if_list_error_message(const char *err_str);
* a list of these structures.
*/
typedef struct {
- int dlt;
- char *name;
- char *description;
+ int dlt; /* e.g. DLT_EN10MB (which is 1) */
+ char *name; /* e.g. "EN10MB" or "DLT 1" */
+ char *description; /* descriptive name from wiretap e.g. "Ethernet", NULL if unknown */
} data_link_info_t;
-int get_pcap_linktype(pcap_t *pch, const char *devname);
GList *get_pcap_linktype_list(const char *devname, char *err_buf);
void free_pcap_linktype_list(GList *linktype_list);
+
+/* get/set the link type of an interface */
+/* (only used in capture_loop.c / capture-pcap-util.c) */
+int get_pcap_linktype(pcap_t *pch, const char *devname);
const char *set_pcap_linktype(pcap_t *pch, char *devname, int dlt);
+
+#ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
+const char *linktype_val_to_name(int dlt);
+#endif
+#ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL
+int linktype_name_to_val(const char *linktype);
+#endif
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/capture-wpcap.c b/capture-wpcap.c
index fe0ff5d60e..b61b6c0e23 100644
--- a/capture-wpcap.c
+++ b/capture-wpcap.c
@@ -41,6 +41,10 @@
/* XXX - yes, I know, I should move cppmagic.h to a generic location. */
#include "tools/lemon/cppmagic.h"
+
+#define MAX_WIN_IF_NAME_LEN 511
+
+
gboolean has_wpcap = FALSE;
#ifdef HAVE_LIBPCAP
diff --git a/capture.c b/capture.c
index 96cc745e74..d069db898b 100644
--- a/capture.c
+++ b/capture.c
@@ -43,8 +43,6 @@
#include <signal.h>
#include <errno.h>
-#include <pcap.h>
-
#include <glib.h>
#include <epan/packet.h>
diff --git a/capture_loop.c b/capture_loop.c
index 751bbf89b7..986f8974d2 100644
--- a/capture_loop.c
+++ b/capture_loop.c
@@ -1086,6 +1086,7 @@ capture_loop_open_output(capture_options *capture_opts, int *save_file_fd,
static void
capture_loop_stop_signal_handler(int signo _U_)
{
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "Signal: Stop capture");
capture_loop_stop();
}
#endif
@@ -1096,35 +1097,6 @@ capture_loop_stop_signal_handler(int signo _U_)
#define TIME_GET() time(NULL)
#endif
-#ifdef _WIN32
-static gboolean
-signal_pipe_stopped(void)
-{
- /* any news from our parent (stdin)? -> just stop the capture */
- HANDLE handle;
- DWORD avail = 0;
- gboolean result;
-
-
- handle = (HANDLE) GetStdHandle(STD_INPUT_HANDLE);
- result = PeekNamedPipe(handle, NULL, 0, NULL, &avail, NULL);
-
- if(!result || avail > 0) {
- /* peek failed or some bytes really available */
-
- /* XXX - if not piping from stdin this fails */
- /*g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG,
- "Signal pipe: handle: %x result: %u avail: %u", handle, result, avail);
- return FALSE;*/
- return TRUE;
- } else {
- /* pipe ok and no bytes available */
- return FALSE;
- }
-}
-#endif
-
-
/* Do the low-level work of a capture.
Returns TRUE if it succeeds, FALSE otherwise. */
int
@@ -1178,7 +1150,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
signal(SIGUSR1, capture_loop_stop_signal_handler);
#endif
- g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "Capture child starting ...");
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "Capture loop starting ...");
capture_opts_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, capture_opts);
/* open the output file (temporary/specified name/ringbuffer) */
@@ -1241,7 +1213,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
start_time = TIME_GET();
upd_time = TIME_GET();
- g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "Capture child running!");
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "Capture loop running!");
/* WOW, everything is prepared! */
/* please fasten your seat belts, we will enter now the actual capture loop */
@@ -1250,10 +1222,8 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
inpkts = capture_loop_dispatch(capture_opts, &ld, errmsg, sizeof(errmsg));
#ifdef _WIN32
- /*fprintf(stderr, "signal pipe ret: %u\n", signal_pipe_stopped());*/
-
/* any news from our parent (signal pipe)? -> just stop the capture */
- if (signal_pipe_stopped()) {
+ if (!signal_pipe_check_running()) {
ld.go = FALSE;
}
#endif
@@ -1280,8 +1250,9 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
cnd_reset(cnd_file_duration);
}
wtap_dump_flush(ld.wtap_pdh);
- sync_pipe_filename_to_parent(capture_opts->save_file);
+ sync_pipe_packet_count_to_parent(inpkts_to_sync_pipe);
inpkts_to_sync_pipe = 0;
+ sync_pipe_filename_to_parent(capture_opts->save_file);
} else {
/* File switch failed: stop here */
ld.go = FALSE;
@@ -1347,8 +1318,9 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
if(cnd_autostop_size)
cnd_reset(cnd_autostop_size);
wtap_dump_flush(ld.wtap_pdh);
- sync_pipe_filename_to_parent(capture_opts->save_file);
+ sync_pipe_packet_count_to_parent(inpkts_to_sync_pipe);
inpkts_to_sync_pipe = 0;
+ sync_pipe_filename_to_parent(capture_opts->save_file);
} else {
/* File switch failed: stop here */
ld.go = FALSE;
@@ -1364,7 +1336,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
} /* while (ld.go) */
- g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "Capture child stopping ...");
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "Capture loop stopping ...");
/* delete stop conditions */
if (cnd_file_duration != NULL)
@@ -1400,6 +1372,13 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
/* close the wiretap (output) file */
close_ok = capture_loop_close_output(capture_opts, &ld, &err_close);
+ /* there might be packets not yet notified to the parent */
+ /* (do this after closing the file, so all packets are already flushed) */
+ if(inpkts_to_sync_pipe) {
+ sync_pipe_packet_count_to_parent(inpkts_to_sync_pipe);
+ inpkts_to_sync_pipe = 0;
+ }
+
/* If we've displayed a message about a write error, there's no point
in displaying another message about an error on close. */
if (!close_ok && write_ok) {
@@ -1437,7 +1416,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
/* close the input file (pcap or capture pipe) */
capture_loop_close_input(&ld);
- g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "Capture child stopped!");
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "Capture loop stopped!");
/* ok, if the write and the close were successful. */
return write_ok && close_ok;
@@ -1462,7 +1441,7 @@ error:
/* close the input file (pcap or cap_pipe) */
capture_loop_close_input(&ld);
- g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "Capture child stopped with error");
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "Capture loop stopped with error");
return FALSE;
}
diff --git a/capture_opts.c b/capture_opts.c
index a893ff6f9b..d8c2f85954 100644
--- a/capture_opts.c
+++ b/capture_opts.c
@@ -31,8 +31,6 @@
#include <string.h>
#include <ctype.h>
-#include <pcap.h>
-
#include <glib.h>
#include <epan/packet.h>
@@ -44,7 +42,6 @@
#include "cmdarg_err.h"
#include "capture-pcap-util.h"
-#include "capture_ui_utils.h"
#include <wiretap/file_util.h>
@@ -239,7 +236,7 @@ capture_opts_add_iface_opt(capture_options *capture_opts, const char *optarg)
GList *if_list;
if_info_t *if_info;
int err;
- gchar err_str[PCAP_ERRBUF_SIZE];
+ gchar err_str[CAPTURE_PCAP_ERRBUF_SIZE];
gchar *cant_get_if_list_errstr;
@@ -369,7 +366,7 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg,
break;
case 'y': /* Set the pcap data link type */
#ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL
- capture_opts->linktype = pcap_datalink_name_to_val(optarg);
+ capture_opts->linktype = linktype_name_to_val(optarg);
if (capture_opts->linktype == -1) {
cmdarg_err("The specified data link type \"%s\" isn't valid",
optarg);
@@ -391,7 +388,7 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg,
int capture_opts_list_link_layer_types(capture_options *capture_opts)
{
- gchar err_str[PCAP_ERRBUF_SIZE];
+ gchar err_str[CAPTURE_PCAP_ERRBUF_SIZE];
GList *lt_list, *lt_entry;
data_link_info_t *data_link_info;
@@ -399,11 +396,11 @@ int capture_opts_list_link_layer_types(capture_options *capture_opts)
lt_list = get_pcap_linktype_list(capture_opts->iface, err_str);
if (lt_list == NULL) {
if (err_str[0] != '\0') {
- cmdarg_err("The list of data link types for the capture device could not be obtained (%s)."
+ cmdarg_err("The list of data link types for the capture device \"%s\" could not be obtained (%s)."
"Please check to make sure you have sufficient permissions, and that\n"
- "you have the proper interface or pipe specified.\n", err_str);
+ "you have the proper interface or pipe specified.\n", capture_opts->iface, err_str);
} else
- cmdarg_err("The capture device has no data link types.");
+ cmdarg_err("The capture device \"%s\" has no data link types.", capture_opts->iface);
return 2;
}
cmdarg_err_cont("Data link types (use option -y to set):");
@@ -429,7 +426,7 @@ int capture_opts_list_interfaces()
GList *if_entry;
if_info_t *if_info;
int err;
- gchar err_str[PCAP_ERRBUF_SIZE];
+ gchar err_str[CAPTURE_PCAP_ERRBUF_SIZE];
gchar *cant_get_if_list_errstr;
int i;
@@ -491,7 +488,7 @@ gboolean capture_opts_trim_iface(capture_options *capture_opts, const char *capt
GList *if_list;
if_info_t *if_info;
int err;
- gchar err_str[PCAP_ERRBUF_SIZE];
+ gchar err_str[CAPTURE_PCAP_ERRBUF_SIZE];
gchar *cant_get_if_list_errstr;
diff --git a/capture_sync.c b/capture_sync.c
index e013f699ea..6cb53e8ae7 100644
--- a/capture_sync.c
+++ b/capture_sync.c
@@ -28,8 +28,6 @@
#ifdef HAVE_LIBPCAP
-#include <pcap.h>
-
#include <glib.h>
#include <stdio.h>
#include <ctype.h>
@@ -41,10 +39,16 @@
#include <signal.h>
+#ifdef _WIN32
+#include <fcntl.h>
+#endif
+
#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
#endif
+#include "capture-pcap-util.h"
+
#ifndef _WIN32
/*
* Define various POSIX macros (and, in the case of WCOREDUMP, non-POSIX
@@ -353,7 +357,7 @@ sync_pipe_start(capture_options *capture_opts) {
if (capture_opts->linktype != -1) {
argv = sync_pipe_add_arg(argv, &argc, "-y");
#ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
- g_snprintf(ssnap, ARGV_NUMBER_LEN, "%s",pcap_datalink_val_to_name(capture_opts->linktype));
+ g_snprintf(ssnap, ARGV_NUMBER_LEN, "%s",linktype_val_to_name(capture_opts->linktype));
#else
/* XXX - just treat it as a number */
g_snprintf(ssnap, ARGV_NUMBER_LEN, "%d",capture_opts->linktype);
@@ -472,6 +476,7 @@ sync_pipe_start(capture_options *capture_opts) {
si.hStdInput = signal_pipe_read;
si.hStdOutput = sync_pipe_write;
si.hStdError = sync_pipe_write;
+ /*si.hStdError = (HANDLE) _get_osfhandle(2);*/
#endif
g_string_append(args, exename);
diff --git a/capture_sync.h b/capture_sync.h
index 6dbb64151a..2e08588839 100644
--- a/capture_sync.h
+++ b/capture_sync.h
@@ -94,4 +94,10 @@ extern void
sync_pipe_errmsg_to_parent(const char *errmsg);
+/** does the parent signalled the child to stop */
+#ifdef _WIN32
+extern gboolean
+signal_pipe_check_running(void);
+#endif
+
#endif /* capture_sync.h */
diff --git a/capture_ui_utils.c b/capture_ui_utils.c
index 94ac20c6ae..4cf77e51d2 100644
--- a/capture_ui_utils.c
+++ b/capture_ui_utils.c
@@ -28,7 +28,6 @@
#ifdef HAVE_LIBPCAP
-#include <pcap.h>
#include <string.h>
#include <glib.h>
@@ -110,7 +109,7 @@ get_interface_descriptive_name(const char *if_name)
GList *if_entry;
if_info_t *if_info;
int err;
- char err_buf[PCAP_ERRBUF_SIZE];
+ char err_buf[CAPTURE_PCAP_ERRBUF_SIZE];
/* Do we have a user-supplied description? */
descr = capture_dev_user_descr_find(if_name);
diff --git a/dumpcap.c b/dumpcap.c
index a5d016b995..cfcdb4e4ea 100644
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -81,8 +81,6 @@ void exit_main(int err) __attribute__ ((noreturn));
void exit_main(int err);
#endif
-const char *get_basename(const char *path);
-
static void
print_usage(gboolean print_ver) {
@@ -152,44 +150,50 @@ show_version(GString *comp_info_str, GString *runtime_info_str)
/*
* Report an error in command-line arguments.
- * Creates a console on Windows.
- * XXX - pop this up in a window of some sort on UNIX+X11 if the controlling
- * terminal isn't the standard error?
*/
void
cmdarg_err(const char *fmt, ...)
{
va_list ap;
- va_start(ap, fmt);
- fprintf(stderr, "dumpcap: ");
- vfprintf(stderr, fmt, ap);
- fprintf(stderr, "\n");
- va_end(ap);
+ if(capture_child) {
+ /* XXX - convert to g_log */
+ } else {
+ va_start(ap, fmt);
+ fprintf(stderr, "dumpcap: ");
+ vfprintf(stderr, fmt, ap);
+ fprintf(stderr, "\n");
+ va_end(ap);
+ }
}
/*
* Report additional information for an error in command-line arguments.
- * Creates a console on Windows.
- * XXX - pop this up in a window of some sort on UNIX+X11 if the controlling
- * terminal isn't the standard error?
*/
void
cmdarg_err_cont(const char *fmt, ...)
{
va_list ap;
- va_start(ap, fmt);
- vfprintf(stderr, fmt, ap);
- fprintf(stderr, "\n");
- va_end(ap);
+ if(capture_child) {
+ /* XXX - convert to g_log */
+ } else {
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ fprintf(stderr, "\n");
+ va_end(ap);
+ }
}
#ifdef _WIN32
BOOL WINAPI ConsoleCtrlHandlerRoutine(DWORD dwCtrlType)
{
- /*printf("Event: %u", dwCtrlType);*/
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO,
+ "Console: Ctrl+C");
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG,
+ "Console: Ctrl+C CtrlType: %u", dwCtrlType);
+
capture_loop_stop();
return TRUE;
@@ -415,13 +419,8 @@ main(int argc, char *argv[])
}
/* Let the user know what interface was chosen. */
-/* descr = get_interface_descriptive_name(capture_opts.iface);
- fprintf(stderr, "Capturing on %s\n", descr);
- g_free(descr);*/
-
- if(!capture_child) {
- fprintf(stderr, "Capturing on %s\n", capture_opts->iface);
- }
+ /* get_interface_descriptive_name() is not available! */
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_MESSAGE, "Interface: %s\n", capture_opts->iface);
if (list_link_layer_types) {
status = capture_opts_list_link_layer_types(capture_opts);
@@ -462,6 +461,10 @@ console_log_handler(const char *log_domain, GLogLevelFlags log_level,
const char *level;
+ if(capture_child) {
+ return;
+ }
+
/* ignore log message, if log_level isn't interesting */
if( !(log_level & G_LOG_LEVEL_MASK & ~(G_LOG_LEVEL_DEBUG|G_LOG_LEVEL_INFO))) {
#ifndef DEBUG_DUMPCAP
@@ -498,15 +501,25 @@ console_log_handler(const char *log_domain, GLogLevelFlags log_level,
g_assert_not_reached();
}
- /* don't use printf (stdout), as the capture child uses stdout for it's sync_pipe */
- fprintf(stderr, "%02u:%02u:%02u %8s %s %s\n",
- today->tm_hour, today->tm_min, today->tm_sec,
- log_domain != NULL ? log_domain : "",
- level, message);
+ /* don't use printf (stdout), in child mode we're using stdout for the sync_pipe */
+ if(log_level & G_LOG_LEVEL_MESSAGE) {
+ /* normal user messages without additional infos */
+ fprintf(stderr, "%s\n", message);
+ fflush(stderr);
+ } else {
+ /* info/debug messages with additional infos */
+ fprintf(stderr, "%02u:%02u:%02u %8s %s %s\n",
+ today->tm_hour, today->tm_min, today->tm_sec,
+ log_domain != NULL ? log_domain : "",
+ level, message);
+ fflush(stderr);
+ }
}
+
/****************************************************************************************************************/
-/* sync_pipe stubs */
+/* sync_pipe handling */
+
/*
* Maximum length of sync pipe message data. Must be < 2^24, as the
@@ -529,10 +542,6 @@ pipe_write_block(int pipe, char indicator, int len, const char *msg)
/*g_warning("write %d enter", pipe);*/
- /* if we're not a capture child, we don't have to tell our none existing parent anything */
- if(!capture_child)
- return;
-
g_assert(indicator < '0' || indicator > '9');
g_assert(len <= SP_MAX_MSG_LEN);
@@ -569,41 +578,39 @@ sync_pipe_packet_count_to_parent(int packet_count)
static int count = 0;
- if(!capture_child) {
+ if(capture_child) {
+ g_snprintf(tmp, sizeof(tmp), "%d", packet_count);
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "Packets: %s", tmp);
+ pipe_write_block(1, SP_PACKET_COUNT, strlen(tmp)+1, tmp);
+ } else {
count += packet_count;
- fprintf(stderr, "\r%u", count);
+ fprintf(stderr, "\rPackets: %u ", count);
/* stderr could be line buffered */
fflush(stderr);
}
- g_snprintf(tmp, sizeof(tmp), "%d", packet_count);
-
- g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "sync_pipe_packet_count_to_parent: %s", tmp);
-
- pipe_write_block(1, SP_PACKET_COUNT, strlen(tmp)+1, tmp);
}
void
sync_pipe_filename_to_parent(const char *filename)
{
- if(!capture_child) {
- fprintf(stderr, "\nFile: %s\n", filename);
- /* stderr could be line buffered */
- fflush(stderr);
- }
-
- g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "File: %s", filename);
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_MESSAGE, "File: %s", filename);
- pipe_write_block(1, SP_FILE, strlen(filename)+1, filename);
+ if(capture_child) {
+ pipe_write_block(1, SP_FILE, strlen(filename)+1, filename);
+ }
}
void
sync_pipe_errmsg_to_parent(const char *errmsg)
{
- g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "sync_pipe_errmsg_to_parent: %s", errmsg);
- pipe_write_block(1, SP_ERROR_MSG, strlen(errmsg)+1, errmsg);
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_MESSAGE, "Error: %s", errmsg);
+
+ if(capture_child) {
+ pipe_write_block(1, SP_ERROR_MSG, strlen(errmsg)+1, errmsg);
+ }
}
void
@@ -613,13 +620,51 @@ sync_pipe_drops_to_parent(int drops)
g_snprintf(tmp, sizeof(tmp), "%d", drops);
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_MESSAGE, "Packets dropped: %s", tmp);
- g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "sync_pipe_drops_to_parent: %s", tmp);
-
- pipe_write_block(1, SP_DROPS, strlen(tmp)+1, tmp);
+ if(capture_child) {
+ pipe_write_block(1, SP_DROPS, strlen(tmp)+1, tmp);
+ }
}
+/****************************************************************************************************************/
+/* signal_pipe handling */
+
+
+#ifdef _WIN32
+gboolean
+signal_pipe_check_running(void)
+{
+ /* any news from our parent (stdin)? -> just stop the capture */
+ HANDLE handle;
+ DWORD avail = 0;
+ gboolean result;
+
+
+ /* if we are running standalone, no check required */
+ if(!capture_child) {
+ return TRUE;
+ }
+
+ handle = (HANDLE) GetStdHandle(STD_INPUT_HANDLE);
+ result = PeekNamedPipe(handle, NULL, 0, NULL, &avail, NULL);
+
+ if(!result || avail > 0) {
+ /* peek failed or some bytes really available */
+ /* (if not piping from stdin this would fail) */
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO,
+ "Signal pipe: Stop capture");
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG,
+ "Signal pipe: handle: %x result: %u avail: %u", handle, result, avail);
+ return FALSE;
+ } else {
+ /* pipe ok and no bytes available */
+ return TRUE;
+ }
+}
+#endif
+
/****************************************************************************************************************/
/* simple_dialog stubs */
@@ -652,6 +697,7 @@ simple_dialog_format_message(const char *msg)
return str;
}
+
/****************************************************************************************************************/
/* Stub functions */
diff --git a/gtk/capture_dlg.c b/gtk/capture_dlg.c
index 51f6b7351d..dc44a49f03 100644
--- a/gtk/capture_dlg.c
+++ b/gtk/capture_dlg.c
@@ -28,7 +28,6 @@
#ifdef HAVE_LIBPCAP
-#include <pcap.h>
#include <string.h>
#include <gtk/gtk.h>
@@ -159,7 +158,7 @@ set_link_type_list(GtkWidget *linktype_om, GtkWidget *entry)
if_info_t *if_info;
GList *lt_list;
int err;
- char err_buf[PCAP_ERRBUF_SIZE];
+ char err_buf[CAPTURE_PCAP_ERRBUF_SIZE];
GtkWidget *lt_menu, *lt_menu_item;
GList *lt_entry;
data_link_info_t *data_link_info;
@@ -525,7 +524,7 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
GList *if_list, *combo_list, *cfilter_list;
int err;
int row;
- char err_str[PCAP_ERRBUF_SIZE];
+ char err_str[CAPTURE_PCAP_ERRBUF_SIZE];
gchar *cant_get_if_list_errstr;
#ifdef _WIN32
GtkAdjustment *buffer_size_adj;
diff --git a/gtk/capture_if_details_dlg.c b/gtk/capture_if_details_dlg.c
index eda8b5c49b..02e9b06f3d 100644
--- a/gtk/capture_if_details_dlg.c
+++ b/gtk/capture_if_details_dlg.c
@@ -38,7 +38,6 @@
#include "globals.h"
#include "file.h"
-#include <pcap.h>
#include "capture.h"
#include "main.h"
#include "dlg_utils.h"
diff --git a/gtk/capture_if_dlg.c b/gtk/capture_if_dlg.c
index 417f11eed9..17aa92732c 100644
--- a/gtk/capture_if_dlg.c
+++ b/gtk/capture_if_dlg.c
@@ -33,8 +33,6 @@
#endif
-#include <pcap.h>
-
#include <gtk/gtk.h>
#include "globals.h"
@@ -160,7 +158,7 @@ capture_details_cb(GtkWidget *details_bt _U_, gpointer if_data)
static void
open_if(gchar *name, if_dlg_data_t *if_dlg_data)
{
- gchar open_err_str[PCAP_ERRBUF_SIZE];
+ gchar open_err_str[CAPTURE_PCAP_ERRBUF_SIZE];
/*
* XXX - on systems with BPF, the number of BPF devices limits the
@@ -328,7 +326,7 @@ capture_if_cb(GtkWidget *w _U_, gpointer d _U_)
#endif
GtkTooltips *tooltips;
int err;
- char err_str[PCAP_ERRBUF_SIZE];
+ char err_str[CAPTURE_PCAP_ERRBUF_SIZE];
gchar *cant_get_if_list_errstr;
int row;
if_dlg_data_t *if_dlg_data;
diff --git a/gtk/capture_info_dlg.c b/gtk/capture_info_dlg.c
index 6dd4feecef..e03e6f8151 100644
--- a/gtk/capture_info_dlg.c
+++ b/gtk/capture_info_dlg.c
@@ -30,7 +30,6 @@
#ifdef HAVE_LIBPCAP
-#include <pcap.h>
#include <gtk/gtk.h>
#include "gtk/compat_macros.h"
@@ -38,7 +37,6 @@
#include <epan/packet.h>
#include "capture.h"
-#include "capture_loop.h"
#include "capture_info.h"
#include "globals.h"
#include "capture_ui_utils.h"
diff --git a/gtk/capture_prefs.c b/gtk/capture_prefs.c
index 403990169e..c17b75e053 100644
--- a/gtk/capture_prefs.c
+++ b/gtk/capture_prefs.c
@@ -28,7 +28,6 @@
#ifdef HAVE_LIBPCAP
-#include <pcap.h>
#include <string.h>
#include <gtk/gtk.h>
@@ -85,7 +84,7 @@ capture_prefs_show(void)
GtkWidget *ifopts_lb, *ifopts_bt;
GList *if_list, *combo_list;
int err;
- char err_str[PCAP_ERRBUF_SIZE];
+ char err_str[CAPTURE_PCAP_ERRBUF_SIZE];
int row = 0;
GtkTooltips *tooltips = gtk_tooltips_new();
@@ -695,7 +694,7 @@ ifopts_if_clist_add(void)
{
GList *if_list;
int err;
- char err_str[PCAP_ERRBUF_SIZE];
+ char err_str[CAPTURE_PCAP_ERRBUF_SIZE];
gchar *cant_get_if_list_errstr;
if_info_t *if_info;
guint i;
diff --git a/gtk/cfilter_combo_utils.c b/gtk/cfilter_combo_utils.c
index ef0821ea79..9c184d3e26 100644
--- a/gtk/cfilter_combo_utils.c
+++ b/gtk/cfilter_combo_utils.c
@@ -34,7 +34,6 @@
#include "cfilter_combo_utils.h"
#include "recent.h"
#ifdef HAVE_LIBPCAP
-#include <pcap.h>
#endif
/* XXX: use a preference for this setting! */
diff --git a/gtk/drag_and_drop.c b/gtk/drag_and_drop.c
index d868de3e61..86471eee82 100644
--- a/gtk/drag_and_drop.c
+++ b/gtk/drag_and_drop.c
@@ -26,10 +26,6 @@
# include "config.h"
#endif
-#ifdef HAVE_LIBPCAP
-#include <pcap.h>
-#endif
-
#include <gtk/gtk.h>
#include "globals.h"
diff --git a/gtk/main.c b/gtk/main.c
index aa03b5a950..4f07243c23 100644
--- a/gtk/main.c
+++ b/gtk/main.c
@@ -91,7 +91,6 @@
#include "merge.h"
#ifdef HAVE_LIBPCAP
-#include <pcap.h>
#include "capture-pcap-util.h"
#include "capture.h"
#include "capture_sync.h"
diff --git a/gtk/summary_dlg.c b/gtk/summary_dlg.c
index d93bc8411f..cab8194c3d 100644
--- a/gtk/summary_dlg.c
+++ b/gtk/summary_dlg.c
@@ -36,7 +36,6 @@
#include "globals.h"
#include "file.h"
#ifdef HAVE_LIBPCAP
-#include <pcap.h>
#include "capture.h"
#include "main.h"
#endif
diff --git a/summary.h b/summary.h
index e417fef693..e11c6b7b99 100644
--- a/summary.h
+++ b/summary.h
@@ -26,7 +26,6 @@
#define __SUMMARY_H__
#ifdef HAVE_LIBPCAP
-#include <pcap.h>
#include "capture.h"
#endif
diff --git a/tempfile.c b/tempfile.c
index d82a3d3924..38da552d67 100644
--- a/tempfile.c
+++ b/tempfile.c
@@ -48,12 +48,6 @@
#define eth_mkstemp mkstemp
#endif
-/*
- * This has to come after the include of <pcap.h>, as the include of
- * <pcap.h> might cause <winsock2.h> to be included, and if we've
- * already included <winsock.h> as a result of including <windows.h>,
- * we get a bunch of redefinitions.
- */
#ifdef HAVE_WINDOWS_H
#include <windows.h>
#endif
diff --git a/tethereal.c b/tethereal.c
index 10d6049c1d..845c5ad352 100644
--- a/tethereal.c
+++ b/tethereal.c
@@ -2908,6 +2908,23 @@ sync_pipe_errmsg_to_parent(const char *errmsg)
/****************************************************************************************************************/
+/* signal pipe "dummies", needed for capture_loop.c */
+
+#ifdef HAVE_LIBPCAP
+
+#ifdef _WIN32
+gboolean
+signal_pipe_check_running(void)
+{
+ /* currently, no check required */
+ return TRUE;
+}
+#endif /* _WIN32 */
+
+#endif /* HAVE_LIBPCAP */
+
+
+/****************************************************************************************************************/
/* simple_dialog "dummies", needed for capture_loop.c */
diff --git a/version_info.c b/version_info.c
index 141b556f6c..e6a15d939d 100644
--- a/version_info.c
+++ b/version_info.c
@@ -40,10 +40,6 @@
#include <pcre.h> /* to get the libpcre version number */
#endif /* HAVE_LIBPCRE */
-#ifdef HAVE_WINDOWS_H
-#include <windows.h>
-#endif
-
#ifdef HAVE_SOME_SNMP
#ifdef HAVE_NET_SNMP
@@ -65,6 +61,11 @@
#include "svnversion.h"
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
+#endif
+
+
#ifdef SVNVERSION
const char *svnversion = " (" SVNVERSION ")";
#else