diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | Makefile.common | 4 | ||||
-rw-r--r-- | capture_opts.c | 4 | ||||
-rw-r--r-- | dumpcap.c | 30 | ||||
-rw-r--r-- | rawshark.c | 26 | ||||
-rw-r--r-- | tfshark.c | 31 | ||||
-rw-r--r-- | tshark.c | 32 | ||||
-rw-r--r-- | ui/gtk/main.c | 23 | ||||
-rw-r--r-- | ui/qt/main.cpp | 22 | ||||
-rw-r--r-- | wsutil/CMakeLists.txt | 2 | ||||
-rw-r--r-- | wsutil/Makefile.common | 6 | ||||
-rw-r--r-- | wsutil/clopts_common.c (renamed from clopts_common.c) | 7 | ||||
-rw-r--r-- | wsutil/clopts_common.h (renamed from clopts_common.h) | 16 | ||||
-rw-r--r-- | wsutil/cmdarg_err.c | 67 | ||||
-rw-r--r-- | wsutil/cmdarg_err.h (renamed from cmdarg_err.h) | 25 |
15 files changed, 166 insertions, 131 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 69aaa2c524..8e2cabf322 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -915,7 +915,6 @@ set(SHARK_COMMON_SRC ${PLATFORM_PCAP_SRC} capture-pcap-util.c cfile.c - clopts_common.c frame_tvbuff.c version.h sync_pipe_write.c @@ -1351,7 +1350,6 @@ if(BUILD_dumpcap AND PCAP_FOUND) capture_opts.c capture-pcap-util.c capture_stop_conditions.c - clopts_common.c conditions.c dumpcap.c pcapio.c diff --git a/Makefile.common b/Makefile.common index 34205d70c7..97e3cef31a 100644 --- a/Makefile.common +++ b/Makefile.common @@ -44,7 +44,6 @@ SHARK_COMMON_SRC = \ $(PLATFORM_PCAP_SRC) \ capture-pcap-util.c \ cfile.c \ - clopts_common.c \ frame_tvbuff.c \ sync_pipe_write.c \ version_info.c @@ -55,8 +54,6 @@ SHARK_COMMON_INCLUDES = \ capture-pcap-util.h \ capture-pcap-util-int.h \ cfile.h \ - clopts_common.h \ - cmdarg_err.h \ color.h \ file.h \ fileset.h \ @@ -172,7 +169,6 @@ dumpcap_SOURCES = \ capture_opts.c \ capture-pcap-util.c \ capture_stop_conditions.c \ - clopts_common.c \ conditions.c \ dumpcap.c \ pcapio.c \ diff --git a/capture_opts.c b/capture_opts.c index 6b17189e05..d9ec2d3e93 100644 --- a/capture_opts.c +++ b/capture_opts.c @@ -42,11 +42,11 @@ #include "capture_opts.h" #include "ringbuffer.h" -#include "clopts_common.h" -#include "cmdarg_err.h" #include <capchild/capture_ifinfo.h> #include "capture-pcap-util.h" +#include <wsutil/clopts_common.h> +#include <wsutil/cmdarg_err.h> #include <wsutil/file_util.h> static gboolean capture_opts_output_to_pipe(const char *save_file, gboolean *is_pipe); @@ -71,6 +71,7 @@ #include <zlib.h> /* to get the libz version number */ #endif +#include <wsutil/cmdarg_err.h> #include <wsutil/crash_info.h> #include <wsutil/copyright_info.h> #include <wsutil/ws_version_info.h> @@ -89,8 +90,6 @@ #endif #include "ringbuffer.h" -#include "clopts_common.h" -#include "cmdarg_err.h" #include "version_info.h" #include "capture-pcap-util.h" @@ -113,6 +112,7 @@ # include "wsutil/inet_v6defs.h" #endif +#include <wsutil/clopts_common.h> #include <wsutil/privileges.h> #include "sync_pipe.h" @@ -580,49 +580,41 @@ show_version(GString *comp_info_str, GString *runtime_info_str) /* * Report an error in command-line arguments. + * If we're a capture child, send a message back to the parent, otherwise + * just print it. */ -void -cmdarg_err(const char *fmt, ...) +static void +dumpcap_cmdarg_err(const char *fmt, va_list ap) { - va_list ap; - if (capture_child) { gchar *msg; /* Generate a 'special format' message back to parent */ - va_start(ap, fmt); msg = g_strdup_vprintf(fmt, ap); sync_pipe_errmsg_to_parent(2, msg, ""); g_free(msg); - va_end(ap); } else { - va_start(ap, fmt); fprintf(stderr, "dumpcap: "); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); - va_end(ap); } } /* * Report additional information for an error in command-line arguments. + * If we're a capture child, send a message back to the parent, otherwise + * just print it. */ -void -cmdarg_err_cont(const char *fmt, ...) +static void +dumpcap_cmdarg_err_cont(const char *fmt, va_list ap) { - va_list ap; - if (capture_child) { gchar *msg; - va_start(ap, fmt); msg = g_strdup_vprintf(fmt, ap); sync_pipe_errmsg_to_parent(2, msg, ""); g_free(msg); - va_end(ap); } else { - va_start(ap, fmt); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); - va_end(ap); } } @@ -4232,6 +4224,8 @@ main(int argc, char *argv[]) #endif GString *str; + cmdarg_err_init(dumpcap_cmdarg_err, dumpcap_cmdarg_err_cont); + /* Assemble the compile-time version information string */ comp_info_str = g_string_new("Compiled "); get_compiled_version_info(comp_info_str, NULL, NULL); diff --git a/rawshark.c b/rawshark.c index 5e0e629e15..13d8d24b78 100644 --- a/rawshark.c +++ b/rawshark.c @@ -64,6 +64,8 @@ #include <glib.h> #include <epan/epan-int.h> #include <epan/epan.h> + +#include <wsutil/cmdarg_err.h> #include <wsutil/crash_info.h> #include <wsutil/privileges.h> #include <wsutil/file_util.h> @@ -83,8 +85,6 @@ #include <epan/print.h> #include <epan/addr_resolv.h> #include "ui/util.h" -#include "clopts_common.h" -#include "cmdarg_err.h" #include "version_info.h" #include "register.h" #include "conditions.h" @@ -102,6 +102,7 @@ #include <wiretap/libpcap.h> #include <wiretap/pcap-encap.h> +#include <wsutil/clopts_common.h> #include <wsutil/ws_version_info.h> #ifdef HAVE_LIBPCAP @@ -158,6 +159,8 @@ static void open_failure_message(const char *filename, int err, static void failure_message(const char *msg_format, va_list ap); static void read_failure_message(const char *filename, int err); static void write_failure_message(const char *filename, int err); +static void rawshark_cmdarg_err(const char *fmt, va_list ap); +static void rawshark_cmdarg_err_cont(const char *fmt, va_list ap); static void protocolinfo_init(char *field); static gboolean parse_field_string_format(char *format); @@ -473,6 +476,8 @@ main(int argc, char *argv[]) static const char optstring[] = OPTSTRING_INIT; + cmdarg_err_init(rawshark_cmdarg_err, rawshark_cmdarg_err_cont); + /* Assemble the compile-time version information string */ comp_info_str = g_string_new("Compiled "); get_compiled_version_info(comp_info_str, NULL, epan_get_compiled_version_info); @@ -1732,33 +1737,24 @@ write_failure_message(const char *filename, int err) /* * Report an error in command-line arguments. */ -void -cmdarg_err(const char *fmt, ...) +static void +rawshark_cmdarg_err(const char *fmt, va_list ap) { - va_list ap; - - va_start(ap, fmt); fprintf(stderr, "rawshark: "); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); - va_end(ap); } /* * Report additional information for an error in command-line arguments. */ -void -cmdarg_err_cont(const char *fmt, ...) +static void +rawshark_cmdarg_err_cont(const char *fmt, va_list ap) { - va_list ap; - - va_start(ap, fmt); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); - va_end(ap); } - /* * Editor modelines * @@ -59,6 +59,9 @@ #include <epan/exceptions.h> #include <epan/epan-int.h> #include <epan/epan.h> + +#include <wsutil/clopts_common.h> +#include <wsutil/cmdarg_err.h> #include <wsutil/crash_info.h> #include <wsutil/privileges.h> #include <wsutil/file_util.h> @@ -81,8 +84,6 @@ #include <epan/print.h> #include <epan/addr_resolv.h> #include "ui/util.h" -#include "clopts_common.h" -#include "cmdarg_err.h" #include "version_info.h" #include "register.h" #include <epan/epan_dissect.h> @@ -792,6 +793,8 @@ main(int argc, char *argv[]) static const char optstring[] = OPTSTRING; + cmdarg_err_init(failure_message, failure_message_cont); + /* Assemble the compile-time version information string */ comp_info_str = g_string_new("Compiled "); get_compiled_version_info(comp_info_str, NULL, epan_get_compiled_version_info); @@ -2768,33 +2771,15 @@ write_failure_message(const char *filename, int err) } /* - * Report an error in command-line arguments. - */ -void -cmdarg_err(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - failure_message(fmt, ap); - va_end(ap); -} - -/* * Report additional information for an error in command-line arguments. */ -void -cmdarg_err_cont(const char *fmt, ...) +static void +failure_message_cont(const char *msg_format, va_list ap) { - va_list ap; - - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); + vfprintf(stderr, msg_format, ap); fprintf(stderr, "\n"); - va_end(ap); } - /* * Editor modelines - http://www.wireshark.org/tools/modelines.html * @@ -64,6 +64,9 @@ #include <epan/exceptions.h> #include <epan/epan-int.h> #include <epan/epan.h> + +#include <wsutil/clopts_common.h> +#include <wsutil/cmdarg_err.h> #include <wsutil/crash_info.h> #include <wsutil/privileges.h> #include <wsutil/file_util.h> @@ -88,8 +91,6 @@ #include <epan/addr_resolv.h> #include "ui/util.h" #include "ui/ui_util.h" -#include "clopts_common.h" -#include "cmdarg_err.h" #include "version_info.h" #include "register.h" #include <epan/epan_dissect.h> @@ -212,6 +213,7 @@ static void open_failure_message(const char *filename, int err, static void failure_message(const char *msg_format, va_list ap); static void read_failure_message(const char *filename, int err); static void write_failure_message(const char *filename, int err); +static void failure_message_cont(const char *msg_format, va_list ap); capture_file cfile; @@ -1009,6 +1011,8 @@ main(int argc, char *argv[]) } #endif + cmdarg_err_init(failure_message, failure_message_cont); + /* Assemble the compile-time version information string */ comp_info_str = g_string_new("Compiled "); get_compiled_version_info(comp_info_str, NULL, epan_get_compiled_version_info); @@ -4315,33 +4319,15 @@ write_failure_message(const char *filename, int err) } /* - * Report an error in command-line arguments. - */ -void -cmdarg_err(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - failure_message(fmt, ap); - va_end(ap); -} - -/* * Report additional information for an error in command-line arguments. */ -void -cmdarg_err_cont(const char *fmt, ...) +static void +failure_message_cont(const char *msg_format, va_list ap) { - va_list ap; - - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); + vfprintf(stderr, msg_format, ap); fprintf(stderr, "\n"); - va_end(ap); } - /* * Editor modelines - http://www.wireshark.org/tools/modelines.html * diff --git a/ui/gtk/main.c b/ui/gtk/main.c index 5c54337cb6..ff5bf274b3 100644 --- a/ui/gtk/main.c +++ b/ui/gtk/main.c @@ -60,6 +60,7 @@ #include <portaudio.h> #endif /* HAVE_LIBPORTAUDIO */ +#include <wsutil/clopts_common.h> #include <wsutil/crash_info.h> #include <wsutil/filesystem.h> #include <wsutil/file_util.h> @@ -92,6 +93,7 @@ #include <epan/print.h> #include <epan/timestamp.h> +#include <wsutil/cmdarg_err.h> #include <wsutil/plugins.h> /* general (not GTK specific) */ @@ -104,8 +106,6 @@ #include "../register.h" #include "../ringbuffer.h" #include "ui/util.h" -#include "../clopts_common.h" -#include "../cmdarg_err.h" #include "../version_info.h" #include "../log.h" @@ -1279,19 +1279,17 @@ show_version(void) /* * Report an error in command-line arguments. * Creates a console on Windows. + * XXX - pop this up in a window of some sort on UNIX+X11 if the controlling + * terminal isn't the standard error? */ -void -cmdarg_err(const char *fmt, ...) +static void +wireshark_cmdarg_err(const char *fmt, va_list ap) { - va_list ap; - #ifdef _WIN32 create_console(); #endif fprintf(stderr, "wireshark: "); - va_start(ap, fmt); vfprintf(stderr, fmt, ap); - va_end(ap); fprintf(stderr, "\n"); } @@ -1301,18 +1299,14 @@ cmdarg_err(const char *fmt, ...) * XXX - pop this up in a window of some sort on UNIX+X11 if the controlling * terminal isn't the standard error? */ -void -cmdarg_err_cont(const char *fmt, ...) +static void +wireshark_cmdarg_err_cont(const char *fmt, va_list ap) { - va_list ap; - #ifdef _WIN32 create_console(); #endif - va_start(ap, fmt); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); - va_end(ap); } /* @@ -2184,6 +2178,7 @@ main(int argc, char *argv[]) static const char optstring[] = OPTSTRING; + cmdarg_err_init(wireshark_cmdarg_err, wireshark_cmdarg_err_cont); /* Set the C-language locale to the native environment. */ setlocale(LC_ALL, ""); diff --git a/ui/qt/main.cpp b/ui/qt/main.cpp index d14e6226f7..ef4704bc4f 100644 --- a/ui/qt/main.cpp +++ b/ui/qt/main.cpp @@ -41,6 +41,8 @@ # include <getopt.h> #endif +#include <wsutil/clopts_common.h> +#include <wsutil/cmdarg_err.h> #include <wsutil/crash_info.h> #include <wsutil/filesystem.h> #include <wsutil/file_util.h> @@ -88,8 +90,6 @@ #include "register.h" #include "ringbuffer.h" #include "ui/util.h" -#include "clopts_common.h" -#include "cmdarg_err.h" #include "version_info.h" #include "log.h" @@ -317,18 +317,14 @@ show_version(void) * Creates a console on Windows. */ // xxx copied from ../gtk/main.c -void -cmdarg_err(const char *fmt, ...) +static void +wireshark_cmdarg_err(const char *fmt, va_list ap) { - va_list ap; - #ifdef _WIN32 create_console(); #endif fprintf(stderr, "wireshark: "); - va_start(ap, fmt); vfprintf(stderr, fmt, ap); - va_end(ap); fprintf(stderr, "\n"); } @@ -339,18 +335,14 @@ cmdarg_err(const char *fmt, ...) * terminal isn't the standard error? */ // xxx copied from ../gtk/main.c -void -cmdarg_err_cont(const char *fmt, ...) +static void +wireshark_cmdarg_err_cont(const char *fmt, va_list ap) { - va_list ap; - #ifdef _WIN32 create_console(); #endif - va_start(ap, fmt); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); - va_end(ap); } static void @@ -493,6 +485,8 @@ int main(int argc, char *argv[]) e_prefs *prefs_p; GLogLevelFlags log_flags; + cmdarg_err_init(wireshark_cmdarg_err, wireshark_cmdarg_err_cont); + #ifdef _WIN32 create_app_running_mutex(); #endif diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt index 0157e74785..d8e2f04de1 100644 --- a/wsutil/CMakeLists.txt +++ b/wsutil/CMakeLists.txt @@ -45,6 +45,8 @@ set(WSUTIL_FILES base64.c bitswap.c cfutils.c + clopts_common.c + cmdarg_err.c compiler_info.c copyright_info.c cpu_info.c diff --git a/wsutil/Makefile.common b/wsutil/Makefile.common index 4bb8dea86b..2c0595c94e 100644 --- a/wsutil/Makefile.common +++ b/wsutil/Makefile.common @@ -33,6 +33,8 @@ LIBWSUTIL_SRC = \ base64.c \ bitswap.c \ cfutils.c \ + clopts_common.c \ + cmdarg_err.c \ compiler_info.c \ copyright_info.c \ cpu_info.c \ @@ -79,8 +81,10 @@ LIBWSUTIL_INCLUDES = \ base64.h \ bits_ctz.h \ bits_count_ones.h \ - bitswap.h \ + bitswap.h \ cfutils.h \ + clopts_common.h \ + cmdarg_err.h \ compiler_info.h \ copyright_info.h \ cpu_info.h \ diff --git a/clopts_common.c b/wsutil/clopts_common.c index 1ffcdedbc9..8b1878758b 100644 --- a/clopts_common.c +++ b/wsutil/clopts_common.c @@ -1,5 +1,5 @@ /* clopts_common.c - * Handle command-line arguments common to Wireshark and TShark + * Handle command-line arguments common to various programs * * Wireshark - Network traffic analyzer * By Gerald Combs <gerald@wireshark.org> @@ -26,8 +26,9 @@ #include <string.h> #include <stdlib.h> -#include "clopts_common.h" -#include "cmdarg_err.h" +#include <wsutil/cmdarg_err.h> + +#include <wsutil/clopts_common.h> int get_natural_int(const char *string, const char *name) diff --git a/clopts_common.h b/wsutil/clopts_common.h index e98d7b4986..c409e8957a 100644 --- a/clopts_common.h +++ b/wsutil/clopts_common.h @@ -1,5 +1,5 @@ /* clopts_common.h - * Handle command-line arguments common to Wireshark and TShark + * Handle command-line arguments common to various programs * * Wireshark - Network traffic analyzer * By Gerald Combs <gerald@wireshark.org> @@ -20,19 +20,23 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef __PROTO_DUMPOPTS_H__ -#define __PROTO_DUMPOPTS_H__ +#ifndef __WSUTIL_CLOPTS_COMMON_H__ +#define __WSUTIL_CLOPTS_COMMON_H__ + +#include "ws_symbol_export.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ -int get_natural_int(const char *string, const char *name); +WS_DLL_PUBLIC int +get_natural_int(const char *string, const char *name); -int get_positive_int(const char *string, const char *name); +WS_DLL_PUBLIC int +get_positive_int(const char *string, const char *name); #ifdef __cplusplus } #endif /* __cplusplus */ -#endif /* __PROTO_DUMPOPTS_H__ */ +#endif /* __WSUTIL_CLOPTS_COMMON_H__ */ diff --git a/wsutil/cmdarg_err.c b/wsutil/cmdarg_err.c new file mode 100644 index 0000000000..7dd2fa23c6 --- /dev/null +++ b/wsutil/cmdarg_err.c @@ -0,0 +1,67 @@ +/* cmdarg_err.c + * Routines to report command-line argument errors. + * + * 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. + */ + +#include "config.h" + +#include <stdio.h> + +#include <wsutil/cmdarg_err.h> + +static void (*print_err)(const char *, va_list ap); +static void (*print_err_cont)(const char *, va_list ap); + +/* + * Set the reporting functions for error messages. + */ +void +cmdarg_err_init(void (*err)(const char *, va_list), + void (*err_cont)(const char *, va_list)) +{ + print_err = err; + print_err_cont = err_cont; +} + +/* + * Report an error in command-line arguments. + */ +void +cmdarg_err(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + print_err(fmt, ap); + va_end(ap); +} + +/* + * Report additional information for an error in command-line arguments. + */ +void +cmdarg_err_cont(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + print_err_cont(fmt, ap); + va_end(ap); +} diff --git a/cmdarg_err.h b/wsutil/cmdarg_err.h index b4d639f8f1..169c893b9f 100644 --- a/cmdarg_err.h +++ b/wsutil/cmdarg_err.h @@ -1,5 +1,5 @@ /* cmdarg_err.h - * Declarations of routines to report command-line errors. + * Declarations of routines to report command-line argument errors. * * Wireshark - Network traffic analyzer * By Gerald Combs <gerald@wireshark.org> @@ -20,29 +20,42 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef __CMDARG_ERR_H__ -#define __CMDARG_ERR_H__ +#ifndef __WSUTIL_CMDARG_ERR_H__ +#define __WSUTIL_CMDARG_ERR_H__ + +#include <stdarg.h> #include <glib.h> +#include "ws_symbol_export.h" + #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /* + * Set the reporting functions for error messages. + */ +WS_DLL_PUBLIC void +cmdarg_err_init(void (*err)(const char *, va_list), + void (*err_cont)(const char *, va_list)); + +/* * Report an error in command-line arguments. */ -extern void cmdarg_err(const char *fmt, ...) +WS_DLL_PUBLIC void +cmdarg_err(const char *fmt, ...) G_GNUC_PRINTF(1, 2); /* * Report additional information for an error in command-line arguments. */ -extern void cmdarg_err_cont(const char *fmt, ...) +WS_DLL_PUBLIC void +cmdarg_err_cont(const char *fmt, ...) G_GNUC_PRINTF(1, 2); #ifdef __cplusplus } #endif /* __cplusplus */ -#endif /* __CMDARG_ERR_H__ */ +#endif /* __WSUTIL_CMDARG_ERR_H__ */ |