/* The line separator used between packets, changeable via the -S option */
static const char *separator = "";
-static int load_cap_file(capture_file *, int, gint64);
+static gboolean process_file(capture_file *, int, gint64);
static gboolean process_packet_single_pass(capture_file *cf,
epan_dissect_t *edt, gint64 offset, struct wtap_pkthdr *whdr,
const guchar *pd, guint tap_flags);
gboolean arg_error = FALSE;
int err;
+ volatile gboolean success;
volatile int exit_status = 0;
gboolean quiet = FALSE;
gchar *volatile cf_name = NULL;
line_buffered = TRUE;
break;
case 'o': /* Override preference from command line */
- switch (prefs_set_pref(optarg)) {
+ {
+ char *errmsg = NULL;
+
+ switch (prefs_set_pref(optarg, &errmsg)) {
case PREFS_SET_OK:
break;
case PREFS_SET_SYNTAX_ERR:
- cmdarg_err("Invalid -o flag \"%s\"", optarg);
+ cmdarg_err("Invalid -o flag \"%s\"%s%s", optarg,
+ errmsg ? ": " : "", errmsg ? errmsg : "");
+ g_free(errmsg);
return 1;
break;
break;
}
break;
+ }
case 'q': /* Quiet */
quiet = TRUE;
break;
/* Process the packets in the file */
TRY {
/* XXX - for now there is only 1 packet */
- err = load_cap_file(&cfile, 1, 0);
+ success = process_file(&cfile, 1, 0);
}
CATCH(OutOfMemoryError) {
fprintf(stderr,
"\n"
"Some infos / workarounds can be found at:\n"
"https://wiki.wireshark.org/KnownBugs/OutOfMemory\n");
- err = ENOMEM;
+ success = FALSE;
}
ENDTRY;
- if (err != 0) {
+ if (!success) {
/* We still dump out the results of taps, etc., as we might have
read some packets; however, we exit with an error status. */
exit_status = 2;
epan_dissect_prime_with_dfilter(edt, cf->rfcode);
/* This is the first pass, so prime the epan_dissect_t with the
- fields postdissectors want on the first pass. */
- prime_epan_dissect_with_postdissector_wanted_fields(edt);
+ hfids postdissectors want on the first pass. */
+ prime_epan_dissect_with_postdissector_wanted_hfids(edt);
frame_data_set_before_dissect(&fdlocal, &cf->elapsed_time,
&ref, prev_dis);
epan_dissect_prime_with_dfilter(edt, cf->dfcode);
/* This is the first and only pass, so prime the epan_dissect_t
- with the fields postdissectors want on the first pass. */
- prime_epan_dissect_with_postdissector_wanted_fields(edt);
+ with the hfids postdissectors want on the first pass. */
+ prime_epan_dissect_with_postdissector_wanted_hfids(edt);
col_custom_prime_edt(edt, &cf->cinfo);
return TRUE; /* success */
}
-static int
-load_cap_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
+static gboolean
+process_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
{
guint32 framenum;
int err;
*
* we're going to apply a read filter;
*
- * a postdissector wants field values on the first pass.
+ * a postdissector wants field values or protocols
+ * on the first pass.
*/
create_proto_tree =
- (cf->rfcode != NULL || postdissectors_want_fields());
+ (cf->rfcode != NULL || postdissectors_want_hfids());
/* We're not going to display the protocol tree on this pass,
so it's not going to be "visible". */
#else
if (!process_packet_second_pass(cf, edt, fdata, &cf->phdr, &buf,
tap_flags))
- return 2;
+ return FALSE;
#endif
}
*
* one of the tap listeners requires a protocol tree;
*
- * a postdissector wants field values on the first pass;
+ * a postdissector wants field values or protocols
+ * on the first pass;
*
* we have custom columns (which require field values, which
* currently requires that we build a protocol tree).
*/
create_proto_tree =
(cf->rfcode || cf->dfcode || print_details || filtering_tap_listeners ||
- (tap_flags & TL_REQUIRES_PROTO_TREE) || postdissectors_want_fields() ||
+ (tap_flags & TL_REQUIRES_PROTO_TREE) || postdissectors_want_hfids() ||
have_custom_cols(&cf->cinfo));
/* The protocol tree will be "visible", i.e., printed, only if we're
if (!process_packet_single_pass(cf, edt, data_offset,
&file_phdr/*wtap_phdr(cf->wth)*/,
raw_data, tap_flags))
- return 2;
+ return FALSE;
/* Stop reading if we have the maximum number of packets;
* When the -c option has not been used, max_packet_count
wtap_close(cf->wth);
cf->wth = NULL;
- return err;
+ return (err != 0);
}
static gboolean
static gboolean
print_packet(capture_file *cf, epan_dissect_t *edt)
{
- print_args_t print_args;
-
if (print_summary || output_fields_has_cols(output_fields)) {
/* Just fill in the columns. */
epan_dissect_fill_in_columns(edt, FALSE, TRUE);
switch (output_action) {
case WRITE_TEXT:
- /* Only initialize the fields that are actually used in proto_tree_print.
- * This is particularly important for .range, as that's heap memory which
- * we would otherwise have to g_free().
- print_args.to_file = TRUE;
- print_args.format = print_format;
- print_args.print_summary = print_summary;
- print_args.print_formfeed = FALSE;
- packet_range_init(&print_args.range, &cfile);
- */
- print_args.print_hex = print_hex;
- print_args.print_dissections = print_details ? print_dissections_expanded : print_dissections_none;
-
- if (!proto_tree_print(&print_args, edt, output_only_tables, print_stream))
+ if (!proto_tree_print(print_details ? print_dissections_expanded : print_dissections_none,
+ print_hex, edt, output_only_tables, print_stream))
return FALSE;
if (!print_hex) {
if (!print_line(print_stream, 0, separator))