Add an item to the "File/Print" dialog box to ask that the full hex data
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 29 Sep 1999 22:19:24 +0000 (22:19 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 29 Sep 1999 22:19:24 +0000 (22:19 +0000)
of the packet be printed (this is only done if "Print detail" is
selected; it should be grayed out of "Print summary" is selected).

If that item is selected, suppress the hex printing of uninterpreted
data items in the protocol tree.

Move some GTK+ keys not used outside of "gtk/print_dlg.c" from
"gtk/keys.h" into "gtk/print_dlg.c".

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@736 f5534014-38df-0310-8fa8-9805f1628bb7

display.c
file.c
file.h
globals.h
gtk/keys.h
gtk/print_dlg.c
packet.c
print.c
print.h

index ede240c9c1e59c3dace7bc19805516849f5982b4..218b103c5b2d67c6b5f440a49f8538c52c3a4754 100644 (file)
--- a/display.c
+++ b/display.c
@@ -1,7 +1,7 @@
 /* display.c
  * Routines for packet display windows
  *
- * $Id: display.c,v 1.11 1999/09/26 14:39:11 deniel Exp $
+ * $Id: display.c,v 1.12 1999/09/29 22:19:12 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
 # include <sys/sockio.h>
 #endif
 
+#include "globals.h"
 #include "timestamp.h"
 #include "packet.h"
 #include "file.h"
 #include "display.h"
-#include "globals.h"
 
 extern capture_file  cf;
 extern GtkWidget *packet_list;
diff --git a/file.c b/file.c
index 97890c7b324b0ab6d4248add3dc456dbe2c23583..d69b1d813a8e533b07c2a2826e0dfcfbad0cf522 100644 (file)
--- a/file.c
+++ b/file.c
@@ -1,7 +1,7 @@
 /* file.c
  * File I/O routines
  *
- * $Id: file.c,v 1.99 1999/09/29 14:41:34 gram Exp $
+ * $Id: file.c,v 1.100 1999/09/29 22:19:14 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -871,11 +871,16 @@ print_packets(capture_file *cf, print_args_t *print_args)
         dissect_packet(cf->pd, fd, protocol_tree);
 
         /* Print the information in that tree. */
-        proto_tree_print(FALSE, print_args->expand_all, (GNode *)protocol_tree,
+        proto_tree_print(FALSE, print_args, (GNode *)protocol_tree,
                        cf->pd, fd, cf->print_fh);
 
         proto_tree_free(protocol_tree);
 
+       if (print_args->print_hex) {
+         /* Print the full packet data as hex. */
+         print_hex_data(cf->print_fh, cf->pd, fd->cap_len);
+       }
+
         /* Print a blank line if we print anything after this. */
         print_separator = TRUE;
       }
diff --git a/file.h b/file.h
index 623c7cf153c08d7c3f78f3d21a7ccf547251152e..17ed3294420cecbf52fbb85d40619cc8b022a02b 100644 (file)
--- a/file.h
+++ b/file.h
@@ -1,7 +1,7 @@
 /* file.h
  * Definitions for file structures and routines
  *
- * $Id: file.h,v 1.46 1999/09/23 04:38:52 ashokn Exp $
+ * $Id: file.h,v 1.47 1999/09/29 22:19:13 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -133,16 +133,6 @@ int  read_cap_file(capture_file *);
 int  tail_cap_file(char *, capture_file *);
 /* size_t read_frame_header(capture_file *); */
 
-typedef struct {
-  gboolean     to_file;        /* TRUE if we're printing to a file */
-  char         *dest;          /* if printing to file, pathname;
-                                  if not, command string */
-  gboolean     print_summary;  /* TRUE if we should just print summary;
-                                  FALSE if we should print protocol tree. */
-  gboolean     expand_all;     /* TRUE if we should expand all levels;
-                                  FALSE if we should expand as displayed. */
-} print_args_t;
-
 int print_packets(capture_file *cf, print_args_t *print_args);
 void filter_packets(capture_file *);
 void change_time_formats(capture_file *);
index 4cd43d8217e1dd22321552ff1ff71d437704c583..bd4eaaa2953065dee7e9c5313b17072ec745cd9b 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -1,7 +1,7 @@
 /* globals.h
  * Global defines, etc.
  *
- * $Id: globals.h,v 1.7 1999/09/26 14:39:12 deniel Exp $
+ * $Id: globals.h,v 1.8 1999/09/29 22:19:13 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
 #include <gtk/gtk.h>
 #endif
 
+#ifndef __PRINT_H__
+#include "print.h"
+#endif
+
 #ifndef __FILE_H__
 #include "file.h"
 #endif
index 9b1296c7fabba3301dfe0428c09346933a856c4d..3d2b26ef4041f47f9d57e50a93023bc7d2ba56b4 100644 (file)
@@ -1,7 +1,7 @@
 /* keys.h
  * Key definitions for various objects
  *
- * $Id: keys.h,v 1.5 1999/09/12 23:54:09 guy Exp $
+ * $Id: keys.h,v 1.6 1999/09/29 22:19:24 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -36,8 +36,5 @@
 #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 PRINT_SUMMARY_RB_KEY      "printer_summary_radio_button"
-#define PRINT_EXPAND_ALL_RB_KEY   "printer_expand_all_radio_button"
-#define PRINT_AS_DISPLAYED_RB_KEY "printer_as_displayed_radio_button"
 
 #endif
index 65afa3016c7f9cea66822cb836a290b9efb38850..25c09d1efdb7a455cde13b39613e9ed34d9238c3 100644 (file)
@@ -1,7 +1,7 @@
 /* print_dlg.c
  * Dialog boxes for printing
  *
- * $Id: print_dlg.c,v 1.6 1999/09/12 23:54:09 guy Exp $
+ * $Id: print_dlg.c,v 1.7 1999/09/29 22:19:23 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -63,6 +63,11 @@ static void print_close_cb(GtkWidget *close_bt, gpointer parent_w);
  */
 static int     print_to_file;
 
+#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"
+#define PRINT_AS_DISPLAYED_RB_KEY "printer_as_displayed_radio_button"
+
 /* Print the capture */
 void
 file_print_cmd_cb(GtkWidget *widget, gpointer data)
@@ -79,7 +84,7 @@ file_print_cmd_cb(GtkWidget *widget, gpointer data)
   GtkWidget     *file_bt_hb, *file_bt, *file_te;
   GSList        *dest_grp;
   GtkWidget     *options_hb;
-  GtkWidget     *summary_vb, *summary_rb, *detail_rb;
+  GtkWidget     *print_type_vb, *summary_rb, *detail_rb, *hex_cb;
   GSList        *summary_grp;
   GtkWidget     *expand_vb, *expand_all_rb, *as_displayed_rb;
   GSList        *expand_grp;
@@ -202,24 +207,30 @@ file_print_cmd_cb(GtkWidget *widget, gpointer data)
   gtk_widget_show(options_hb);
 
   /* Vertical box into which to put the "Print summary"/"Print detail"
-     radio buttons. */
-  summary_vb = gtk_vbox_new(FALSE, 5);
-  gtk_container_border_width(GTK_CONTAINER(summary_vb), 5);
-  gtk_container_add(GTK_CONTAINER(options_hb), summary_vb);
-  gtk_widget_show(summary_vb);
+     radio buttons and the "Print hex" check button. */
+  print_type_vb = gtk_vbox_new(FALSE, 5);
+  gtk_container_border_width(GTK_CONTAINER(print_type_vb), 5);
+  gtk_container_add(GTK_CONTAINER(options_hb), print_type_vb);
+  gtk_widget_show(print_type_vb);
 
   /* "Print summary"/"Print detail" radio buttons */
   summary_rb = gtk_radio_button_new_with_label(NULL, "Print summary");
   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(summary_rb), FALSE);
   summary_grp = gtk_radio_button_group(GTK_RADIO_BUTTON(summary_rb));
