Skip to content

Commit

Permalink
Make --help and --version information a bit more uniform.
Browse files Browse the repository at this point in the history
Have --version print the version number, the copyright information, the
"compiled with" information, the "running on/with" information, and the
compiler information.

Have --help print the version number, a one-line summary of what the
program does, a reference to http://www.wireshark.org for more
information, a Usage: line, and a list of command-line options.

This means programs doing that don't need to include version.h; that's
left up to get_ws_vcs_version_info() to do.

Change-Id: Idac641bc10e4dfd04c9914d379b3a3e0cc5ca8cb
Reviewed-on: https://code.wireshark.org/review/2794
Reviewed-by: Guy Harris <[email protected]>
  • Loading branch information
guyharris committed Jul 3, 2014
1 parent d70e56a commit b4ce352
Show file tree
Hide file tree
Showing 14 changed files with 715 additions and 242 deletions.
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,6 @@ set(SHARK_COMMON_SRC
capture-pcap-util.c
cfile.c
frame_tvbuff.c
${CMAKE_BINARY_DIR}/version.h
sync_pipe_write.c
version_info.c
)
Expand Down Expand Up @@ -1221,6 +1220,7 @@ if(BUILD_text2pcap)
set(text2pcap_CLEAN_FILES
text2pcap.c
pcapio.c
version_info.c
)
set(text2pcap_FILES
${text2pcap_CLEAN_FILES}
Expand All @@ -1245,7 +1245,7 @@ if(BUILD_mergecap)
)
set(mergecap_FILES
mergecap.c
${CMAKE_BINARY_DIR}/version.h
version_info.c
image/mergecap.rc
)
add_executable(mergecap ${mergecap_FILES})
Expand All @@ -1264,7 +1264,7 @@ if(BUILD_reordercap)
)
set(reordercap_FILES
reordercap.c
${CMAKE_BINARY_DIR}/version.h
version_info.c
image/reordercap.rc
)
add_executable(reordercap ${reordercap_FILES})
Expand All @@ -1285,6 +1285,7 @@ if(BUILD_capinfos)
)
set(capinfos_FILES
capinfos.c
version_info.c
image/capinfos.rc
)
add_executable(capinfos ${capinfos_FILES})
Expand Down Expand Up @@ -1322,6 +1323,7 @@ if(BUILD_editcap)
)
set(editcap_FILES
editcap.c
version_info.c
image/editcap.rc
)
add_executable(editcap ${editcap_FILES})
Expand All @@ -1347,7 +1349,6 @@ if(BUILD_dumpcap AND PCAP_FOUND)
${NL_LIBRARIES}
)
set(dumpcap_FILES
${CMAKE_BINARY_DIR}/version.h
capture_opts.c
capture-pcap-util.c
capture_stop_conditions.c
Expand Down
21 changes: 12 additions & 9 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ SHARK_COMMON_SRC = \

# corresponding headers
SHARK_COMMON_INCLUDES = \
version.h \
capture-pcap-util.h \
capture-pcap-util-int.h \
cfile.h \
Expand Down Expand Up @@ -107,30 +106,34 @@ rawshark_SOURCES = \

# text2pcap specifics
text2pcap_SOURCES = \
pcapio.c \
text2pcap.c \
text2pcap-scanner.l
pcapio.c \
text2pcap.c \
text2pcap-scanner.l \
version_info.c

text2pcap_INCLUDES = \
pcapio.h \
text2pcap.h

# mergecap specifics
mergecap_SOURCES = \
mergecap.c
mergecap.c \
version_info.c

# editcap specifics
editcap_SOURCES = \
editcap.c
editcap.c \
version_info.c

# reordercap specifics
reordercap_SOURCES = \
reordercap.c \
version.h
reordercap.c \
version_info.c

# capinfos specifics
capinfos_SOURCES = \
capinfos.c
capinfos.c \
version_info.c

# captype specifics
captype_SOURCES = \
Expand Down
7 changes: 0 additions & 7 deletions Makefile.nmake
Original file line number Diff line number Diff line change
Expand Up @@ -551,13 +551,6 @@ text2pcap-scanner.c : text2pcap-scanner.l
text2pcap-scanner.obj : text2pcap-scanner.c
$(CC) $(GENERATED_CFLAGS) -Fd.\ -c $?

#
# The following targets will rebuild their respective objs
# if and when version.h should change.
#
text2pcap.obj mergecap.obj capinfos.obj captype.obj editcap.obj reordercap.obj: version.h


clean-local:
rm -f $(wireshark_OBJECTS) $(tshark_OBJECTS) $(tfshark_OBJECTS) $(dumpcap_OBJECTS) $(rawshark_OBJECTS) \
$(EXECUTABLES) *.pdb *.sbr *.exe.manifest \
Expand Down
100 changes: 74 additions & 26 deletions capinfos.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,23 @@

#include <glib.h>

#ifdef HAVE_LIBZ
#include <zlib.h> /* to get the libz version number */
#endif

#include <wsutil/privileges.h>
#include <wsutil/filesystem.h>
#include <wsutil/crash_info.h>
#include <wsutil/copyright_info.h>
#include <wsutil/os_version_info.h>
#include <wsutil/ws_version_info.h>

#ifdef HAVE_PLUGINS
#include <wsutil/plugins.h>
#endif

#include "wtap.h"
#include <wsutil/report_err.h>
#include <wsutil/privileges.h>
#include <wsutil/str_util.h>
#include <wsutil/file_util.h>

Expand All @@ -102,7 +109,7 @@
#include <wsutil/unicode-utils.h>
#endif /* _WIN32 */

#include "version.h"
#include "version_info.h"

/*
* By default capinfos now continues processing
Expand Down Expand Up @@ -996,31 +1003,22 @@ process_cap_file(wtap *wth, const char *filename)
}

static void
print_version(FILE *output)
show_version(GString *comp_info_str, GString *runtime_info_str)
{
fprintf(output, "Capinfos %s"
#ifdef GITVERSION
" (" GITVERSION " from " GITBRANCH ")"
#endif
"\n", VERSION);
printf("Capinfos (Wireshark) %s\n"
"\n"
"%s"
"\n"
"%s"
"\n"
"%s",
get_ws_vcs_version_info(), get_copyright_info(),
comp_info_str->str, runtime_info_str->str);
}

static void
usage(gboolean is_error)
print_usage(FILE *output)
{
FILE *output;

if (!is_error) {
output = stdout;
/* XXX - add capinfos header info here */
}
else {
output = stderr;
}

