aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Lamping <ulf.lamping@web.de>2005-05-26 17:50:27 +0000
committerUlf Lamping <ulf.lamping@web.de>2005-05-26 17:50:27 +0000
commit5d404864f204147ede0cb6e19c64e06ebdb85496 (patch)
tree91a8bae1bf7b20b378e960da7c100cb4475479ef
parent4a5deae5759f85eba4592689aec83ce380959af6 (diff)
use the log features of the GLib to have verbose output of the capturing engine, e.g. GLib provides different domains for different submodules. Output more verbose than warning level will be disabled by default (just like before).
use the console_log_handler in main.c for win32 AND unix now Currently use the log for the capturing engine (only), as I desperately needed a log output for debugging. svn path=/trunk/; revision=14438
-rw-r--r--capture.c16
-rw-r--r--capture.h6
-rw-r--r--capture_loop.c91
-rw-r--r--capture_opts.c52
-rw-r--r--capture_sync.c30
-rw-r--r--gtk/main.c81
-rw-r--r--log.h39
7 files changed, 267 insertions, 48 deletions
diff --git a/capture.c b/capture.c
index 2d8b23c0a8..2a8e5b43ac 100644
--- a/capture.c
+++ b/capture.c
@@ -69,6 +69,7 @@
#include "capture-wpcap.h"
#endif
#include "ui_util.h"
+#include "log.h"
@@ -89,6 +90,8 @@ capture_start(capture_options *capture_opts)
g_assert(capture_opts->state == CAPTURE_STOPPED);
capture_opts->state = CAPTURE_PREPARING;
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Start ...");
+
/* try to start the capture child process */
ret = sync_pipe_start(capture_opts);
if(!ret) {
@@ -114,6 +117,8 @@ capture_start(capture_options *capture_opts)
void
capture_stop(capture_options *capture_opts)
{
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Stop ...");
+
/* stop the capture child gracefully */
sync_pipe_stop(capture_opts);
}
@@ -122,6 +127,8 @@ capture_stop(capture_options *capture_opts)
void
capture_restart(capture_options *capture_opts)
{
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Restart");
+
capture_opts->restart = TRUE;
capture_stop(capture_opts);
}
@@ -130,6 +137,8 @@ capture_restart(capture_options *capture_opts)
void
capture_kill_child(capture_options *capture_opts)
{
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Kill");
+
/* kill the capture child */
sync_pipe_kill(capture_opts);
}
@@ -225,8 +234,12 @@ capture_input_new_file(capture_options *capture_opts, gchar *new_file)
int err;
+ if(capture_opts->state == CAPTURE_PREPARING) {
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture started!");
+ }
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "File: \"%s\"", new_file);
+
g_assert(capture_opts->state == CAPTURE_PREPARING || capture_opts->state == CAPTURE_RUNNING);
- /*g_warning("New capture file: %s", new_file);*/
/* free the old filename */
if(capture_opts->save_file != NULL) {
@@ -317,6 +330,7 @@ capture_input_closed(capture_options *capture_opts)
int err;
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture stopped!");
g_assert(capture_opts->state == CAPTURE_PREPARING || capture_opts->state == CAPTURE_RUNNING);
/* if we didn't started the capture (happens if an error occured), do a fake start */
diff --git a/capture.h b/capture.h
index c7e3677f5c..c46c21f6e5 100644
--- a/capture.h
+++ b/capture.h
@@ -106,6 +106,12 @@ capture_opts_init(capture_options *capture_opts, void *cfile);
extern void
capture_opts_add_opt(capture_options *capture_opts, const char *appname, int opt, const char *optarg, gboolean *start_capture);
+/* log content of capture_opts */
+extern void
+capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_options *capture_opts);
+
+
+
/**
* Start a capture session.
*
diff --git a/capture_loop.c b/capture_loop.c
index fd1a6c53b1..17f069b95b 100644
--- a/capture_loop.c
+++ b/capture_loop.c
@@ -86,6 +86,7 @@
/* XXX - try to remove this later */
#include "util.h"
#include "alert_box.h"
+#include "log.h"
#include <epan/dissectors/packet-ap1394.h>
@@ -240,6 +241,9 @@ cap_pipe_open_live(char *pipename, struct pcap_hdr *hdr, loop_data *ld,
fd_set rfds;
struct timeval timeout;
+
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "cap_pipe_open_live: %s", pipename);
+
/*
* XXX Ethereal blocks until we return
*/
@@ -387,6 +391,7 @@ cap_pipe_open_live(char *pipename, struct pcap_hdr *hdr, loop_data *ld,
return fd;
error:
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "cap_pipe_open_live: error %s", errmsg);
ld->cap_pipe_err = PIPERR;
close(fd);
return -1;
@@ -406,6 +411,11 @@ cap_pipe_dispatch(int fd, loop_data *ld, struct pcap_hdr *hdr,
enum { PD_REC_HDR_READ, PD_DATA_READ, PD_PIPE_EOF, PD_PIPE_ERR,
PD_ERR } result;
+
+#ifdef LOG_CAPTURE_VERBOSE
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "cap_pipe_dispatch");
+#endif
+
switch (ld->cap_pipe_state) {
case STATE_EXPECT_REC_HDR:
@@ -515,6 +525,9 @@ static int capture_loop_open_input(capture_options *capture_opts, loop_data *ld,
char *libpcap_warn;
#endif
+
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "capture_loop_open_input : %s", capture_opts->iface);
+
/* Initialize Windows Socket if we are in a WIN32 OS
This needs to be done before querying the interface for network/netmask */
#ifdef _WIN32
@@ -691,6 +704,9 @@ static int capture_loop_open_input(capture_options *capture_opts, loop_data *ld,
/* open the capture input file (pcap or capture pipe) */
static void capture_loop_close_input(loop_data *ld) {
+
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "capture_loop_close_input");
+
#ifndef _WIN32
/* if open, close the capture pipe "input file" */
if (ld->cap_pipe_fd >= 0) {
@@ -718,6 +734,9 @@ static int capture_loop_init_filter(loop_data *ld, const gchar * iface, gchar *
gchar lookup_net_err_str[PCAP_ERRBUF_SIZE];
struct bpf_program fcode;
+
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "capture_loop_init_filter: %s", cfilter);
+
/* capture filters only work on real interfaces */
if (cfilter && !ld->from_cap_pipe) {
/* A capture filter was specified; set it up. */
@@ -779,12 +798,14 @@ static int capture_loop_init_filter(loop_data *ld, const gchar * iface, gchar *
/* open the wiretap part of the capture output file */
-static int capture_loop_open_wiretap_output(capture_options *capture_opts, int save_file_fd, loop_data *ld, char *errmsg, int errmsg_len) {
+static int capture_loop_init_wiretap_output(capture_options *capture_opts, int save_file_fd, loop_data *ld, char *errmsg, int errmsg_len) {
int pcap_encap;
int file_snaplen;
int err;
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "capture_loop_init_wiretap_output");
+
/* get packet encapsulation type and snaplen */
#ifndef _WIN32
if (ld->from_cap_pipe) {
@@ -849,6 +870,9 @@ static int capture_loop_open_wiretap_output(capture_options *capture_opts, int s
}
static gboolean capture_loop_close_output(capture_options *capture_opts, loop_data *ld, int *err_close) {
+
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "capture_loop_close_output");
+
if (capture_opts->multi_files_on) {
return ringbuf_wtap_dump_close(&capture_opts->save_file, err_close);
} else {
@@ -872,6 +896,9 @@ capture_loop_dispatch(capture_options *capture_opts, loop_data *ld,
#ifndef _WIN32
if (ld->from_cap_pipe) {
/* dispatch from capture pipe */
+#ifdef LOG_CAPTURE_VERBOSE
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "capture_loop_dispatch: from capture pipe");
+#endif
FD_ZERO(&set1);
FD_SET(ld->cap_pipe_fd, &set1);
timeout.tv_sec = 0;
@@ -938,6 +965,9 @@ capture_loop_dispatch(capture_options *capture_opts, loop_data *ld,
* that's unacceptable, plead with whoever supplies the software
* for that device to add "select()" support.
*/
+#ifdef LOG_CAPTURE_VERBOSE
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "capture_loop_dispatch: from pcap_dispatch with select");
+#endif
if (ld->pcap_fd != -1) {
FD_ZERO(&set1);
FD_SET(ld->pcap_fd, &set1);
@@ -968,14 +998,50 @@ capture_loop_dispatch(capture_options *capture_opts, loop_data *ld,
#endif /* MUST_DO_SELECT */
{
/* dispatch from pcap without select */
+#if 1
+#ifdef LOG_CAPTURE_VERBOSE
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "capture_loop_dispatch: from pcap_dispatch");
+#endif
inpkts = pcap_dispatch(ld->pcap_h, 1, capture_loop_packet_cb, (gchar *) ld);
if (inpkts < 0) {
ld->pcap_err = TRUE;
ld->go = FALSE;
}
+#else
+ {
+#ifdef LOG_CAPTURE_VERBOSE
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "capture_loop_dispatch: from pcap_next_ex");
+#endif
+ /* XXX - this is currently unused, as there is some confusion with pcap_next_ex() vs. pcap_dispatch() */
+
+ /* WinPcap's remote capturing feature doesn't work, see http://wiki.ethereal.com/CaptureSetup_2fWinPcapRemote */
+ /* for reference, an example remote interface: rpcap://[1.2.3.4]/\Device\NPF_{39993D68-7C9B-4439-A329-F2D888DA7C5C} */
+
+ /* emulate dispatch from pcap */
+ int in;
+ struct pcap_pkthdr *pkt_header;
+ u_char *pkt_data;
+
+ inpkts = 0;
+ while( (in = pcap_next_ex(ld->pcap_h, &pkt_header, &pkt_data)) == 1) {
+ capture_loop_packet_cb( (gchar *) ld, pkt_header, pkt_data);
+ inpkts++;
+ }
+
+ if(in < 0) {
+ ld->pcap_err = TRUE;
+ ld->go = FALSE;
+ inpkts = in;
+ }
+ }
+#endif
}
}
+#ifdef LOG_CAPTURE_VERBOSE
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "capture_loop_dispatch: %d new packet%s", inpkts, plurality(inpkts, "", "s"));
+#endif
+
return inpkts;
}
@@ -991,6 +1057,9 @@ capture_loop_open_output(capture_options *capture_opts, int *save_file_fd,
gboolean is_tempfile;
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "capture_loop_open_output: %s",
+ (capture_opts->save_file) ? capture_opts->save_file : "");
+
if (capture_opts->save_file != NULL) {
/* We return to the caller while the capture is in progress.
* Therefore we need to take a copy of save_file in
@@ -1023,7 +1092,7 @@ capture_loop_open_output(capture_options *capture_opts, int *save_file_fd,
/* did we fail to open the output file? */
if (*save_file_fd == -1) {
if (is_tempfile) {
- simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
+ g_snprintf(errmsg, errmsg_len,
"The temporary file to which the capture would be saved (\"%s\") "
"could not be opened: %s.", capfile_name, strerror(errno));
} else {
@@ -1135,9 +1204,10 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
/* We haven't yet gotten the capture statistics. */
*stats_known = FALSE;
- /*g_warning("capture_loop_start");
- capture_opts_info(capture_opts);*/
-
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "Capture child starting ...");
+#ifdef LOG_CAPTURE_VERBOSE
+ capture_opts_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, capture_opts);
+#endif
/* open the output file (temporary/specified name/ringbuffer) */
if (!capture_loop_open_output(capture_opts, &save_file_fd, errmsg, sizeof(errmsg))) {
@@ -1155,7 +1225,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
}
/* open the wiretap part of the output file (the output file is already open) */
- if (!capture_loop_open_wiretap_output(capture_opts, save_file_fd, &ld, errmsg, sizeof(errmsg))) {
+ if (!capture_loop_init_wiretap_output(capture_opts, save_file_fd, &ld, errmsg, sizeof(errmsg))) {
goto error;
}
@@ -1206,6 +1276,9 @@ 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!");
+
/* WOW, everything is prepared! */
/* please fasten your seat belts, we will enter now the actual capture loop */
while (ld.go) {
@@ -1347,6 +1420,8 @@ 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 ...");
+
/* close capture info dialog */
if(capture_opts->show_info) {
capture_info_destroy(&capture_ui);
@@ -1423,7 +1498,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_warning("loop closed");*/
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "Capture child stopped!");
/* ok, if the write and the close were successful. */
return write_ok && close_ok;
@@ -1448,7 +1523,7 @@ error:
/* close the input file (pcap or cap_pipe) */
capture_loop_close_input(&ld);
- /*g_warning("loop error");*/
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "Capture child stopped with error: %s", errmsg);
return FALSE;
}
diff --git a/capture_opts.c b/capture_opts.c
index 938c2832b7..74b1a7992a 100644
--- a/capture_opts.c
+++ b/capture_opts.c
@@ -89,36 +89,36 @@ capture_opts_init(capture_options *capture_opts, void *cfile)
}
-/* debug only: print content of capture_opts to console */
+/* log content of capture_opts */
void
-capture_opts_info(capture_options *capture_opts) {
- g_warning("CAPTURE OPTIONS :");
- g_warning("File : %p", capture_opts->cf);
- g_warning("Filter : %s", capture_opts->cfilter);
- g_warning("Interface : %s", capture_opts->iface);
+capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_options *capture_opts) {
+ g_log(log_domain, log_level, "CAPTURE OPTIONS :");
+ g_log(log_domain, log_level, "CFile : 0x%p", capture_opts->cf);
+ g_log(log_domain, log_level, "Filter : %s", capture_opts->cfilter);
+ g_log(log_domain, log_level, "Interface : %s", capture_opts->iface);
#ifdef _WIN32
- g_warning("BufferSize : %u (MB)", capture_opts->buffer_size);
+ g_log(log_domain, log_level, "BufferSize : %u (MB)", capture_opts->buffer_size);
#endif
- g_warning("SnapLen (%u): %u", capture_opts->has_snaplen, capture_opts->snaplen);
- g_warning("Promisc : %u", capture_opts->promisc_mode);
- g_warning("LinkType : %d", capture_opts->linktype);
- g_warning("SaveFile : %s", (capture_opts->save_file) ? capture_opts->save_file : "");
- g_warning("RealTimeMode : %u", capture_opts->real_time_mode);
- g_warning("ShowInfo : %u", capture_opts->show_info);
- g_warning("QuitAfterCap : %u", capture_opts->quit_after_cap);
-
- g_warning("MultiFilesOn : %u", capture_opts->multi_files_on);
- g_warning("FileDuration (%u): %u", capture_opts->has_file_duration, capture_opts->file_duration);
- g_warning("RingNumFiles (%u): %u", capture_opts->has_ring_num_files, capture_opts->ring_num_files);
-
- g_warning("AutostopFiles (%u): %u", capture_opts->has_autostop_files, capture_opts->autostop_files);
- g_warning("AutostopPackets (%u): %u", capture_opts->has_autostop_packets, capture_opts->autostop_packets);
- g_warning("AutostopFilesize(%u): %u", capture_opts->has_autostop_filesize, capture_opts->autostop_filesize);
- g_warning("AutostopDuration(%u): %u", capture_opts->has_autostop_duration, capture_opts->autostop_duration);
-
- g_warning("ForkChild : %d", capture_opts->fork_child);
+ g_log(log_domain, log_level, "SnapLen (%u): %u", capture_opts->has_snaplen, capture_opts->snaplen);
+ g_log(log_domain, log_level, "Promisc : %u", capture_opts->promisc_mode);
+ g_log(log_domain, log_level, "LinkType : %d", capture_opts->linktype);
+ g_log(log_domain, log_level, "SaveFile : %s", (capture_opts->save_file) ? capture_opts->save_file : "");
+ g_log(log_domain, log_level, "RealTimeMode : %u", capture_opts->real_time_mode);
+ g_log(log_domain, log_level, "ShowInfo : %u", capture_opts->show_info);
+ g_log(log_domain, log_level, "QuitAfterCap : %u", capture_opts->quit_after_cap);
+
+ g_log(log_domain, log_level, "MultiFilesOn : %u", capture_opts->multi_files_on);
+ g_log(log_domain, log_level, "FileDuration (%u): %u", capture_opts->has_file_duration, capture_opts->file_duration);
+ g_log(log_domain, log_level, "RingNumFiles (%u): %u", capture_opts->has_ring_num_files, capture_opts->ring_num_files);
+
+ g_log(log_domain, log_level, "AutostopFiles (%u): %u", capture_opts->has_autostop_files, capture_opts->autostop_files);
+ g_log(log_domain, log_level, "AutostopPackets (%u): %u", capture_opts->has_autostop_packets, capture_opts->autostop_packets);
+ g_log(log_domain, log_level, "AutostopFilesize(%u): %u", capture_opts->has_autostop_filesize, capture_opts->autostop_filesize);
+ g_log(log_domain, log_level, "AutostopDuration(%u): %u", capture_opts->has_autostop_duration, capture_opts->autostop_duration);
+
+ g_log(log_domain, log_level, "ForkChild : %d", capture_opts->fork_child);
#ifdef _WIN32
- g_warning("SignalPipeFd : %d", capture_opts->signal_pipe_fd);
+ g_log(log_domain, log_level, "SignalPipeFd : %d", capture_opts->signal_pipe_fd);
#endif
}
diff --git a/capture_sync.c b/capture_sync.c
index 90bfdc0dff..249384de08 100644
--- a/capture_sync.c
+++ b/capture_sync.c
@@ -87,6 +87,7 @@
#include "capture-wpcap.h"
#endif
#include "ui_util.h"
+#include "log.h"
#ifdef HAVE_IO_H
# include <io.h>
@@ -228,21 +229,26 @@ sync_pipe_packet_count_to_parent(int packet_count)
{
char tmp[SP_DECISIZE+1+1];
-
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)
{
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "sync_pipe_filename_to_parent: %s", filename);
+
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);
}
@@ -254,6 +260,8 @@ sync_pipe_drops_to_parent(int drops)
g_snprintf(tmp, sizeof(tmp), "%d", drops);
+ 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);
}
@@ -264,6 +272,7 @@ static void
signal_pipe_capquit_to_child(capture_options *capture_opts)
{
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "signal_pipe_capquit_to_child");
pipe_write_block(capture_opts->signal_pipe_fd, SP_QUIT, 0, NULL);
}
@@ -339,8 +348,10 @@ sync_pipe_start(capture_options *capture_opts) {
int sync_pipe[2]; /* pipe used to send messages from child to parent */
- /*g_warning("sync_pipe_start");
- capture_opts_info(capture_opts);*/
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_start");
+#ifdef LOG_CAPTURE_VERBOSE
+ capture_opts_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, capture_opts);
+#endif
capture_opts->fork_child = -1;
@@ -579,7 +590,6 @@ sync_pipe_start(capture_options *capture_opts) {
return TRUE;
}
-
/* There's stuff to read from the sync pipe, meaning the child has sent
us a message, or the sync pipe has closed, meaning the child has
closed it (perhaps because it exited). */
@@ -595,10 +605,13 @@ sync_pipe_input_cb(gint source, gpointer user_data)
nread = pipe_read_block(source, &indicator, BUFSIZE, buffer);
if(nread <= 0) {
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_input_cb: child has closed sync_pipe");
+
/* The child has closed the sync pipe, meaning it's not going to be
capturing any more packets. Pick up its exit status, and
complain if it did anything other than exit with status 0. */
sync_pipe_wait_for_child(capture_opts, FALSE);
+
#ifdef _WIN32
close(capture_opts->signal_pipe_fd);
#endif
@@ -609,6 +622,8 @@ sync_pipe_input_cb(gint source, gpointer user_data)
switch(indicator) {
case SP_FILE:
if(!capture_input_new_file(capture_opts, buffer)) {
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_input_cb: file failed, closing capture");
+
/* We weren't able to open the new capture file; user has been
alerted. Close the sync pipe. */
/* XXX - is it safe to close the pipe inside this callback? */
@@ -624,12 +639,16 @@ sync_pipe_input_cb(gint source, gpointer user_data)
break;
case SP_PACKET_COUNT:
nread = atoi(buffer);
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_input_cb: new packets %u", nread);
capture_input_new_packets(capture_opts, nread);
break;
case SP_ERROR_MSG:
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Error message from child: \"%s\"", buffer);
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, buffer);
+ /* the capture child will close the sync_pipe, nothing to do for now */
break;
case SP_DROPS:
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_INFO, "%d packet%s dropped", atoi(buffer), plurality(atoi(buffer), "", "s"));
cf_set_drops_known(capture_opts->cf, TRUE);
cf_set_drops(capture_opts->cf, atoi(buffer));
break;
@@ -649,6 +668,7 @@ sync_pipe_wait_for_child(capture_options *capture_opts, gboolean always_report)
int wstatus;
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_wait_for_child: wait till child closed");
g_assert(capture_opts->fork_child != -1);
#ifdef _WIN32
@@ -691,6 +711,8 @@ sync_pipe_wait_for_child(capture_options *capture_opts, gboolean always_report)
/* No more child process. */
capture_opts->fork_child = -1;
#endif
+
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_wait_for_child: capture child closed");
}
diff --git a/gtk/main.c b/gtk/main.c
index f23ba89352..62098e55eb 100644
--- a/gtk/main.c
+++ b/gtk/main.c
@@ -137,6 +137,7 @@
#include "../image/eicon3d64.xpm"
#endif
#include "capture_ui_utils.h"
+#include "log.h"
@@ -173,9 +174,9 @@ gboolean have_capture_file = FALSE; /* XXX - is there an aquivalent in cfile? */
static gboolean has_console; /* TRUE if app has console */
/*static void create_console(void);*/
static void destroy_console(void);
+#endif
static void console_log_handler(const char *log_domain,
GLogLevelFlags log_level, const char *message, gpointer user_data);
-#endif
#ifdef HAVE_LIBPCAP
static gboolean list_link_layer_types;
@@ -1606,6 +1607,7 @@ main(int argc, char *argv[])
char badopt;
GtkWidget *splash_win = NULL;
gboolean capture_child; /* True if this is the child for "-S" */
+ GLogLevelFlags log_flags;
#define OPTSTRING_INIT "a:b:B:c:f:Hhi:klLm:nN:o:pP:Qr:R:Ss:t:T:w:vy:z:"
@@ -1641,25 +1643,42 @@ main(int argc, char *argv[])
ethereal_path = argv[0];
-#ifdef _WIN32
/* Arrange that if we have no console window, and a GLib message logging
routine is called to log a message, we pop up a console window.
We do that by inserting our own handler for all messages logged
to the default domain; that handler pops up a console if necessary,
and then calls the default handler. */
- g_log_set_handler(NULL,
+
+ /* We might want to have component specific log levels later ... */
+
+ /* XXX - BEWARE: GLib is buggy (at least 2.4.7 on Win32) and
+ /* will show very odd behaviour and might even crash, if NO handler for a */
+ /* specific combination of domain and level is registered :-( */
+
+ /* so register all possible combinations and filter levels inside the */
+ /* console_log_handler */
+ log_flags =
G_LOG_LEVEL_ERROR|
G_LOG_LEVEL_CRITICAL|
G_LOG_LEVEL_WARNING|
G_LOG_LEVEL_MESSAGE|
G_LOG_LEVEL_INFO|
G_LOG_LEVEL_DEBUG|
- G_LOG_FLAG_FATAL|G_LOG_FLAG_RECURSION,
- console_log_handler, NULL);
-#endif
+ G_LOG_FLAG_FATAL|G_LOG_FLAG_RECURSION;
+
+ g_log_set_handler(NULL,
+ log_flags,
+ console_log_handler, NULL /* user_data */);
#ifdef HAVE_LIBPCAP
+ g_log_set_handler(LOG_DOMAIN_CAPTURE,
+ log_flags,
+ console_log_handler, NULL /* user_data */);
+ g_log_set_handler(LOG_DOMAIN_CAPTURE_CHILD,
+ log_flags,
+ console_log_handler, NULL /* user_data */);
+
/* Set the initial values in the capture_opts. This might be overwritten
by preference settings and then again by the command line parameters. */
capture_opts_init(capture_opts, &cfile);
@@ -2559,6 +2578,8 @@ destroy_console(void)
FreeConsole();
}
}
+#endif /* _WIN32 */
+
/* This routine should not be necessary, at least as I read the GLib
source code, as it looks as if GLib is, on Win32, *supposed* to
@@ -2574,16 +2595,58 @@ static void
console_log_handler(const char *log_domain, GLogLevelFlags log_level,
const char *message, gpointer user_data)
{
+ time_t curr;
+ struct tm *today;
+ const char *level;
+
+
+ /* only display warning and more critical messages */
+ /* change this, if you need more verbose output (e.g. for debugging) */
+ if(log_level > G_LOG_LEVEL_WARNING) {
+ return;
+ }
+
+ /* create a "timestamp" */
+ time(&curr);
+ today = localtime(&curr);
+
+#ifdef _WIN32
create_console();
if (has_console) {
/* For some unknown reason, the above doesn't appear to actually cause
anything to be sent to the standard output, so we'll just splat the
message out directly, just to make sure it gets out. */
- printf("%s\n", message);
- } else
+#endif
+ switch(log_level) {
+ case G_LOG_LEVEL_ERROR:
+ level = "Err ";
+ break;
+ case G_LOG_LEVEL_CRITICAL:
+ level = "Crit";
+ break;
+ case G_LOG_LEVEL_WARNING:
+ level = "Warn";
+ break;
+ case G_LOG_LEVEL_MESSAGE:
+ level = "Msg ";
+ break;
+ case G_LOG_LEVEL_INFO:
+ level = "Info";
+ break;
+ case G_LOG_LEVEL_DEBUG:
+ level = "Dbg ";
+ break;
+ default:
+ g_assert_not_reached();
+ }
+
+ printf("%02u:%02u:%02u %s %s %s\n", today->tm_hour, today->tm_min, today->tm_sec, log_domain, level, message);
+#ifdef _WIN32
+ } else {
g_log_default_handler(log_domain, log_level, message, user_data);
-}
+ }
#endif
+}
GtkWidget *info_bar_new(void)
diff --git a/log.h b/log.h
new file mode 100644
index 0000000000..56bb60d6f2
--- /dev/null
+++ b/log.h
@@ -0,0 +1,39 @@
+/* log.h
+ * log output definitions
+ *
+ * $Id$
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@ethereal.com>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __LOG_H__
+#define __LOG_H__
+
+/* capture domain (except for capture child, see below) */
+#define LOG_DOMAIN_CAPTURE "Capture"
+
+/* capture child domain (the capture child might also contain file domain messages!) */
+#define LOG_DOMAIN_CAPTURE_CHILD "CaptureChild"
+
+
+/* enable very verbose capture log debug output */
+/*#define LOG_CAPTURE_VERBOSE*/
+
+
+#endif