-  gtk_container_add(GTK_CONTAINER(summary_vb), summary_rb);
+  gtk_container_add(GTK_CONTAINER(print_type_vb), summary_rb);
   gtk_widget_show(summary_rb);
   detail_rb = gtk_radio_button_new_with_label(summary_grp, "Print detail");
   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(detail_rb), TRUE);
   gtk_signal_connect(GTK_OBJECT(detail_rb), "toggled",
                        GTK_SIGNAL_FUNC(print_cmd_toggle_detail), NULL);
-  gtk_container_add(GTK_CONTAINER(summary_vb), detail_rb);
+  gtk_container_add(GTK_CONTAINER(print_type_vb), detail_rb);
   gtk_widget_show(detail_rb);
+  
+  /* "Print hex" check button. */
+  hex_cb = gtk_check_button_new_with_label("Print hex data");
+  gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(hex_cb), FALSE);
+  gtk_container_add(GTK_CONTAINER(print_type_vb), hex_cb);
+  gtk_widget_show(hex_cb);
 
   /* Vertical box into which to put the "Expand all levels"/"Print as displayed"
      radio buttons. */
@@ -256,6 +267,7 @@ file_print_cmd_cb(GtkWidget *widget, gpointer data)
   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);
   gtk_object_set_data(GTK_OBJECT(ok_bt), PRINT_SUMMARY_RB_KEY, summary_rb);
