aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--file.c49
-rw-r--r--gtk/keys.h3
-rw-r--r--gtk/main.c10
-rw-r--r--gtk/print_dlg.c47
-rw-r--r--prefs.h5
-rw-r--r--print.c63
-rw-r--r--print.h15
7 files changed, 114 insertions, 78 deletions
diff --git a/file.c b/file.c
index bc46a4e332..b05c28b9e6 100644
--- a/file.c
+++ b/file.c
@@ -1,7 +1,7 @@
/* file.c
* File I/O routines
*
- * $Id: file.c,v 1.148 2000/01/05 07:22:47 guy Exp $
+ * $Id: file.c,v 1.149 2000/01/06 07:33:20 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -844,6 +844,8 @@ colorize_packets(capture_file *cf)
gtk_clist_thaw(GTK_CLIST(packet_list));
}
+#define MAX_LINE_LENGTH 256
+
int
print_packets(capture_file *cf, print_args_t *print_args)
{
@@ -856,19 +858,15 @@ print_packets(capture_file *cf, print_args_t *print_args)
gint *col_widths = NULL;
gint data_width;
gboolean print_separator;
+ char line_buf[MAX_LINE_LENGTH+1]; /* static-sized buffer! */
+ char *cp;
+ int sprintf_len;
cf->print_fh = open_print_dest(print_args->to_file, print_args->dest);
if (cf->print_fh == NULL)
return FALSE; /* attempt to open destination failed */
- /* XXX - printing multiple frames in PostScript looks as if it's
- tricky - you have to deal with page boundaries, I think -
- and I'll have to spend some time learning enough about
- PostScript to figure it out, so, for now, we only print
- multiple frames as text. */
-#if 0
- print_preamble(cf->print_fh);
-#endif
+ print_preamble(cf->print_fh, print_args->format);
if (print_args->print_summary) {
/* We're printing packet summaries.
@@ -877,6 +875,7 @@ print_packets(capture_file *cf, print_args_t *print_args)
width of the title and the width of the data - and print
the column titles. */
col_widths = (gint *) g_malloc(sizeof(gint) * cf->cinfo.num_cols);
+ cp = &line_buf[0];
for (i = 0; i < cf->cinfo.num_cols; i++) {
/* Don't pad the last column. */
if (i == cf->cinfo.num_cols - 1)
@@ -890,14 +889,17 @@ print_packets(capture_file *cf, print_args_t *print_args)
/* Right-justify the packet number column. */
if (cf->cinfo.col_fmt[i] == COL_NUMBER)
- fprintf(cf->print_fh, "%*s", col_widths[i], cf->cinfo.col_title[i]);
+ sprintf_len = sprintf(cp, "%*s", col_widths[i], cf->cinfo.col_title[i]);
else
- fprintf(cf->print_fh, "%-*s", col_widths[i], cf->cinfo.col_title[i]);
+ sprintf_len = sprintf(cp, "%-*s", col_widths[i], cf->cinfo.col_title[i]);
+ cp += sprintf_len;
if (i == cf->cinfo.num_cols - 1)
- fputc('\n', cf->print_fh);
+ *cp++ = '\n';
else
- fputc(' ', cf->print_fh);
+ *cp++ = ' ';
}
+ *cp = '\0';
+ print_line(cf->print_fh, print_args->format, line_buf);
}
print_separator = FALSE;
@@ -944,20 +946,24 @@ print_packets(capture_file *cf, print_args_t *print_args)
}
dissect_packet(cf->pd, fd, NULL);
fill_in_columns(fd);
+ cp = &line_buf[0];
for (i = 0; i < cf->cinfo.num_cols; i++) {
/* Right-justify the packet number column. */
if (cf->cinfo.col_fmt[i] == COL_NUMBER)
- fprintf(cf->print_fh, "%*s", col_widths[i], cf->cinfo.col_data[i]);
+ sprintf_len = sprintf(cp, "%*s", col_widths[i], cf->cinfo.col_data[i]);
else
- fprintf(cf->print_fh, "%-*s", col_widths[i], cf->cinfo.col_data[i]);
+ sprintf_len = sprintf(cp, "%-*s", col_widths[i], cf->cinfo.col_data[i]);
+ cp += sprintf_len;
if (i == cf->cinfo.num_cols - 1)
- fputc('\n', cf->print_fh);
+ *cp++ = '\n';
else
- fputc(' ', cf->print_fh);
+ *cp++ = ' ';
}
+ *cp = '\0';
+ print_line(cf->print_fh, print_args->format, line_buf);
} else {
if (print_separator)
- fputc('\n', cf->print_fh);
+ print_line(cf->print_fh, print_args->format, "\n");
/* Create the logical protocol tree. */
protocol_tree = proto_tree_create_root();
@@ -971,7 +977,8 @@ print_packets(capture_file *cf, print_args_t *print_args)
if (print_args->print_hex) {
/* Print the full packet data as hex. */
- print_hex_data(cf->print_fh, cf->pd, fd->cap_len, fd->encoding);
+ print_hex_data(cf->print_fh, print_args->format, cf->pd,
+ fd->cap_len, fd->encoding);
}
/* Print a blank line if we print anything after this. */
@@ -983,9 +990,7 @@ print_packets(capture_file *cf, print_args_t *print_args)
if (col_widths != NULL)
g_free(col_widths);
-#if 0
- print_finale(cf->print_fh);
-#endif
+ print_finale(cf->print_fh, print_args->format);
close_print_dest(print_args->to_file, cf->print_fh);
diff --git a/gtk/keys.h b/gtk/keys.h
index 53e7d60996..b64ec08511 100644
--- a/gtk/keys.h
+++ b/gtk/keys.h
@@ -1,7 +1,7 @@
/* keys.h
* Key definitions for various objects
*
- * $Id: keys.h,v 1.8 1999/12/09 20:41:41 oabad Exp $
+ * $Id: keys.h,v 1.9 2000/01/06 07:33:33 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -37,7 +37,6 @@
#define PRINT_CMD_TE_KEY "printer_command_entry"
#define PRINT_FILE_BT_KEY "printer_file_button"
#define PRINT_FILE_TE_KEY "printer_file_entry"
-#define PRINT_DEST_RB_KEY "printer_destination_radio_button"
#define PLUGINS_DFILTER_TE "plugins_dfilter_te"
diff --git a/gtk/main.c b/gtk/main.c
index 8112e4d0ea..bd1864fa53 100644
--- a/gtk/main.c
+++ b/gtk/main.c
@@ -1,6 +1,6 @@
/* main.c
*
- * $Id: main.c,v 1.82 2000/01/05 22:31:46 gerald Exp $
+ * $Id: main.c,v 1.83 2000/01/06 07:33:33 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -394,9 +394,11 @@ static void follow_print_stream(GtkWidget *w, gpointer parent_w)
E_FOLLOW_FILENAME_KEY);
if (filename != NULL) {
- print_preamble(fh);
- print_file(fh, filename);
- print_finale(fh);
+ /* XXX - make this look at the preferences and print in
+ PostScript if that's what the user specified. */
+ print_preamble(fh, PR_FMT_TEXT);
+ print_file(fh, filename, PR_FMT_TEXT);
+ print_finale(fh, PR_FMT_TEXT);
close_print_dest(to_file, fh);
}
else {
diff --git a/gtk/print_dlg.c b/gtk/print_dlg.c
index 0407f5778f..d701d2186c 100644
--- a/gtk/print_dlg.c
+++ b/gtk/print_dlg.c
@@ -1,7 +1,7 @@
/* print_dlg.c
* Dialog boxes for printing
*
- * $Id: print_dlg.c,v 1.12 2000/01/03 06:59:24 guy Exp $
+ * $Id: print_dlg.c,v 1.13 2000/01/06 07:33:35 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -63,6 +63,15 @@ static void print_close_cb(GtkWidget *close_bt, gpointer parent_w);
*/
static int print_to_file;
+/*
+ * Remember whether we printed as text or PostScript the last time we
+ * printed something.
+ */
+static gint print_format = PR_FMT_TEXT;
+
+#define PRINT_FORMAT_RB_KEY "printer_format_radio_button"
+#define PRINT_DEST_RB_KEY "printer_destination_radio_button"
+
#define PRINT_SUMMARY_RB_KEY "printer_summary_radio_button"
#define PRINT_HEX_CB_KEY "printer_hex_check_button"
#define PRINT_EXPAND_ALL_RB_KEY "printer_expand_all_radio_button"
@@ -74,10 +83,9 @@ file_print_cmd_cb(GtkWidget *widget, gpointer data)
{
GtkWidget *print_w;
GtkWidget *main_vb, *main_tb, *button;
-#if 0
+ GtkWidget *format_rb;
GtkWidget *format_hb, *format_lb;
GSList *format_grp;
-#endif
GtkWidget *dest_rb;
GtkWidget *dest_hb, *dest_lb;
GtkWidget *cmd_lb, *cmd_te;
@@ -108,12 +116,6 @@ file_print_cmd_cb(GtkWidget *widget, gpointer data)
gtk_table_set_col_spacings(GTK_TABLE(main_tb), 15);
gtk_widget_show(main_tb);
- /* XXX - printing multiple frames in PostScript looks as if it's
- tricky - you have to deal with page boundaries, I think -
- and I'll have to spend some time learning enough about
- PostScript to figure it out, so, for now, we only print
- multiple frames as text. */
-#if 0
/* Output format */
format_lb = gtk_label_new("Format:");
gtk_misc_set_alignment(GTK_MISC(format_lb), 1.0, 0.5);
@@ -125,18 +127,17 @@ file_print_cmd_cb(GtkWidget *widget, gpointer data)
gtk_widget_show(format_hb);
button = gtk_radio_button_new_with_label(NULL, "Plain Text");
- if (prefs.pr_format == PR_FMT_TEXT)
+ if (print_format == PR_FMT_TEXT)
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), TRUE);
format_grp = gtk_radio_button_group(GTK_RADIO_BUTTON(button));
gtk_box_pack_start(GTK_BOX(format_hb), button, FALSE, FALSE, 10);
gtk_widget_show(button);
- button = gtk_radio_button_new_with_label(format_grp, "PostScript");
- if (prefs.pr_format == PR_FMT_PS)
- gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), TRUE);
- gtk_box_pack_start(GTK_BOX(format_hb), button, FALSE, FALSE, 10);
- gtk_widget_show(button);
-#endif
+ format_rb = gtk_radio_button_new_with_label(format_grp, "PostScript");
+ if (print_format == PR_FMT_PS)
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(format_rb), TRUE);
+ gtk_box_pack_start(GTK_BOX(format_hb), format_rb, FALSE, FALSE, 10);
+ gtk_widget_show(format_rb);
/* Output destination */
dest_lb = gtk_label_new("Print to:");
@@ -265,6 +266,7 @@ file_print_cmd_cb(GtkWidget *widget, gpointer data)
gtk_widget_show(bbox);
ok_bt = gtk_button_new_with_label ("OK");
+ gtk_object_set_data(GTK_OBJECT(ok_bt), PRINT_FORMAT_RB_KEY, format_rb);
gtk_object_set_data(GTK_OBJECT(ok_bt), PRINT_DEST_RB_KEY, dest_rb);
gtk_object_set_data(GTK_OBJECT(ok_bt), PRINT_CMD_TE_KEY, cmd_te);
gtk_object_set_data(GTK_OBJECT(ok_bt), PRINT_FILE_TE_KEY, file_te);
@@ -395,6 +397,14 @@ print_ok_cb(GtkWidget *ok_bt, gpointer parent_w)
PRINT_CMD_TE_KEY))));
button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(ok_bt),
+ PRINT_FORMAT_RB_KEY);
+ if (GTK_TOGGLE_BUTTON (button)->active)
+ print_format = PR_FMT_PS;
+ else
+ print_format = PR_FMT_TEXT;
+ print_args.format = print_format;
+
+ button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(ok_bt),
PRINT_SUMMARY_RB_KEY);
print_args.print_summary = GTK_TOGGLE_BUTTON (button)->active;
@@ -475,13 +485,14 @@ file_print_packet_cmd_cb(GtkWidget *widget, gpointer data) {
return;
}
- print_preamble(fh);
+ print_preamble(fh, prefs.pr_format);
+ print_args.format = prefs.pr_format;
print_args.print_summary = FALSE;
print_args.print_hex = FALSE;
print_args.expand_all = TRUE;
proto_tree_print(TRUE, &print_args, (GNode*) cf.protocol_tree, cf.pd,
cf.current_frame, fh);
- print_finale(fh);
+ print_finale(fh, prefs.pr_format);
close_print_dest(print_args.to_file, fh);
}
diff --git a/prefs.h b/prefs.h
index 52e9a4675d..c13bb78dbe 100644
--- a/prefs.h
+++ b/prefs.h
@@ -1,7 +1,7 @@
/* prefs.h
* Definitions for preference handling routines
*
- * $Id: prefs.h,v 1.14 2000/01/03 06:29:33 guy Exp $
+ * $Id: prefs.h,v 1.15 2000/01/06 07:33:22 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -26,9 +26,6 @@
#ifndef __PREFS_H__
#define __PREFS_H__
-#define PR_FMT_TEXT 0
-#define PR_FMT_PS 1
-
#define PR_DEST_CMD 0
#define PR_DEST_FILE 1
diff --git a/print.c b/print.c
index ed3f01bdca..20fe6554ae 100644
--- a/print.c
+++ b/print.c
@@ -1,7 +1,7 @@
/* print.c
* Routines for printing packet analysis trees.
*
- * $Id: print.c,v 1.25 1999/12/10 04:20:53 gram Exp $
+ * $Id: print.c,v 1.26 2000/01/06 07:33:22 guy Exp $
*
* Gilbert Ramirez <gram@verdict.uthscsa.edu>
*
@@ -37,7 +37,6 @@
#endif
#include "packet.h"
-#include "prefs.h"
#include "print.h"
#include "ps.h"
#include "util.h"
@@ -46,6 +45,8 @@ static void proto_tree_print_node_text(GNode *node, gpointer data);
static void proto_tree_print_node_ps(GNode *node, gpointer data);
static void ps_clean_string(unsigned char *out, const unsigned char *in,
int outbuf_size);
+static void print_hex_data_text(FILE *fh, register const u_char *cp,
+ register u_int length, char_enc encoding);
static void print_hex_data_ps(FILE *fh, register const u_char *cp,
register u_int length, char_enc encoding);
static void print_ps_file(FILE* target_fh, FILE* source_fh);
@@ -85,19 +86,19 @@ void close_print_dest(int to_file, FILE *fh)
pclose(fh);
}
-void print_preamble(FILE *fh)
+void print_preamble(FILE *fh, gint format)
{
- if (prefs.pr_format == PR_FMT_PS)
+ if (format == PR_FMT_PS)
print_ps_preamble(fh);
}
-void print_finale(FILE *fh)
+void print_finale(FILE *fh, gint format)
{
- if (prefs.pr_format == PR_FMT_PS)
+ if (format == PR_FMT_PS)
print_ps_finale(fh);
}
-void print_file(FILE* fh, const char* filename)
+void print_file(FILE* fh, const char* filename, gint format)
{
FILE* fh2 = fopen(filename, "r");
if (fh2 == NULL) {
@@ -105,7 +106,7 @@ void print_file(FILE* fh, const char* filename)
return;
}
- if (prefs.pr_format == PR_FMT_PS)
+ if (format == PR_FMT_PS)
print_ps_file(fh, fh2);
else
print_text_file(fh, fh2);
@@ -126,12 +127,7 @@ void proto_tree_print(gboolean print_one_packet, print_args_t *print_args,
/* If we're printing the entire packet in hex, don't
print uninterpreted data fields in hex as well. */
- /* XXX - printing multiple frames in PostScript looks as if it's
- tricky - you have to deal with page boundaries, I think -
- and I'll have to spend some time learning enough about
- PostScript to figure it out, so, for now, we only print
- multiple frames as text. */
- if (prefs.pr_format == PR_FMT_TEXT || !print_one_packet) {
+ if (print_args->format == PR_FMT_TEXT) {
g_node_children_foreach((GNode*) protocol_tree, G_TRAVERSE_ALL,
proto_tree_print_node_text, &data);
} else {
@@ -182,8 +178,8 @@ void proto_tree_print_node_text(GNode *node, gpointer data)
/* If it's uninterpreted data, dump it (unless our caller will
be printing the entire packet in hex). */
if (fi->hfinfo->id == proto_data && pdata->print_hex_for_data)
- print_hex_data(pdata->fh, &pdata->pd[fi->start], fi->length,
- pdata->encoding);
+ print_hex_data_text(pdata->fh, &pdata->pd[fi->start],
+ fi->length, pdata->encoding);
/* If we're printing all levels, or if this level is expanded,
recurse into the subtree, if it exists. */
@@ -197,10 +193,20 @@ void proto_tree_print_node_text(GNode *node, gpointer data)
}
}
+void print_hex_data(FILE *fh, gint format, register const u_char *cp,
+ register u_int length, char_enc encoding)
+{
+ if (format == PR_FMT_PS)
+ print_hex_data_ps(fh, cp, length, encoding);
+ else
+ print_hex_data_text(fh, cp, length, encoding);
+}
+
/* This routine was created by Dan Lasley <DLASLEY@PROMUS.com>, and
only slightly modified for ethereal by Gilbert Ramirez. */
-void print_hex_data(FILE *fh, register const u_char *cp, register u_int length,
- char_enc encoding)
+static
+void print_hex_data_text(FILE *fh, register const u_char *cp,
+ register u_int length, char_enc encoding)
{
register int ad, i, j, k;
u_char c;
@@ -263,9 +269,9 @@ void proto_tree_print_node_ps(GNode *node, gpointer data)
ps_clean_string(psbuffer, label_ptr, MAX_LINE_LENGTH);
fprintf(pdata->fh, "%d (%s) putline\n", pdata->level, psbuffer);
- /* If it's uninterpreted data, dump it. */
- if (fi->hfinfo->id == proto_data) {
- print_ps_hex(pdata->fh);
+ /* If it's uninterpreted data, dump it (unless our caller will
+ be printing the entire packet in hex). */
+ if (fi->hfinfo->id == proto_data && pdata->print_hex_for_data) {
print_hex_data_ps(pdata->fh, &pdata->pd[fi->start], fi->length,
pdata->encoding);
}
@@ -308,8 +314,8 @@ void ps_clean_string(unsigned char *out, const unsigned char *in,
}
static
-void print_hex_data_ps(FILE *fh, register const u_char *cp, register u_int length,
- char_enc encoding)
+void print_hex_data_ps(FILE *fh, register const u_char *cp,
+ register u_int length, char_enc encoding)
{
register int ad, i, j, k;
u_char c;
@@ -319,6 +325,7 @@ void print_hex_data_ps(FILE *fh, register const u_char *cp, register u_int lengt
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
u_char psline[MAX_LINE_LENGTH];
+ print_ps_hex(fh);
memset (line, ' ', sizeof line);
line[sizeof (line)-1] = 0;
for (ad=i=j=k=0; i<length; i++) {
@@ -368,3 +375,13 @@ void print_ps_file(FILE* target_fh, FILE* source_fh)
}
}
+void print_line(FILE *fh, gint format, char *line)
+{
+ char psbuffer[MAX_LINE_LENGTH]; /* static sized buffer! */
+
+ if (format == PR_FMT_PS) {
+ ps_clean_string(psbuffer, line, MAX_LINE_LENGTH);
+ fprintf(fh, "(%s) hexdump\n", psbuffer);
+ } else
+ fputs(line, fh);
+}
diff --git a/print.h b/print.h
index 268e2f169f..e20dcf6912 100644
--- a/print.h
+++ b/print.h
@@ -1,7 +1,7 @@
/* print.h
* Definitions for printing packet analysis trees.
*
- * $Id: print.h,v 1.15 1999/11/22 06:24:41 gram Exp $
+ * $Id: print.h,v 1.16 2000/01/06 07:33:23 guy Exp $
*
* Gilbert Ramirez <gram@verdict.uthscsa.edu>
*
@@ -28,10 +28,14 @@
#ifndef __PRINT_H__
#define __PRINT_H__
+#define PR_FMT_TEXT 0
+#define PR_FMT_PS 1
+
typedef struct {
gboolean to_file; /* TRUE if we're printing to a file */
char *dest; /* if printing to file, pathname;
if not, command string */
+ gint format; /* text or PostScript */
gboolean print_summary; /* TRUE if we should just print summary;
FALSE if we should print protocol tree. */
gboolean print_hex; /* TRUE if we should also print hex data;
@@ -44,12 +48,13 @@ typedef struct {
FILE *open_print_dest(int to_file, const char *dest);
void close_print_dest(int to_file, FILE *fh);
-void print_preamble(FILE *fh);
-void print_finale(FILE *fh);
-void print_file(FILE* fh, const char* filename);
+void print_preamble(FILE *fh, gint format);
+void print_finale(FILE *fh, gint format);
+void print_file(FILE* fh, const char* filename, gint format);
void proto_tree_print(gboolean print_one_packet, print_args_t *print_args,
GNode *protocol_tree, const u_char *pd, frame_data *fd, FILE *fh);
-void print_hex_data(FILE *fh, register const u_char *cp,
+void print_hex_data(FILE *fh, gint format, register const u_char *cp,
register u_int length, char_enc encoding);
+void print_line(FILE *fh, gint format, char *line);
#endif /* print.h */