#endif
+/*#define DEBUG_DUMPCAP*/
+
#ifndef _WIN32
static const char *sync_pipe_signame(int);
#endif
* if that string is constructed by gluing those strings together.
*/
static gchar *
-protect_arg (gchar *argv)
+protect_arg (const gchar *argv)
{
gchar *new_arg;
- gchar *p = argv;
+ const gchar *p = argv;
gchar *q;
gint len = 0;
gboolean need_dblquotes = FALSE;
else if (*p == '"')
len++;
else if (*p == '\\') {
- gchar *pp = p;
+ const gchar *pp = p;
while (*pp && *pp == '\\')
pp++;
if (*p == '"')
*q++ = '\\';
else if (*p == '\\') {
- gchar *pp = p;
+ const gchar *pp = p;
while (*pp && *pp == '\\')
pp++;
char sautostop_duration[ARGV_NUMBER_LEN];
#ifdef _WIN32
char buffer_size[ARGV_NUMBER_LEN];
- char *filterstring;
- char *savefilestring;
HANDLE sync_pipe_read; /* pipe used to send messages from child to parent */
HANDLE sync_pipe_write; /* pipe used to send messages from child to parent */
HANDLE signal_pipe_read; /* pipe used to send messages from parent to child (currently only stop) */
argv = sync_pipe_add_arg(argv, &argc, buffer_size);
#endif
- if (capture_opts->cfilter) {
+ if (capture_opts->cfilter != NULL && strlen(capture_opts->cfilter) != 0) {
argv = sync_pipe_add_arg(argv, &argc, "-f");
argv = sync_pipe_add_arg(argv, &argc, capture_opts->cfilter);
}
/*si.hStdError = (HANDLE) _get_osfhandle(2);*/
#endif
- /*
- * XXX - is this necessary? argv[0] should be the full path of
- * dumpcap.
- */
- quoted_arg = protect_arg(exename);
- g_string_append(args, quoted_arg);
- g_free(quoted_arg);
-
/* convert args array into a single string */
/* XXX - could change sync_pipe_add_arg() instead */
/* there is a drawback here: the length is internally limited to 1024 bytes */
for(i=0; argv[i] != 0; i++) {
- g_string_append_c(args, ' ');
+ if(i != 0) g_string_append_c(args, ' '); /* don't prepend a space before the path!!! */
quoted_arg = protect_arg(argv[i]);
g_string_append(args, quoted_arg);
g_free(quoted_arg);
/* call dumpcap */
if(!CreateProcess(NULL, args->str, NULL, NULL, TRUE,
CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi)) {
- g_error("couldn't open dumpcap.exe!");
+ g_warning("Couldn't open dumpcap (Error: %u): %s", GetLastError(), args->str);
+ capture_opts->fork_child = -1;
+ } else {
+ capture_opts->fork_child = (int) pi.hProcess;
}
- capture_opts->fork_child = (int) pi.hProcess;
g_string_free(args, TRUE);
/* associate the operating system filehandle to a C run-time file handle */
/* associate the operating system filehandle to a C run-time file handle */
capture_opts->signal_pipe_write_fd = _open_osfhandle( (long) signal_pipe_write, _O_BINARY);
- if (filterstring) {
- g_free(filterstring);
- }
- if(savefilestring) {
- g_free(savefilestring);
- }
-
/* child own's the read side now, close our handle */
CloseHandle(signal_pipe_read);
#else /* _WIN32 */