+  gtk_object_set_data(GTK_OBJECT(ok_bt), PRINT_HEX_CB_KEY, hex_cb);
   gtk_object_set_data(GTK_OBJECT(ok_bt), PRINT_EXPAND_ALL_RB_KEY, expand_all_rb);
   gtk_signal_connect(GTK_OBJECT(ok_bt), "clicked",
     GTK_SIGNAL_FUNC(print_ok_cb), GTK_OBJECT(print_w));
@@ -381,6 +393,10 @@ print_ok_cb(GtkWidget *ok_bt, gpointer parent_w)
                                               PRINT_SUMMARY_RB_KEY);
   print_args.print_summary = GTK_TOGGLE_BUTTON (button)->active;
 
+  button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(ok_bt),
+                                              PRINT_HEX_CB_KEY);
+  print_args.print_hex = GTK_TOGGLE_BUTTON (button)->active;
+
   button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(ok_bt),
                                               PRINT_EXPAND_ALL_RB_KEY);
   print_args.expand_all = GTK_TOGGLE_BUTTON (button)->active;
@@ -418,15 +434,20 @@ print_close_cb(GtkWidget *close_bt, gpointer parent_w)
 void
 file_print_packet_cmd_cb(GtkWidget *widget, gpointer data) {
   FILE *fh;
+  print_args_t print_args;
 
   switch (prefs.pr_dest) {
 
   case PR_DEST_CMD:
     fh = popen(prefs.pr_cmd, "w");
+    print_args.to_file = FALSE;
+    print_args.dest = prefs.pr_cmd;
     break;
 
   case PR_DEST_FILE:
     fh = fopen(prefs.pr_file, "w");
+    print_args.to_file = TRUE;
+    print_args.dest = prefs.pr_file;
     break;
 
   default:
@@ -450,8 +471,12 @@ file_print_packet_cmd_cb(GtkWidget *widget, gpointer data) {
   }
 
   print_preamble(fh);
-  proto_tree_print(TRUE, TRUE, (GNode*) cf.protocol_tree, cf.pd, cf.fd, fh);
+  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.fd, fh);
   print_finale(fh);
-  close_print_dest(prefs.pr_dest == PR_DEST_FILE, fh);
+  close_print_dest(print_args.to_file, fh);
 }
 
index 37056f29814e1faaabcd81fe03752023d4d92360..dcf12ec83e14f97fd3963c537a0163fecce03dc1 100644 (file)
--- a/packet.c
+++ b/packet.c
@@ -1,7 +1,7 @@
 /* packet.c
  * Routines for packet disassembly
  *
- * $Id: packet.c,v 1.44 1999/09/18 15:44:41 deniel Exp $
+ * $Id: packet.c,v 1.45 1999/09/29 22:19:12 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -56,6 +56,7 @@
 #endif
 
 #include "packet.h"
+#include "print.h"
 #include "file.h"
 
 extern capture_file  cf;
diff --git a/print.c b/print.c
index 6f7c65904979355f8a774696ecdf9188cf716fe6..fd89b2c2675dc44320e00353cb2a02a683652ac1 100644 (file)
--- a/print.c
+++ b/print.c
@@ -1,7 +1,7 @@
 /* print.c
  * Routines for printing packet analysis trees.
  *
- * $Id: print.c,v 1.20 1999/09/12 20:23:33 guy Exp $
+ * $Id: print.c,v 1.21 1999/09/29 22:19:13 guy Exp $
  *
  * Gilbert Ramirez <gram@verdict.uthscsa.edu>
  *
 #include "ps.h"
 
 static void proto_tree_print_node_text(GNode *node, gpointer data);
-static void dumpit (FILE *fh, register const u_char *cp, register u_int length);
 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 dumpit_ps (FILE *fh, register const u_char *cp, register u_int length);
+static void print_hex_data_ps(FILE *fh, register const u_char *cp, register u_int length);
 
 extern int proto_data; /* in packet-data.c */
 
