diff options
author | Hadriel Kaplan <hadrielk@yahoo.com> | 2014-03-04 06:19:01 -0500 |
---|---|---|
committer | Alexis La Goutte <alexis.lagoutte@gmail.com> | 2014-03-05 18:38:05 +0000 |
commit | 041f844d7228d1ac41cf9b5e4629d7b7adec0e1f (patch) | |
tree | 12397039ed87f6584903638f7783b26e04311d84 /tshark.c | |
parent | f1f06014c41b195b3695827319cf43f4e39becca (diff) |
Add command-line arg for input file format for tshark/wireshark
Now that we have the ability to choose input file format type
in the GUI, we might as well have it in the command-line too.
Plus it would help me in test-stuies if we had a commandline.
So I've added a '-X read_format:Foo' for this. Using just
'-X read_format:', or with a bad name, will make it print out
the full list (in tshark); just like the '-F' does for output
file formats.
Note: I am *not* putting in code for Win32 GUI,
because I can't compile that and I wouldn't have even
done the GTK one if I could compile Qt originally. (I don't think we need
to add any more features to GTK or Win32, just Qt from now on,
right?)
Change-Id: I2fe6481d186f63bd2303b9e591edf397a2e14b64
Reviewed-on: https://code.wireshark.org/review/493
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Diffstat (limited to 'tshark.c')
-rw-r--r-- | tshark.c | 35 |
1 files changed, 34 insertions, 1 deletions
@@ -245,6 +245,28 @@ list_capture_types(void) { } static void +list_read_capture_types(void) { + int i; + struct string_elem *captypes; + GSList *list = NULL; + const char *magic = "Magic-value-based"; + const char *heuristic = "Heuristics-based"; + + /* this is a hack, but WTAP_NUM_FILE_TYPES_SUBTYPES is always >= number of open routines so we're safe */ + captypes = g_new(struct string_elem, WTAP_NUM_FILE_TYPES_SUBTYPES); + + fprintf(stderr, "tshark: The available read file types for the \"-X read_format:\" option are:\n"); + for (i = 0; open_routines[i].name != NULL; i++) { + captypes[i].sstr = open_routines[i].name; + captypes[i].lstr = (open_routines[i].type == OPEN_INFO_MAGIC) ? magic : heuristic; + list = g_slist_insert_sorted(list, &captypes[i], string_compare); + } + g_slist_foreach(list, string_elem_print, NULL); + g_slist_free(list); + g_free(captypes); +} + +static void print_usage(gboolean print_ver) { FILE *output; @@ -930,6 +952,7 @@ main(int argc, char *argv[]) volatile int out_file_type = WTAP_FILE_TYPE_SUBTYPE_PCAP; #endif volatile gboolean out_file_name_res = FALSE; + volatile int in_file_type = WTAP_TYPE_AUTO; gchar *volatile cf_name = NULL; gchar *rfilter = NULL; gchar *dfilter = NULL; @@ -1894,6 +1917,16 @@ main(int argc, char *argv[]) } #endif + if (ex_opt_count("read_format") > 0) { + const gchar* name = ex_opt_get_next("read_format"); + in_file_type = open_info_name_to_type(name); + if (in_file_type == WTAP_TYPE_AUTO) { + cmdarg_err("\"%s\" isn't a valid read file format type", name? name : ""); + list_read_capture_types(); + return 1; + } + } + /* disabled protocols as per configuration file */ if (gdp_path == NULL && dp_path == NULL) { set_disabled_protos_list(); @@ -1999,7 +2032,7 @@ main(int argc, char *argv[]) relinquish_special_privs_perm(); print_current_user(); - if (cf_open(&cfile, cf_name, WTAP_TYPE_AUTO, FALSE, &err) != CF_OK) { + if (cf_open(&cfile, cf_name, in_file_type, FALSE, &err) != CF_OK) { epan_cleanup(); return 2; } |