print_version(output);
fprintf(output, "Prints various information (infos) about capture files.\n");
fprintf(output, "See http://www.wireshark.org for more information.\n");
fprintf(output, "\n");
fprintf(output, "Usage: capinfos [options] <infile> ...\n");
fprintf(output, "\n");
Expand Down Expand Up @@ -1107,9 +1105,37 @@ hash_to_str(const unsigned char *hash, size_t length, char *str) {
}
#endif /* HAVE_LIBGCRYPT */

static void
get_capinfos_compiled_info(GString *str)
{
/* LIBZ */
g_string_append(str, ", ");
#ifdef HAVE_LIBZ
g_string_append(str, "with libz ");
#ifdef ZLIB_VERSION
g_string_append(str, ZLIB_VERSION);
#else /* ZLIB_VERSION */
g_string_append(str, "(version unknown)");
#endif /* ZLIB_VERSION */
#else /* HAVE_LIBZ */
g_string_append(str, "without libz");
#endif /* HAVE_LIBZ */
}

static void
get_capinfos_runtime_info(GString *str)
{
/* zlib */
#if defined(HAVE_LIBZ) && !defined(_WIN32)
g_string_append_printf(str, ", with libz %s", zlibVersion());
#endif
}

int
main(int argc, char *argv[])
{
GString *comp_info_str;
GString *runtime_info_str;
wtap *wth;
int err;
gchar *err_info;
Expand All @@ -1132,6 +1158,22 @@ main(int argc, char *argv[])
size_t hash_bytes;
#endif

/* Assemble the compile-time version information string */
comp_info_str = g_string_new("Compiled ");
get_compiled_version_info(comp_info_str, NULL, get_capinfos_compiled_info);

/* Assemble the run-time version information string */
runtime_info_str = g_string_new("Running ");
get_runtime_version_info(runtime_info_str, get_capinfos_runtime_info);

/* Add it to the information to be reported on a crash. */
ws_add_crash_info("Capinfos (Wireshark) %s\n"
"\n"
"%s"
"\n"
"%s",
get_ws_vcs_version_info(), comp_info_str->str, runtime_info_str->str);

#ifdef _WIN32
arg_list_utf_16to8(argc, argv);
create_app_running_mutex();
Expand Down Expand Up @@ -1363,17 +1405,23 @@ main(int argc, char *argv[])
break;

case 'h':
usage(FALSE);
printf("Capinfos (Wireshark) %s\n"
"Print various information (infos) about capture files.\n"
"See http://www.wireshark.org for more information.\n",
get_ws_vcs_version_info());
print_usage(stdout);
exit(0);
break;

case 'v':
print_version(stdout);
show_version(comp_info_str, runtime_info_str);
g_string_free(comp_info_str, TRUE);
g_string_free(runtime_info_str, TRUE);
exit(0);
break;

case '?': /* Bad flag - print usage message */
usage(TRUE);
print_usage(stderr);
exit(1);
break;
}
Expand All @@ -1383,7 +1431,7 @@ main(int argc, char *argv[])
setlocale(LC_ALL, "");