@@ -57,6 +56,7 @@ typedef struct {
        FILE            *fh;
        const guint8    *pd;
        gboolean        print_all_levels;
+       gboolean        print_hex_for_data;
 } print_data;
 
 FILE *open_print_dest(int to_file, const char *dest)
@@ -93,7 +93,7 @@ void print_finale(FILE *fh)
                print_ps_finale(fh);
 }
 
-void proto_tree_print(gboolean print_one_packet, gboolean print_all_levels,
+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)
 {
        print_data data;
@@ -102,7 +102,10 @@ void proto_tree_print(gboolean print_one_packet, gboolean print_all_levels,
        data.level = 0;
        data.fh = fh;
        data.pd = pd;
-       data.print_all_levels = print_all_levels;
+       data.print_all_levels = print_args->expand_all;
+       data.print_hex_for_data = !print_args->print_hex;
+           /* 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 -
@@ -157,9 +160,10 @@ void proto_tree_print_node_text(GNode *node, gpointer data)
        /* Print the text */
        fprintf(pdata->fh, "%s%s\n", space, label_ptr);
 
-       /* If it's uninterpreted data, dump it. */
-       if (fi->hfinfo->id == proto_data)
-               dumpit(pdata->fh, &pdata->pd[fi->start], fi->length);
+       /* 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);
 
        /* If we're printing all levels, or if this level is expanded,
           recurse into the subtree, if it exists. */
@@ -175,8 +179,7 @@ void proto_tree_print_node_text(GNode *node, gpointer data)
 
 /* This routine was created by Dan Lasley <DLASLEY@PROMUS.com>, and
 only slightly modified for ethereal by Gilbert Ramirez. */
-static
-void dumpit (FILE *fh, register const u_char *cp, register u_int length)
+void print_hex_data(FILE *fh, register const u_char *cp, register u_int length)
 {
         register int ad, i, j, k;
         u_char c;
@@ -239,7 +242,7 @@ void proto_tree_print_node_ps(GNode *node, gpointer data)
        /* If it's uninterpreted data, dump it. */
        if (fi->hfinfo->id == proto_data) {
                print_ps_hex(pdata->fh);
-               dumpit_ps(pdata->fh, &pdata->pd[fi->start], fi->length);
+               print_hex_data_ps(pdata->fh, &pdata->pd[fi->start], fi->length);
        }
 
        /* Recurse into the subtree, if it exists */
@@ -280,7 +283,7 @@ void ps_clean_string(unsigned char *out, const unsigned char *in,
 }
 
 static
-void dumpit_ps (FILE *fh, register const u_char *cp, register u_int length)
+void print_hex_data_ps(FILE *fh, register const u_char *cp, register u_int length)
 {
         register int ad, i, j, k;
         u_char c;
diff --git a/print.h b/print.h
index 64455dd23bc38d200765cfd0951a3a00639d0ec2..3be9128641485fb0003fd1e8442c8c858212f503 100644 (file)
--- a/print.h
+++ b/print.h
@@ -1,7 +1,7 @@
 /* print.h
  * Definitions for printing packet analysis trees.
  *
- * $Id: print.h,v 1.12 1999/09/12 20:23:34 guy Exp $
+ * $Id: print.h,v 1.13 1999/09/29 22:19:13 guy Exp $
  *
  * Gilbert Ramirez <gram@verdict.uthscsa.edu>
  *
 #ifndef __PRINT_H__
 #define __PRINT_H__
 
+typedef struct {
+  gboolean     to_file;        /* TRUE if we're printing to a file */
+  char         *dest;          /* if printing to file, pathname;
+                                  if not, command string */
+  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;
+                                  FALSE if we should print only if not dissected. */
+  gboolean     expand_all;     /* TRUE if we should expand all levels;
+                                  FALSE if we should expand as displayed. */
+} print_args_t;
+
 /* Functions in print.h */
 
 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 proto_tree_print(gboolean print_one_packet, gboolean print_all_levels,
+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,
+    register u_int length);
 
 #endif /* print.h */