g_slist_foreach(if_info->ip_addr, free_if_info_addr_cb, NULL);
g_slist_free(if_info->ip_addr);
+ g_free(if_info);
}
void
unsigned int bytes_read;
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "cap_pipe_open_live: %s", pipename);
+
+ if(pipename == NULL){
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_WARNING, "cap_pipe_open_live: pipe name is NULL");
+ g_snprintf(errmsg, errmsgl,
+ "The capture session could not be initiated because the pipe is not valid, maybe lack of privileges?");
+ return -1;
+ }
/*
* XXX (T)Wireshark blocks until we return
if (ld->cap_pipe_fd >= 0) {
g_assert(ld->from_cap_pipe);
eth_close(ld->cap_pipe_fd);
+ ld->cap_pipe_fd = 0;
}
/* if open, close the pcap "input file" */
if(ld->pcap_h != NULL) {
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "capture_loop_close_input: closing %p", ld->pcap_h);
g_assert(!ld->from_cap_pipe);
pcap_close(ld->pcap_h);
+ ld->pcap_h = NULL;
}
+ ld->go = FALSE;
+
#ifdef _WIN32
/* Shut down windows sockets */
WSACleanup();
#ifdef LOG_CAPTURE_VERBOSE
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "capture_loop_dispatch: from pcap_dispatch");
#endif
+ if(ld->pcap_h){
+ /* libpcap crashed when the pcap handle is NULL!!*/
#ifdef _WIN32
/*
* On Windows, we don't support asynchronously telling a process to
#else
inpkts = pcap_dispatch(ld->pcap_h, -1, ld->packet_cb, (u_char *) ld);
#endif
+ } else {
+ inpkts = -1;
+ }
if (inpkts < 0) {
if (inpkts == -1) {
/* Error, rather than pcap_breakloop(). */
gboolean write_ok;
gboolean close_ok;
gboolean cfilter_error = FALSE;
- char errmsg[4096+1];
- char secondary_errmsg[4096+1];
+#define MSG_MAX_LENGTH 4096+1
+ char errmsg[MSG_MAX_LENGTH] = "";
+ char secondary_errmsg[MSG_MAX_LENGTH] = "";
int save_file_fd = -1;
+ if(capture_opts == NULL){
+ return FALSE;
+ }
/* init the loop data */
ld.go = TRUE;
if(capture_opts->save_file != NULL) {
eth_unlink(capture_opts->save_file);
g_free(capture_opts->save_file);
+ capture_opts->save_file = NULL;
}
}
capture_opts->save_file = NULL;
return 1;
}
capture_opts->has_cfilter = TRUE;
+ g_free(capture_opts->cfilter);
capture_opts->cfilter = g_strdup(optarg);
break;
case 'H': /* Hide capture info dialog box */
break;
case 'w': /* Write to capture file x */
capture_opts->saving_to_file = TRUE;
+ g_free(capture_opts->save_file);
#if defined _WIN32 && (GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 6))
/* since GLib 2.6, we need to convert filenames to utf8 for Win32 */
capture_opts->save_file = g_locale_to_utf8(optarg, -1, NULL, NULL, NULL);
# include "config.h"
#endif
+#include <stdlib.h> /* for exit() */
#include <glib.h>
#include <string.h>
int opt;
extern char *optarg;
gboolean arg_error = FALSE;
- GString *comp_info_str;
- GString *runtime_info_str;
#ifdef _WIN32
WSADATA wsaData;
SetConsoleCtrlHandler(&ConsoleCtrlHandlerRoutine, TRUE);
#endif /* _WIN32 */
- /* Assemble the compile-time version information string */
- comp_info_str = g_string_new("Compiled ");
- get_compiled_version_info(comp_info_str, NULL);
-
- /* Assemble the run-time version information string */
- runtime_info_str = g_string_new("Running ");
- get_runtime_version_info(runtime_info_str, NULL);
/* the default_log_handler will use stdout, which makes trouble in */
/* capture child mode, as it uses stdout for it's sync_pipe */
exit_main(0);
break;
case 'v': /* Show version and exit */
+ {
+ GString *comp_info_str;
+ GString *runtime_info_str;
+ /* Assemble the compile-time version information string */
+ comp_info_str = g_string_new("Compiled with ");
+ get_compiled_version_info(comp_info_str, NULL);
+
+ /* Assemble the run-time version information string */
+ runtime_info_str = g_string_new("Running ");
+ get_runtime_version_info(runtime_info_str, NULL);
show_version(comp_info_str, runtime_info_str);
+ g_string_free(comp_info_str, TRUE);
+ g_string_free(runtime_info_str, TRUE);
exit_main(0);
break;
+ }
/*** capture option specific ***/
case 'a': /* autostop criteria */
case 'b': /* Ringbuffer option */