#include "packet-range.h"
#include "print.h"
#include "ps.h"
-#include "file_util.h"
+#include "version_info.h"
+#include <wsutil/file_util.h>
#include <epan/charsets.h>
#include <epan/dissectors/packet-data.h>
#include <epan/dissectors/packet-frame.h>
/* Open the file or command for output */
if (to_file)
- fh = eth_fopen(dest, "w");
+ fh = ws_fopen(dest, "w");
else
fh = popen(dest, "w");
int chop_len;
int i;
+ /* Will wrap up top-level field items inside a fake protocol wrapper to
+ preserve the PDML schema */
+ gboolean wrap_in_fake_protocol =
+ (((fi->hfinfo->type != FT_PROTOCOL) ||
+ (fi->hfinfo->id == proto_data)) &&
+ (pdata->level == 0));
+
+ /* Indent to the correct level */
for (i = -1; i < pdata->level; i++) {
fputs(" ", pdata->fh);
}
+ if (wrap_in_fake_protocol) {
+ /* Open fake protocol wrapper */
+ fputs("<proto name=\"fake-field-wrapper\">\n", pdata->fh);
+
+ /* Indent to increased level before writint out field */
+ pdata->level++;
+ for (i = -1; i < pdata->level; i++) {
+ fputs(" ", pdata->fh);
+ }
+ }
+
/* Text label. It's printed as a field with no name. */
if (fi->hfinfo->id == hf_text_only) {
/* Get the text */
fputs("\"/>\n", pdata->fh);
}
}
+
/* Uninterpreted data, i.e., the "Data" protocol, is
* printed as a field instead of a protocol. */
else if (fi->hfinfo->id == proto_data) {
+ /* Write out field with data */
fputs("<field name=\"data\" value=\"", pdata->fh);
-
write_pdml_field_hex_value(pdata, fi);
-
fputs("\"/>\n", pdata->fh);
-
}
/* Normal protocols and fields */
else {
print_escaped_xml(pdata->fh, fi->hfinfo->abbrev);
#if 0
- /* PDML spec, see:
+ /* PDML spec, see:
* http://analyzer.polito.it/30alpha/docs/dissectors/PDMLSpec.htm
*
* the show fields contains things in 'human readable' format
* showdtl: contains additional details of the field data
* showmap: contains mappings of the field data (e.g. the hostname to an IP address)
*
- * XXX - the showname shouldn't contain the field data itself
- * (like it's contained in the fi->rep->representation).
- * Unfortunately, we don't have the field data representation for
+ * XXX - the showname shouldn't contain the field data itself
+ * (like it's contained in the fi->rep->representation).
+ * Unfortunately, we don't have the field data representation for
* all fields, so this isn't currently possible */
fputs("\" showname=\"", pdata->fh);
print_escaped_xml(pdata->fh, fi->hfinfo->name);
pdata->level--;
}
+ /* Take back the extra level we added for fake wrapper protocol */
+ if (wrap_in_fake_protocol) {
+ pdata->level--;
+ }
+
if (node->first_child != NULL) {
+ /* Indent to correct level */
for (i = -1; i < pdata->level; i++) {
fputs(" ", pdata->fh);
}
- if (fi->hfinfo->type == FT_PROTOCOL) {
- fputs("</proto>\n", pdata->fh);
- }
- else {
- fputs("</field>\n", pdata->fh);
+ /* Close off current element */
+ if (fi->hfinfo->id != proto_data) { /* Data protocol uses simple tags */
+ if (fi->hfinfo->type == FT_PROTOCOL) {
+ fputs("</proto>\n", pdata->fh);
+ }
+ else {
+ fputs("</field>\n", pdata->fh);
+ }
}
}
+
+ /* Close off fake wrapper protocol */
+ if (wrap_in_fake_protocol) {
+ fputs("</proto>\n", pdata->fh);
+ }
}
/* Print info for a 'geninfo' pseudo-protocol. This is required by
}
+void
+write_carrays_preamble(FILE *fh _U_)
+{
+
+}
+
+void
+proto_tree_write_carrays(const guint8 *pd, guint32 len, guint32 num, FILE *fh)
+{
+ guint32 i = 0;
+
+ if (!len)
+ return;
+
+ fprintf(fh, "char pkt%u[] = {\n", num);
+
+ for (i = 0; i < len; i++) {
+
+ fprintf(fh, "0x%02x", *(pd + i));
+
+ if (i == (len - 1)) {
+ fprintf(fh, " };\n\n");
+ break;
+ }
+
+ if (!((i + 1) % 8)) {
+ fprintf(fh, ", \n");
+ } else {
+ fprintf(fh, ", ");
+ }
+ }
+}
+
+void
+write_carrays_finale(FILE *fh _U_)
+{
+
+}
+
/*
* Find the data source for a specified field, and return a pointer
* to the data in it. Returns NULL if the data is out of bounds.
if (multiple_sources) {
name = src->name;
print_line(stream, 0, "");
- line = g_malloc(strlen(name) + 2); /* <name>:\0 */
- strcpy(line, name);
- strcat(line, ":");
+ line = g_strdup_printf("%s:", name);
print_line(stream, 0, line);
g_free(line);
}
* and advance the offset.
*/
line[k] = '\0';
- if (!print_line(stream, 0, (char*)line))
+ if (!print_line(stream, 0, line))
return FALSE;
ad += 16;
}
print_ps_preamble(output->fh);
- fputs("%% Set the font to 10 point\n", output->fh);
- fputs("/Courier findfont 10 scalefont setfont\n", output->fh);
+ fputs("%% Set the font to 8 point\n", output->fh);
+ fputs("/Courier findfont 8 scalefont setfont\n", output->fh);
fputs("\n", output->fh);
fputs("%% the page title\n", output->fh);
- ps_clean_string(psbuffer, (guchar*)filename, MAX_PS_LINE_LENGTH);
- fprintf(output->fh, "/eth_pagetitle (%s - Wireshark) def\n", psbuffer);
+ ps_clean_string(psbuffer, filename, MAX_PS_LINE_LENGTH);
+ fprintf(output->fh, "/eth_pagetitle (%s - Wireshark " VERSION "%s) def\n", psbuffer, wireshark_svnversion);
fputs("\n", output->fh);
return !ferror(output->fh);
}
output_ps *output = self->data;
unsigned char psbuffer[MAX_PS_LINE_LENGTH]; /* static sized buffer! */
- ps_clean_string(psbuffer, (guchar*)line, MAX_PS_LINE_LENGTH);
+ ps_clean_string(psbuffer, line, MAX_PS_LINE_LENGTH);
fprintf(output->fh, "%d (%s) putline\n", indent, psbuffer);
return !ferror(output->fh);
}
*
* The "/DEST" creates the destination.
*/
- ps_clean_string(psbuffer, (guchar*)title, MAX_PS_LINE_LENGTH);
+ ps_clean_string(psbuffer, title, MAX_PS_LINE_LENGTH);
fprintf(output->fh, "[/Dest /%s /Title (%s) /OUT pdfmark\n", name,
psbuffer);
fputs("[/View [/XYZ -4 currentpoint matrix currentmatrix matrix defaultmatrix\n",
fields->fields = NULL; /*Do lazy initialisation */
fields->field_indicies = NULL;
fields->field_values = NULL;
- fields->quote='\0';
+ fields->quote='\0';
return fields;
}
g_ptr_array_free(fields->fields, TRUE);
}
- g_free(fields);
+ g_free(fields);
}
void output_fields_add(output_fields_t* fields, const gchar* field)
info->separator = *option_value;
break;
}
- return TRUE;
+ return TRUE;
}
if(0 == strcmp(option_name, "quote")) {
info->quote='\0';
break;
}
- return TRUE;
+ return TRUE;
}
return FALSE;
fputc(fields->separator, fh);
}
fputs(field, fh);
- }
+ }
fputc('\n', fh);
}
-
-
-
-static void proto_tree_get_node_field_values(proto_node *node, gpointer data)
+static void proto_tree_get_node_field_values(proto_node *node, gpointer data)
{
write_field_data_t *call_data;
- field_info *fi;
+ field_info *fi;
gpointer field_index;
call_data = data;
call_data->fields->field_values[actual_index - 1] = value;
}
}
-
- /* Recurse here. */
- if (node->first_child != NULL) {
- proto_tree_children_foreach(node,
- proto_tree_get_node_field_values, call_data);
- }
+
+ /* Recurse here. */
+ if (node->first_child != NULL) {
+ proto_tree_children_foreach(node, proto_tree_get_node_field_values,
+ call_data);
+ }
}
void proto_tree_write_fields(output_fields_t* fields, epan_dissect_t *edt, FILE *fh)
i = 0;
while( i < fields->fields->len) {
gchar* field = g_ptr_array_index(fields->fields, i);
- /* Store field indicies +1 so that zero is not a valid value,
+ /* Store field indicies +1 so that zero is not a valid value,
* and can be distinguished from NULL as a pointer.
*/
++i;
- g_hash_table_insert(fields->field_indicies, field, GUINT_TO_POINTER(i));
+ g_hash_table_insert(fields->field_indicies, field, GUINT_TO_POINTER(i));
}
}
/* Buffer to store values for this packet */
fields->field_values = ep_alloc_array0(const gchar*, fields->fields->len);
-
- proto_tree_children_foreach(edt->tree, proto_tree_get_node_field_values,
- &data);
+
+ proto_tree_children_foreach(edt->tree, proto_tree_get_node_field_values,
+ &data);
for(i = 0; i < fields->fields->len; ++i) {
if(0 != i) {
/* Returns an ep_alloced string or a static constant*/
static const gchar* get_node_field_value(field_info* fi, epan_dissect_t* edt)
{
- /* Text label. */
- if (fi->hfinfo->id == hf_text_only) {
- /* Get the text */
- if (fi->rep) {
+ if (fi->hfinfo->id == hf_text_only) {
+ /* Text label.
+ * Get the text */
+ if (fi->rep) {
return fi->rep->representation;
- }
- else {
- return get_field_hex_value(edt->pi.data_src, fi);
- }
- }
- /* Uninterpreted data, i.e., the "Data" protocol, is
- * printed as a field instead of a protocol. */
- else if (fi->hfinfo->id == proto_data) {
+ }
+ else {
+ return get_field_hex_value(edt->pi.data_src, fi);
+ }
+ }
+ else if (fi->hfinfo->id == proto_data) {
+ /* Uninterpreted data, i.e., the "Data" protocol, is
+ * printed as a field instead of a protocol. */
return get_field_hex_value(edt->pi.data_src, fi);
- }
-
- /* Normal protocols and fields */
- else {
- gchar *dfilter_string;
- gint chop_len;
-
- switch (fi->hfinfo->type)
- {
- case FT_PROTOCOL:
+ }
+ else {
+ /* Normal protocols and fields */
+ gchar *dfilter_string;
+ gint chop_len;
+
+ switch (fi->hfinfo->type)
+ {
+ case FT_PROTOCOL:
/* Print out the full details for the protocol. */
- if (fi->rep) {
+ if (fi->rep) {
return fi->rep->representation;
- } else {
+ } else {
/* Just print out the protocol abbreviation */
return fi->hfinfo->abbrev;;
}
- case FT_NONE:
- return NULL;
- default:
- /* XXX - this is a hack until we can just call
- * fvalue_to_string_repr() for *all* FT_* types. */
- dfilter_string = proto_construct_match_selected_string(fi,
- edt);
- if (dfilter_string != NULL) {
- chop_len = strlen(fi->hfinfo->abbrev) + 4; /* for " == " */
-
- /* XXX - Remove double-quotes. Again, once we
- * can call fvalue_to_string_repr(), we can
- * ask it not to produce the version for
- * display-filters, and thus, no
- * double-quotes. */
- if (dfilter_string[strlen(dfilter_string)-1] == '"') {
- dfilter_string[strlen(dfilter_string)-1] = '\0';
- chop_len++;
- }
+ case FT_NONE:
+ /* Return "1" so that the presence of a field of type
+ * FT_NONE can be checked when using -T fields */
+ return "1";
+ default:
+ /* XXX - this is a hack until we can just call
+ * fvalue_to_string_repr() for *all* FT_* types. */
+ dfilter_string = proto_construct_match_selected_string(fi,
+ edt);
+ if (dfilter_string != NULL) {
+ chop_len = strlen(fi->hfinfo->abbrev) + 4; /* for " == " */
+
+ /* XXX - Remove double-quotes. Again, once we
+ * can call fvalue_to_string_repr(), we can
+ * ask it not to produce the version for
+ * display-filters, and thus, no
+ * double-quotes. */
+ if (dfilter_string[strlen(dfilter_string)-1] == '"') {
+ dfilter_string[strlen(dfilter_string)-1] = '\0';
+ chop_len++;
+ }
return &(dfilter_string[chop_len]);
- } else {
- return get_field_hex_value(edt->pi.data_src, fi);
+ } else {
+ return get_field_hex_value(edt->pi.data_src, fi);
}
- }
+ }
}
}
static const gchar*
get_field_hex_value(GSList* src_list, field_info *fi)
{
- const guint8 *pd;
+ const guint8 *pd;
- if (fi->length > tvb_length_remaining(fi->ds_tvb, fi->start)) {
- return "field length invalid!";
- }
+ if (fi->length > tvb_length_remaining(fi->ds_tvb, fi->start)) {
+ return "field length invalid!";
+ }
- /* Find the data for this field. */
- pd = get_field_data(src_list, fi);
+ /* Find the data for this field. */
+ pd = get_field_data(src_list, fi);
- if (pd) {
- int i;
+ if (pd) {
+ int i;
gchar* buffer;
gchar* p;
int len;
buffer = ep_alloc_array(gchar, len + 1);
buffer[len] = '\0'; /* Ensure NULL termination in bad cases */
p = buffer;
- /* Print a simple hex dump */
- for (i = 0 ; i < fi->length; i++) {
- g_snprintf(p, len, "%02x", pd[i]);
+ /* Print a simple hex dump */
+ for (i = 0 ; i < fi->length; i++) {
+ g_snprintf(p, chars_per_byte+1, "%02x", pd[i]);
p += chars_per_byte;
- len -= chars_per_byte;
- }
+ }
return buffer;
- } else {
+ } else {
return NULL;
}
}