/* print.c
* Routines for printing packet analysis trees.
*
- * $Id: print.c,v 1.54 2002/06/23 23:43:32 guy Exp $
+ * $Id: print.c,v 1.57 2002/08/28 21:00:40 jmayer Exp $
*
* Gilbert Ramirez <gram@alumni.rice.edu>
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
* Copyright 1998 Gerald Combs
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <stdio.h>
#include <string.h>
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-
#include <epan/epan.h>
#include <epan/epan_dissect.h>
#include <epan/tvbuff.h>
#include "packet-data.h"
static void proto_tree_print_node(GNode *node, gpointer data);
-static void print_hex_data_buffer(FILE *fh, register const u_char *cp,
- register u_int length, char_enc encoding, gint format);
+static void print_hex_data_buffer(FILE *fh, register const guchar *cp,
+ register guint length, char_enc encoding, gint format);
static void ps_clean_string(unsigned char *out, const unsigned char *in,
int outbuf_size);
pclose(fh);
}
-void print_preamble(FILE *fh, gint format)
-{
- if (format == PR_FMT_PS)
- print_ps_preamble(fh);
-}
-
-void print_finale(FILE *fh, gint format)
-{
- if (format == PR_FMT_PS)
- print_ps_finale(fh);
-}
-
void proto_tree_print(print_args_t *print_args, epan_dissect_t *edt,
FILE *fh)
{
{
field_info *fi = PITEM_FINFO(node);
print_data *pdata = (print_data*) data;
- int i;
- int num_spaces;
- char space[MAX_INDENT+1];
const guint8 *pd;
gchar label_str[ITEM_LABEL_LENGTH];
gchar *label_ptr;
- char psbuffer[MAX_PS_LINE_LENGTH]; /* static sized buffer! */
/* Don't print invisible entries. */
if (!fi->visible)
label_ptr = label_str;
proto_item_fill_label(fi, label_str);
}
-
- if (pdata->format == PR_FMT_PS) {
- /* Print the text, as PostScript */
- ps_clean_string(psbuffer, label_ptr, MAX_PS_LINE_LENGTH);
- fprintf(pdata->fh, "%d (%s) putline\n", pdata->level, psbuffer);
- } else {
- /* Prepare the tabs for printing, depending on tree level */
- num_spaces = pdata->level * 4;
- if (num_spaces > MAX_INDENT) {
- num_spaces = MAX_INDENT;
- }
- for (i = 0; i < num_spaces; i++) {
- space[i] = ' ';
- }
- /* The string is NUL-terminated */
- space[num_spaces] = '\0';
- /* Print the text */
- fprintf(pdata->fh, "%s%s\n", space, label_ptr);
- }
+ print_line(pdata->fh, pdata->level, pdata->format, label_ptr);
/* If it's uninterpreted data, dump it (unless our caller will
be printing the entire packet in hex). */
tvbuff_t *tvb;
char *name;
char *line;
- const u_char *cp;
+ const guchar *cp;
guint length;
/*
tvb = src->tvb;
if (multiple_sources) {
name = src->name;
- print_line(fh, format, "");
+ print_line(fh, 0, format, "");
line = g_malloc(strlen(name) + 2); /* <name>:\0 */
strcpy(line, name);
strcat(line, ":");
- print_line(fh, format, line);
+ print_line(fh, 0, format, line);
g_free(line);
}
length = tvb_length(tvb);
from data dump, data dump */
static void
-print_hex_data_buffer(FILE *fh, register const u_char *cp,
- register u_int length, char_enc encoding, gint format)
+print_hex_data_buffer(FILE *fh, register const guchar *cp,
+ register guint length, char_enc encoding, gint format)
{
register unsigned int ad, i, j, k, l;
- u_char c;
- u_char line[MAX_LINE_LEN + 1];
+ guchar c;
+ guchar line[MAX_LINE_LEN + 1];
unsigned int use_digits;
- static u_char binhex[16] = {
+ static guchar binhex[16] = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
- if (format == PR_FMT_PS)
- print_ps_hex(fh);
- print_line(fh, format, "");
+ print_line(fh, 0, format, "");
/*
* How many of the leading digits of the offset will we supply?
* and advance the offset.
*/
line[k] = '\0';
- print_line(fh, format, line);
+ print_line(fh, 0, format, line);
ad += 16;
}
}
}
}
-void print_line(FILE *fh, gint format, char *line)
+void print_preamble(FILE *fh, gint format)
{
+ if (format == PR_FMT_PS)
+ print_ps_preamble(fh);
+}
+
+void print_finale(FILE *fh, gint format)
+{
+ if (format == PR_FMT_PS)
+ print_ps_finale(fh);
+}
+
+void print_line(FILE *fh, int indent, gint format, char *line)
+{
+ char space[MAX_INDENT+1];
+ int i;
+ int num_spaces;
char psbuffer[MAX_PS_LINE_LENGTH]; /* static sized buffer! */
if (format == PR_FMT_PS) {
ps_clean_string(psbuffer, line, MAX_PS_LINE_LENGTH);
- fprintf(fh, "(%s) hexdump\n", psbuffer);
+ fprintf(fh, "%d (%s) putline\n", indent, psbuffer);
} else {
+ /* Prepare the tabs for printing, depending on tree level */
+ num_spaces = indent * 4;
+ if (num_spaces > MAX_INDENT) {
+ num_spaces = MAX_INDENT;
+ }
+ for (i = 0; i < num_spaces; i++) {
+ space[i] = ' ';
+ }
+ /* The string is NUL-terminated */
+ space[num_spaces] = '\0';
+
+ fputs(space, fh);
fputs(line, fh);
putc('\n', fh);
}