Send the output of the -D and -L options to the standard output rather
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 25 Apr 2013 05:47:11 +0000 (05:47 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 25 Apr 2013 05:47:11 +0000 (05:47 +0000)
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.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@49025 f5534014-38df-0310-8fa8-9805f1628bb7

Makefile.common
capture_opts.c
console_io.h [deleted file]
dumpcap.c
tshark.c
ui/gtk/main.c
ui/qt/main.cpp
ui/win32/console_win32.c

index 90283361bbe7a1935cbdc85ba87e91eae30e4521..e320a7aa5d0bae096cfb9cfb3f62e16bd4b4d088 100644 (file)
@@ -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                  \
index e3d6b5a246ca47fb97565cf0b2ea21e59aac9d26..c37fed6b90b6fe5066c97d3a279e85973ce89b2d 100644 (file)
@@ -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 (file)
index 9d038d4..0000000
+++ /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__ */
index d56bb92b817abddd9c2d58b8d67d937de4b31526..e52c2660ec0adf44f3bff63a0e3156fa9f508179 100644 (file)
--- 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"
 
@@ -526,26 +525,6 @@ show_version(GString *comp_info_str, GString *runtime_info_str)
         wireshark_svnversion, get_copyright_info(), comp_info_str->str, runtime_info_str->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.
  */
index 02895135d4db8c4fb0630c4bc43a000312f7409b..2481db9817c0177fcaf52d5a8090b0e240ea2ab8 100644 (file)
--- 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>
@@ -3976,26 +3975,6 @@ write_failure_message(const char *filename, int err)
           filename, g_strerror(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.
  */
index 5b82f1832de43f078b1a483842951b649b8aabfb..f88f5fd6b6c3065b5cfeb19b69a11792738c19a9 100644 (file)
 #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);
       }
     }
index 6197bc89c1e072e617338548822c59c7dbf978eb..97bbef5db8d377c0241d66511278d066dba08c21 100644 (file)
@@ -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);
 //      }
 //    }
index 58184e2f35ac245284746b4b4d910a278307c7b7..d240a56ce20f57639db6145829bab9fd90f8a30b 100644 (file)
@@ -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! */