summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2013-04-25 05:47:11 +0000
committerGuy Harris <guy@alum.mit.edu>2013-04-25 05:47:11 +0000
commit39779a7bee18c7489079154d8d72350fb0d74f0b (patch)
tree3eebb55d146d2cfc2e74d85ff496afa0c6dc0327
parent35d3fa75bed0add8fbfca7069327a3942552045c (diff)
downloadwireshark-39779a7bee18c7489079154d8d72350fb0d74f0b.tar.gz
Send the output of the -D and -L options to the standard output rather
than the standard error. In Wireshark on Windows, create a console before doing so and destroy it before exiting. Don't do that in TShark or dumpcap, as those are console-mode programs on Windows. This should fix bug 8609 and still allow "wireshark -D" and "wireshark -L" to work when the standard output isn't redirected. svn path=/trunk/; revision=49025
-rw-r--r--Makefile.common1
-rw-r--r--capture_opts.c23
-rw-r--r--console_io.h51
-rw-r--r--dumpcap.c21
-rw-r--r--tshark.c21
-rw-r--r--ui/gtk/main.c73
-rw-r--r--ui/qt/main.cpp81
-rw-r--r--ui/win32/console_win32.c1
8 files changed, 79 insertions, 193 deletions
diff --git a/Makefile.common b/Makefile.common
index 90283361bb..e320a7aa5d 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -71,7 +71,6 @@ WIRESHARK_COMMON_INCLUDES = \
cfutils.h \
clopts_common.h \
cmdarg_err.h \
- console_io.h \
color.h \
disabled_protos.h \
file.h \
diff --git a/capture_opts.c b/capture_opts.c
index e3d6b5a246..c37fed6b90 100644
--- a/capture_opts.c
+++ b/capture_opts.c
@@ -45,7 +45,6 @@
#include "capture_opts.h"
#include "ringbuffer.h"
#include "clopts_common.h"
-#include "console_io.h"
#include "cmdarg_err.h"
#include "capture_ifinfo.h"
@@ -845,19 +844,19 @@ capture_opts_print_if_capabilities(if_capabilities_t *caps, char *name,
data_link_info_t *data_link_info;
if (caps->can_set_rfmon)
- fprintf_stderr("Data link types of interface %s when %sin monitor mode (use option -y to set):\n",
- name, monitor_mode ? "" : "not ");
+ printf("Data link types of interface %s when %sin monitor mode (use option -y to set):\n",
+ name, monitor_mode ? "" : "not ");
else
- fprintf_stderr("Data link types of interface %s (use option -y to set):\n", name);
+ printf("Data link types of interface %s (use option -y to set):\n", name);
for (lt_entry = caps->data_link_types; lt_entry != NULL;
lt_entry = g_list_next(lt_entry)) {
data_link_info = (data_link_info_t *)lt_entry->data;
- fprintf_stderr(" %s", data_link_info->name);
+ printf(" %s", data_link_info->name);
if (data_link_info->description != NULL)
- fprintf_stderr(" (%s)", data_link_info->description);
+ printf(" (%s)", data_link_info->description);
else
- fprintf_stderr(" (not supported)");
- fprintf_stderr("\n");
+ printf(" (not supported)");
+ printf("\n");
}
}
@@ -873,17 +872,17 @@ capture_opts_print_interfaces(GList *if_list)
for (if_entry = g_list_first(if_list); if_entry != NULL;
if_entry = g_list_next(if_entry)) {
if_info = (if_info_t *)if_entry->data;
- fprintf_stderr("%d. %s", i++, if_info->name);
+ printf("%d. %s", i++, if_info->name);
/* Print the interface friendly name, if it exists;
if not fall back to vendor description, if it exists. */
if (if_info->friendly_name != NULL){
- fprintf_stderr(" (%s)", if_info->friendly_name);
+ printf(" (%s)", if_info->friendly_name);
} else {
if (if_info->vendor_description != NULL)
- fprintf_stderr(" (%s)", if_info->vendor_description);
+ printf(" (%s)", if_info->vendor_description);
}
- fprintf_stderr("\n");
+ printf("\n");
}
}
diff --git a/console_io.h b/console_io.h
deleted file mode 100644
index 9d038d4720..0000000000
--- a/console_io.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/* console_io.h
- * Declarations of routines to print to the standard error, and, in
- * GUI programs on Windows, to create a console in which to display
- * the standard error.
- *
- * $Id$
- *
- * Wireshark - Network traffic analyzer
- * By Gerald Combs <gerald@wireshark.org>
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#ifndef __CONSOLE_IO_H__
-#define __CONSOLE_IO_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-/*
- * Print to the standard error. On Windows, create a console for the
- * standard error to show up on, if necessary.
- * XXX - pop this up in a window of some sort on UNIX+X11 if the controlling
- * terminal isn't the standard error?
- */
-extern void
-vfprintf_stderr(const char *fmt, va_list ap);
-
-extern void
-fprintf_stderr(const char *fmt, ...)
- G_GNUC_PRINTF(1, 2);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* __CMDARG_ERR_H__ */
diff --git a/dumpcap.c b/dumpcap.c
index d56bb92b81..e52c2660ec 100644
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -82,7 +82,6 @@
#include "ringbuffer.h"
#include "clopts_common.h"
-#include "console_io.h"
#include "cmdarg_err.h"
#include "version_info.h"
@@ -527,26 +526,6 @@ show_version(GString *comp_info_str, GString *runtime_info_str)
}
/*
- * Print to the standard error. This is a command-line tool, so there's
- * no need to pop up a console.
- */
-void
-vfprintf_stderr(const char *fmt, va_list ap)
-{
- vfprintf(stderr, fmt, ap);
-}
-
-void
-fprintf_stderr(const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- vfprintf_stderr(fmt, ap);
- va_end(ap);
-}
-
-/*
* Report an error in command-line arguments.
*/
void
diff --git a/tshark.c b/tshark.c
index 02895135d4..2481db9817 100644
--- a/tshark.c
+++ b/tshark.c
@@ -71,7 +71,6 @@
#include <epan/addr_resolv.h>
#include "ui/util.h"
#include "clopts_common.h"
-#include "console_io.h"
#include "cmdarg_err.h"
#include "version_info.h"
#include <epan/plugins.h>
@@ -3977,26 +3976,6 @@ write_failure_message(const char *filename, int err)
}
/*
- * Print to the standard error. This is a command-line tool, so there's
- * no need to pop up a console.
- */
-void
-vfprintf_stderr(const char *fmt, va_list ap)
-{
- vfprintf(stderr, fmt, ap);
-}
-
-void
-fprintf_stderr(const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- vfprintf_stderr(fmt, ap);
- va_end(ap);
-}
-
-/*
* Report an error in command-line arguments.
*/
void
diff --git a/ui/gtk/main.c b/ui/gtk/main.c
index 5b82f1832d..f88f5fd6b6 100644
--- a/ui/gtk/main.c
+++ b/ui/gtk/main.c
@@ -50,8 +50,10 @@
#ifdef _WIN32 /* Needed for console I/O */
#if _MSC_VER < 1500
/* AttachConsole() needs this #define! */
+/* But we're not calling it from here any more; do we need this? */
#define _WIN32_WINNT 0x0501
#endif
+
#include <fcntl.h>
#include <conio.h>
#include <ui/win32/console_win32.h>
@@ -1225,10 +1227,6 @@ print_usage(gboolean print_ver) {
static void
show_version(void)
{
-#ifdef _WIN32
- create_console();
-#endif
-
printf(PACKAGE " " VERSION "%s\n"
"\n"
"%s"
@@ -1238,35 +1236,6 @@ show_version(void)
"%s",
wireshark_svnversion, get_copyright_info(), comp_info_str->str,
runtime_info_str->str);
-
-#ifdef _WIN32
- destroy_console();
-#endif
-}
-
-/*
- * Print to the standard error. On Windows, create a console for the
- * standard error to show up on, if necessary.
- * XXX - pop this up in a window of some sort on UNIX+X11 if the controlling
- * terminal isn't the standard error?
- */
-void
-vfprintf_stderr(const char *fmt, va_list ap)
-{
-#ifdef _WIN32
- create_console();
-#endif
- vfprintf(stderr, fmt, ap);
-}
-
-void
-fprintf_stderr(const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- vfprintf_stderr(fmt, ap);
- va_end(ap);
}
/*
@@ -1278,11 +1247,14 @@ cmdarg_err(const char *fmt, ...)
{
va_list ap;
- fprintf_stderr("wireshark: ");
+#ifdef _WIN32
+ create_console();
+#endif
+ fprintf(stderr, "wireshark: ");
va_start(ap, fmt);
- vfprintf_stderr(fmt, ap);
+ vfprintf(stderr, fmt, ap);
va_end(ap);
- fprintf_stderr("\n");
+ fprintf(stderr, "\n");
}
/*
@@ -1296,9 +1268,12 @@ cmdarg_err_cont(const char *fmt, ...)
{
va_list ap;
+#ifdef _WIN32
+ create_console();
+#endif
va_start(ap, fmt);
- vfprintf_stderr(fmt, ap);
- fprintf_stderr("\n");
+ vfprintf(stderr, fmt, ap);
+ fprintf(stderr, "\n");
va_end(ap);
}
@@ -2333,13 +2308,19 @@ main(int argc, char *argv[])
}
exit(2);
}
+#ifdef _WIN32
+ create_console();
+#endif /* _WIN32 */
capture_opts_print_interfaces(if_list);
free_interface_list(if_list);
+#ifdef _WIN32
+ destroy_console();
+#endif /* _WIN32 */
exit(0);
-#else
+#else /* HAVE_LIBPCAP */
capture_option_specified = TRUE;
arg_error = TRUE;
-#endif
+#endif /* HAVE_LIBPCAP */
break;
case 'h': /* Print help and exit */
print_usage(TRUE);
@@ -2359,7 +2340,13 @@ main(int argc, char *argv[])
}
break;
case 'v': /* Show version and exit */
+#ifdef _WIN32
+ create_console();
+#endif
show_version();
+#ifdef _WIN32
+ destroy_console();
+#endif
exit(0);
break;
case 'X':
@@ -2892,11 +2879,17 @@ main(int argc, char *argv[])
cmdarg_err("The capture device \"%s\" has no data link types.", device.name);
exit(2);
}
+#ifdef _WIN32
+ create_console();
+#endif /* _WIN32 */
#if defined(HAVE_PCAP_CREATE)
capture_opts_print_if_capabilities(caps, device.name, device.monitor_mode_supported);
#else
capture_opts_print_if_capabilities(caps, device.name, FALSE);
#endif
+#ifdef _WIN32
+ destroy_console();
+#endif /* _WIN32 */
free_if_capabilities(caps);
}
}
diff --git a/ui/qt/main.cpp b/ui/qt/main.cpp
index 6197bc89c1..97bbef5db8 100644
--- a/ui/qt/main.cpp
+++ b/ui/qt/main.cpp
@@ -75,7 +75,6 @@
#include "ringbuffer.h"
#include "ui/util.h"
#include "clopts_common.h"
-#include "console_io.h"
#include "cmdarg_err.h"
#include "version_info.h"
#include "merge.h"
@@ -293,10 +292,6 @@ print_usage(gboolean print_ver) {
static void
show_version(void)
{
-#ifdef _WIN32
- create_console();
-#endif
-
printf(PACKAGE " " VERSION "%s\n"
"\n"
"%s"
@@ -306,36 +301,6 @@ show_version(void)
"%s",
wireshark_svnversion, get_copyright_info(), comp_info_str->str,
runtime_info_str->str);
-
-#ifdef _WIN32
- destroy_console();
-#endif
-}
-
-/*
- * Print to the standard error. On Windows, create a console for the
- * standard error to show up on, if necessary.
- * XXX - pop this up in a window of some sort on UNIX+X11 if the controlling
- * terminal isn't the standard error?
- */
-// xxx copied from ../gtk/main.c
-void
-vfprintf_stderr(const char *fmt, va_list ap)
-{
-#ifdef _WIN32
- create_console();
-#endif
- vfprintf(stderr, fmt, ap);
-}
-
-void
-fprintf_stderr(const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- vfprintf_stderr(fmt, ap);
- va_end(ap);
}
/*
@@ -348,11 +313,14 @@ cmdarg_err(const char *fmt, ...)
{
va_list ap;
- fprintf_stderr("wireshark: ");
+#ifdef _WIN32
+ create_console();
+#endif
+ fprintf(stderr, "wireshark: ");
va_start(ap, fmt);
- vfprintf_stderr(fmt, ap);
+ vfprintf(stderr, fmt, ap);
va_end(ap);
- fprintf_stderr("\n");
+ fprintf(stderr, "\n");
}
/*
@@ -367,9 +335,12 @@ cmdarg_err_cont(const char *fmt, ...)
{
va_list ap;
+#ifdef _WIN32
+ create_console();
+#endif
va_start(ap, fmt);
- vfprintf_stderr(fmt, ap);
- fprintf_stderr("\n");
+ vfprintf(stderr, fmt, ap);
+ fprintf(stderr, "\n");
va_end(ap);
}
@@ -725,13 +696,19 @@ int main(int argc, char *argv[])
}
exit(2);
}
+#ifdef _WIN32
+ create_console();
+#endif /* _WIN32 */
capture_opts_print_interfaces(if_list);
free_interface_list(if_list);
+#ifdef _WIN32
+ destroy_console();
+#endif /* _WIN32 */
exit(0);
-#else
+#else /* HAVE_LIBPCAP */
capture_option_specified = TRUE;
arg_error = TRUE;
-#endif
+#endif /* HAVE_LIBPCAP */
break;
case 'h': /* Print help and exit */
print_usage(TRUE);
@@ -751,15 +728,21 @@ int main(int argc, char *argv[])
}
break;
case 'v': /* Show version and exit */
+#ifdef _WIN32
+ create_console();
+#endif
show_version();
+#ifdef _WIN32
+ destroy_console();
+#endif
exit(0);
break;
case 'X':
/*
- * Extension command line options have to be processed before
- * we call epan_init() as they are supposed to be used by dissectors
- * or taps very early in the registration process.
- */
+ * Extension command line options have to be processed before
+ * we call epan_init() as they are supposed to be used by dissectors
+ * or taps very early in the registration process.
+ */
ex_opt_add(optarg);
break;
case '?': /* Ignore errors - the "real" scan will catch them. */
@@ -954,10 +937,16 @@ int main(int argc, char *argv[])
// exit(2);
// }
//#if defined(HAVE_PCAP_CREATE)
+//#ifdef _WIN32
+// create_console();
+//#endif /* _WIN32 */
// capture_opts_print_if_capabilities(caps, device.name, device.monitor_mode_supported);
//#else
// capture_opts_print_if_capabilities(caps, device.name, FALSE);
//#endif
+//#ifdef _WIN32
+// destroy_console();
+//#endif /* _WIN32 */
// free_if_capabilities(caps);
// }
// }
diff --git a/ui/win32/console_win32.c b/ui/win32/console_win32.c
index 58184e2f35..d240a56ce2 100644
--- a/ui/win32/console_win32.c
+++ b/ui/win32/console_win32.c
@@ -34,7 +34,6 @@
#include <wsutil/file_util.h>
#include "console_win32.h"
-#include "../../console_io.h"
#if _MSC_VER < 1500
/* AttachConsole() needs this #define! */