summaryrefslogtreecommitdiff
path: root/capture_loop.c
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 /capture_loop.c
parent4a5deae5759f85eba4592689aec83ce380959af6 (diff)
downloadwireshark-5d404864f204147ede0cb6e19c64e06ebdb85496.tar.gz
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
Diffstat (limited to 'capture_loop.c')
-rw-r--r--capture_loop.c91
1 files changed, 83 insertions, 8 deletions
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;
}