X-Git-Url: http://git.samba.org/?a=blobdiff_plain;f=captype.c;h=50f1823f95b83dc7a753143c8a311887bd9a4b68;hb=8dc9551e1d56290e6f7f02cc38b77e1d211fd4a5;hp=3062fb112213d95f865bb5db5ff8304317d0528c;hpb=a1b1c8bed54b1576e4f0e9e7f583844a12d142bf;p=metze%2Fwireshark%2Fwip.git diff --git a/captype.c b/captype.c index 3062fb1122..50f1823f95 100644 --- a/captype.c +++ b/captype.c @@ -23,7 +23,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "config.h" +#include #include #include @@ -32,47 +32,40 @@ #include #include -#ifdef HAVE_UNISTD_H -#include -#endif - -#ifdef HAVE_SYS_TIME_H -#include +#ifdef HAVE_GETOPT_H +#include #endif #include -#include -#include +#include + +#include #include +#include +#include +#include #ifdef HAVE_PLUGINS #include #endif -#include "wtap.h" #include -#include #include #ifdef _WIN32 #include #endif /* _WIN32 */ -#include "version.h" +#ifndef HAVE_GETOPT_LONG +#include "wsutil/wsgetopt.h" +#endif static void -usage(void) +print_usage(FILE *output) { - fprintf(stderr, "Captype %s" -#ifdef GITVERSION - " (" GITVERSION " from " GITBRANCH ")" -#endif - "\n", VERSION); - fprintf(stderr, "Prints the file types of capture files.\n"); - fprintf(stderr, "See http://www.wireshark.org for more information.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, "Usage: captype ...\n"); + fprintf(output, "\n"); + fprintf(output, "Usage: captype ...\n"); } #ifdef HAVE_PLUGINS @@ -91,16 +84,41 @@ failure_message(const char *msg_format _U_, va_list ap _U_) int main(int argc, char *argv[]) { + GString *comp_info_str; + GString *runtime_info_str; wtap *wth; int err; gchar *err_info; int i; + int opt; int overall_error_status; + static const struct option long_options[] = { + {"help", no_argument, NULL, 'h'}, + {"version", no_argument, NULL, 'v'}, + {0, 0, 0, 0 } + }; #ifdef HAVE_PLUGINS char *init_progfile_dir_error; #endif + /* Set the C-language locale to the native environment. */ + setlocale(LC_ALL, ""); + + /* Get the compile-time version information string */ + comp_info_str = get_compiled_version_info(NULL, NULL); + + /* Get the run-time version information string */ + runtime_info_str = get_runtime_version_info(NULL); + + /* Add it to the information to be reported on a crash. */ + ws_add_crash_info("Captype (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(); @@ -131,11 +149,36 @@ main(int argc, char *argv[]) } #endif - /* Set the C-language locale to the native environment. */ - setlocale(LC_ALL, ""); + /* Process the options */ + while ((opt = getopt_long(argc, argv, "hv", long_options, NULL)) !=-1) { + + switch (opt) { + + case 'h': + printf("Captype (Wireshark) %s\n" + "Print the file types of capture files.\n" + "See https://www.wireshark.org for more information.\n", + get_ws_vcs_version_info()); + print_usage(stdout); + exit(0); + break; + + case 'v': + show_version("Captype (Wireshark)", 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 */ + print_usage(stderr); + exit(1); + break; + } + } if (argc < 2) { - usage(); + print_usage(stderr); return 1; } @@ -153,14 +196,9 @@ main(int argc, char *argv[]) else { fprintf(stderr, "captype: Can't open %s: %s\n", argv[i], wtap_strerror(err)); - switch (err) { - - case WTAP_ERR_UNSUPPORTED: - case WTAP_ERR_UNSUPPORTED_ENCAP: - case WTAP_ERR_BAD_FILE: + if (err_info != NULL) { fprintf(stderr, "(%s)\n", err_info); g_free(err_info); - break; } overall_error_status = 1; /* remember that an error has occurred */ }