if ((argc - optind) < 1) {
usage(TRUE);
print_usage(stderr);
exit(1);
}

Expand Down
66 changes: 57 additions & 9 deletions dumpcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,14 +556,12 @@ print_usage(FILE *output)
static void
show_version(GString *comp_info_str, GString *runtime_info_str)
{
printf(
"Dumpcap (Wireshark) %s\n"
"\n"
"%s\n"
"%s\n"
"%s\n"
"See http://www.wireshark.org for more information.\n",
get_ws_vcs_version_info(), get_copyright_info(), comp_info_str->str, runtime_info_str->str);
printf("Dumpcap (Wireshark) %s\n"
"\n"
"%s\n"
"%s\n"
"%s",
get_ws_vcs_version_info(), get_copyright_info(), comp_info_str->str, runtime_info_str->str);
}

/*
Expand Down Expand Up @@ -4156,6 +4154,56 @@ set_80211_channel(const char *iface, const char *opt)
return ret;
}

static void
get_dumpcap_compiled_info(GString *str)
{
/* Libpcap */
g_string_append(str, ", ");
get_compiled_pcap_version(str);

/* LIBZ */
g_string_append(str, ", ");
#ifdef HAVE_LIBZ
g_string_append(str, "with libz ");
#ifdef ZLIB_VERSION
g_string_append(str, ZLIB_VERSION);
#else /* ZLIB_VERSION */
g_string_append(str, "(version unknown)");
#endif /* ZLIB_VERSION */
#else /* HAVE_LIBZ */
g_string_append(str, "without libz");
#endif /* HAVE_LIBZ */

#ifndef _WIN32
/* This is UN*X-only. */
/* LIBCAP */
g_string_append(str, ", ");
#ifdef HAVE_LIBCAP
g_string_append(str, "with POSIX capabilities");
#ifdef _LINUX_CAPABILITY_VERSION
g_string_append(str, " (Linux)");
#endif /* _LINUX_CAPABILITY_VERSION */
#else /* HAVE_LIBCAP */
g_string_append(str, "without POSIX capabilities");
#endif /* HAVE_LIBCAP */
#endif /* _WIN32 */

#ifdef __linux__
/* This is a Linux-specific library. */
/* LIBNL */
g_string_append(str, ", ");
#if defined(HAVE_LIBNL1)
g_string_append(str, "with libnl 1");
#elif defined(HAVE_LIBNL2)
g_string_append(str, "with libnl 2");
#elif defined(HAVE_LIBNL3)
g_string_append(str, "with libnl 3");
#else /* no libnl */
g_string_append(str, "without libnl");
#endif /* libnl version */
#endif /* __linux__ */
}

static void
get_dumpcap_runtime_info(GString *str)
{
Expand Down Expand Up @@ -4216,7 +4264,7 @@ main(int argc, char *argv[])

/* Assemble the compile-time version information string */
comp_info_str = g_string_new("Compiled ");
get_compiled_version_info(comp_info_str, NULL, NULL);
get_compiled_version_info(comp_info_str, NULL, get_dumpcap_compiled_info);

/* Assemble the run-time version information string */
runtime_info_str = g_string_new("Running ");
Expand Down
Loading

0 comments on commit b4ce352

Please sign in to comment.