aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/tshark.pod8
-rw-r--r--print.c35
-rw-r--r--tshark.c1
3 files changed, 39 insertions, 5 deletions
diff --git a/doc/tshark.pod b/doc/tshark.pod
index 24c7a6e0ba..6110d19929 100644
--- a/doc/tshark.pod
+++ b/doc/tshark.pod
@@ -281,9 +281,15 @@ the same character as the field values. Defaults to B<n>.
B<separator=/t|/s|>E<lt>characterE<gt> Set the separator character to
use for fields. If B</t> tab will be used (this is the default), if
-B</s>, s single space will be used. Otherwise any character that can be
+B</s>, a single space will be used. Otherwise any character that can be
accepted by the command line as part of the option may be used.
+B<aggregator=,|/s|>E<lt>characterE<gt> Set the aggregator character to
+use for fields that have multiple occurences. If B<,> a comma will be used
+(this is the default), if B</s>, a single space will be used. Otherwise
+any character that can be accepted by the command line as part of the
+option may be used.
+
B<quote=d|s|n> Set the quote character to use to surround fields. B<d>
uses double-quotes, B<s> single-quotes, B<n> no quotes (the default).
diff --git a/print.c b/print.c
index b0a897fa03..6c22250ed6 100644
--- a/print.c
+++ b/print.c
@@ -75,9 +75,10 @@ typedef struct {
struct _output_fields {
gboolean print_header;
gchar separator;
+ gchar aggregator;
GPtrArray* fields;
GHashTable* field_indicies;
- const gchar** field_values;
+ emem_strbuf_t** field_values;
gchar quote;
};
@@ -1255,6 +1256,7 @@ output_fields_t* output_fields_new()
output_fields_t* fields = g_new(output_fields_t, 1);
fields->print_header = FALSE;
fields->separator = '\t';
+ fields->aggregator = ',';
fields->fields = NULL; /*Do lazy initialisation */
fields->field_indicies = NULL;
fields->field_values = NULL;
@@ -1362,6 +1364,26 @@ gboolean output_fields_set_option(output_fields_t* info, gchar* option)
return TRUE;
}
+ if(0 == strcmp(option_name,"aggregator")) {
+ switch(NULL == option_value ? '\0' : *option_value) {
+ case '\0':
+ return FALSE;
+ case '/':
+ switch(*++option_value) {
+ case 's':
+ info->aggregator = ' ';
+ break;
+ default:
+ info->aggregator = '\\';
+ }
+ break;
+ default:
+ info->aggregator = *option_value;
+ break;
+ }
+ return TRUE;
+ }
+
if(0 == strcmp(option_name, "quote")) {
switch(NULL == option_value ? '\0' : *option_value) {
default: /* Fall through */
@@ -1435,7 +1457,12 @@ static void proto_tree_get_node_field_values(proto_node *node, gpointer data)
guint actual_index;
actual_index = GPOINTER_TO_UINT(field_index);
/* Unwrap change made to disambiguiate zero / null */
- call_data->fields->field_values[actual_index - 1] = value;
+ if (call_data->fields->field_values[actual_index - 1] == NULL ) {
+ call_data->fields->field_values[actual_index - 1] = ep_strbuf_new(value);
+ } else {
+ ep_strbuf_append_printf(call_data->fields->field_values[actual_index - 1],
+ "%c%s",call_data->fields->aggregator,value);
+ }
}
}
@@ -1475,7 +1502,7 @@ void proto_tree_write_fields(output_fields_t* fields, epan_dissect_t *edt, FILE
}
/* Buffer to store values for this packet */
- fields->field_values = ep_alloc_array0(const gchar*, fields->fields->len);
+ fields->field_values = ep_alloc_array0(emem_strbuf_t*, fields->fields->len);
proto_tree_children_foreach(edt->tree, proto_tree_get_node_field_values,
&data);
@@ -1488,7 +1515,7 @@ void proto_tree_write_fields(output_fields_t* fields, epan_dissect_t *edt, FILE
if(fields->quote != '\0') {
fputc(fields->quote, fh);
}
- fputs(fields->field_values[i], fh);
+ fputs(fields->field_values[i]->str, fh);
if(fields->quote != '\0') {
fputc(fields->quote, fh);
}
diff --git a/tshark.c b/tshark.c
index a6b7ffc6c4..9de1469e81 100644
--- a/tshark.c
+++ b/tshark.c
@@ -280,6 +280,7 @@ print_usage(gboolean print_ver)
fprintf(output, " -E<fieldsoption>=<value> set options for output when -Tfields selected:\n");
fprintf(output, " header=y|n switch headers on and off\n");
fprintf(output, " separator=/t|/s|<char> select tab, space, printable character as separator\n");
+ fprintf(output, " aggregator=,|/s|<char> select comma, space, printable character as aggregator\n");
fprintf(output, " quote=d|s|n select double, single, no quotes for values\n");
fprintf(output, " -t ad|a|r|d|dd|e output format of time stamps (def: r: rel. to first)\n");
fprintf(output, " -u s|hms output format of seconds (def: s: seconds)\n");