2000-08-03 12:44:40 +00:00
|
|
|
/* follow_dlg.c
|
|
|
|
*
|
2004-01-25 01:53:24 +00:00
|
|
|
* $Id: follow_dlg.c,v 1.38 2004/01/25 01:53:24 guy Exp $
|
2000-08-03 12:44:40 +00:00
|
|
|
*
|
|
|
|
* Ethereal - Network traffic analyzer
|
2002-01-11 07:40:32 +00:00
|
|
|
* By Gerald Combs <gerald@ethereal.com>
|
2000-08-03 12:44:40 +00:00
|
|
|
* Copyright 2000 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.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2000-08-03 12:44:40 +00:00
|
|
|
* 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.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2000-08-03 12:44:40 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2002-09-07 10:01:55 +00:00
|
|
|
#include <stdio.h>
|
2000-08-03 12:44:40 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_IO_H
|
2000-08-09 05:18:45 +00:00
|
|
|
#include <io.h> /* open/close on win32 */
|
|
|
|
#endif
|
|
|
|
|
2000-09-12 06:28:02 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
#ifdef NEED_SNPRINTF_H
|
|
|
|
# include "snprintf.h"
|
2000-08-03 12:44:40 +00:00
|
|
|
#endif
|
|
|
|
|
2002-01-18 07:25:22 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
|
2000-11-21 23:54:10 +00:00
|
|
|
#include "color.h"
|
|
|
|
#include "color_utils.h"
|
2000-08-03 12:44:40 +00:00
|
|
|
#include "file.h"
|
|
|
|
#include "follow_dlg.h"
|
|
|
|
#include "follow.h"
|
|
|
|
#include "dlg_utils.h"
|
|
|
|
#include "keys.h"
|
|
|
|
#include "globals.h"
|
|
|
|
#include "gtkglobals.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "simple_dialog.h"
|
2000-08-11 22:18:22 +00:00
|
|
|
#include "packet-ipv6.h"
|
2000-08-03 12:44:40 +00:00
|
|
|
#include "prefs.h"
|
2002-01-21 07:37:49 +00:00
|
|
|
#include <epan/resolv.h>
|
2000-08-03 12:44:40 +00:00
|
|
|
#include "util.h"
|
|
|
|
#include "ui_util.h"
|
2002-01-21 07:37:49 +00:00
|
|
|
#include <epan/epan_dissect.h>
|
2002-09-09 20:39:01 +00:00
|
|
|
#include <epan/filesystem.h>
|
2002-11-10 11:00:29 +00:00
|
|
|
#include "compat_macros.h"
|
2000-08-03 12:44:40 +00:00
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
/* Show Stream */
|
|
|
|
typedef enum {
|
|
|
|
FROM_CLIENT,
|
|
|
|
FROM_SERVER,
|
|
|
|
BOTH_HOSTS
|
|
|
|
} show_stream_t;
|
|
|
|
|
|
|
|
/* Show Type */
|
|
|
|
typedef enum {
|
|
|
|
SHOW_ASCII,
|
|
|
|
SHOW_EBCDIC,
|
2003-03-06 04:23:51 +00:00
|
|
|
SHOW_HEXDUMP,
|
|
|
|
SHOW_CARRAY
|
2000-08-09 05:18:45 +00:00
|
|
|
} show_type_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
show_stream_t show_stream;
|
|
|
|
show_type_t show_type;
|
|
|
|
char data_out_filename[128 + 1];
|
|
|
|
GtkWidget *text;
|
|
|
|
GtkWidget *ascii_bt;
|
|
|
|
GtkWidget *ebcdic_bt;
|
|
|
|
GtkWidget *hexdump_bt;
|
2003-03-06 04:23:51 +00:00
|
|
|
GtkWidget *carray_bt;
|
2000-08-09 05:18:45 +00:00
|
|
|
GtkWidget *follow_save_as_w;
|
2000-08-11 22:18:22 +00:00
|
|
|
gboolean is_ipv6;
|
2003-04-06 22:41:34 +00:00
|
|
|
char *filter_out_filter;
|
|
|
|
GtkWidget *filter_te;
|
|
|
|
GtkWidget *streamwindow;
|
2000-08-09 05:18:45 +00:00
|
|
|
} follow_info_t;
|
|
|
|
|
|
|
|
static void follow_destroy_cb(GtkWidget * win, gpointer data);
|
|
|
|
static void follow_charset_toggle_cb(GtkWidget * w, gpointer parent_w);
|
|
|
|
static void follow_load_text(follow_info_t *follow_info);
|
2003-04-06 22:41:34 +00:00
|
|
|
static void follow_filter_out_stream(GtkWidget * w, gpointer parent_w);
|
2000-08-09 05:18:45 +00:00
|
|
|
static void follow_print_stream(GtkWidget * w, gpointer parent_w);
|
|
|
|
static void follow_save_as_cmd_cb(GtkWidget * w, gpointer data);
|
|
|
|
static void follow_save_as_ok_cb(GtkWidget * w, GtkFileSelection * fs);
|
|
|
|
static void follow_save_as_destroy_cb(GtkWidget * win, gpointer user_data);
|
|
|
|
static void follow_stream_om_both(GtkWidget * w, gpointer data);
|
|
|
|
static void follow_stream_om_client(GtkWidget * w, gpointer data);
|
|
|
|
static void follow_stream_om_server(GtkWidget * w, gpointer data);
|
|
|
|
|
|
|
|
|
2002-02-28 19:35:09 +00:00
|
|
|
extern FILE *data_out_file;
|
2000-08-09 05:18:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define E_FOLLOW_INFO_KEY "follow_info_key"
|
2000-08-03 12:44:40 +00:00
|
|
|
|
2000-09-08 10:59:21 +00:00
|
|
|
/* List of "follow_info_t" structures for all "Follow TCP Stream" windows,
|
|
|
|
so we can redraw them all if the colors or font changes. */
|
|
|
|
static GList *follow_infos;
|
|
|
|
|
|
|
|
/* Add a "follow_info_t" structure to the list. */
|
|
|
|
static void
|
|
|
|
remember_follow_info(follow_info_t *follow_info)
|
|
|
|
{
|
|
|
|
follow_infos = g_list_append(follow_infos, follow_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove a "follow_info_t" structure from the list. */
|
|
|
|
static void
|
|
|
|
forget_follow_info(follow_info_t *follow_info)
|
|
|
|
{
|
|
|
|
follow_infos = g_list_remove(follow_infos, follow_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-03-05 11:56:00 +00:00
|
|
|
follow_redraw(gpointer data, gpointer user_data _U_)
|
2000-09-08 10:59:21 +00:00
|
|
|
{
|
|
|
|
follow_load_text((follow_info_t *)data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Redraw the text in all "Follow TCP Stream" windows. */
|
|
|
|
void
|
|
|
|
follow_redraw_all(void)
|
|
|
|
{
|
|
|
|
g_list_foreach(follow_infos, follow_redraw, NULL);
|
|
|
|
}
|
|
|
|
|
2000-08-03 12:44:40 +00:00
|
|
|
/* Follow the TCP stream, if any, to which the last packet that we called
|
|
|
|
a dissection routine on belongs (this might be the most recently
|
|
|
|
selected packet, or it might be the last packet in the file). */
|
|
|
|
void
|
2002-03-05 11:56:00 +00:00
|
|
|
follow_stream_cb(GtkWidget * w, gpointer data _U_)
|
2000-08-03 12:44:40 +00:00
|
|
|
{
|
2000-08-17 07:56:44 +00:00
|
|
|
GtkWidget *streamwindow, *vbox, *txt_scrollw, *text, *filter_te;
|
2000-08-09 05:18:45 +00:00
|
|
|
GtkWidget *hbox, *button, *radio_bt;
|
|
|
|
GtkWidget *stream_om, *stream_menu, *stream_mi;
|
|
|
|
int tmp_fd;
|
|
|
|
gchar *follow_filter;
|
2003-04-06 22:41:34 +00:00
|
|
|
const gchar *previous_filter;
|
2001-04-02 09:41:56 +00:00
|
|
|
const char *hostname0, *hostname1;
|
2000-08-09 05:18:45 +00:00
|
|
|
char *port0, *port1;
|
|
|
|
char string[128];
|
|
|
|
follow_tcp_stats_t stats;
|
|
|
|
follow_info_t *follow_info;
|
|
|
|
|
|
|
|
/* we got tcp so we can follow */
|
2001-11-21 23:16:26 +00:00
|
|
|
if (cfile.edt->pi.ipproto != 6) {
|
2000-08-09 05:18:45 +00:00
|
|
|
simple_dialog(ESD_TYPE_CRIT, NULL,
|
|
|
|
"Error following stream. Please make\n"
|
|
|
|
"sure you have a TCP packet selected.");
|
|
|
|
return;
|
|
|
|
}
|
2000-08-03 12:44:40 +00:00
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
follow_info = g_new0(follow_info_t, 1);
|
|
|
|
|
|
|
|
/* Create a temporary file into which to dump the reassembled data
|
|
|
|
from the TCP stream, and set "data_out_file" to refer to it, so
|
|
|
|
that the TCP code will write to it.
|
|
|
|
|
|
|
|
XXX - it might be nicer to just have the TCP code directly
|
|
|
|
append stuff to the text widget for the TCP stream window,
|
|
|
|
if we can arrange that said window not pop up until we're
|
|
|
|
done. */
|
|
|
|
tmp_fd = create_tempfile(follow_info->data_out_filename,
|
|
|
|
sizeof follow_info->data_out_filename, "follow");
|
|
|
|
|
|
|
|
if (tmp_fd == -1) {
|
|
|
|
simple_dialog(ESD_TYPE_WARN, NULL,
|
|
|
|
"Could not create temporary file %s: %s",
|
|
|
|
follow_info->data_out_filename, strerror(errno));
|
|
|
|
g_free(follow_info);
|
|
|
|
return;
|
|
|
|
}
|
2000-08-03 12:44:40 +00:00
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
data_out_file = fdopen(tmp_fd, "wb");
|
|
|
|
if (data_out_file == NULL) {
|
|
|
|
simple_dialog(ESD_TYPE_WARN, NULL,
|
|
|
|
"Could not create temporary file %s: %s",
|
|
|
|
follow_info->data_out_filename, strerror(errno));
|
|
|
|
close(tmp_fd);
|
|
|
|
unlink(follow_info->data_out_filename);
|
|
|
|
g_free(follow_info);
|
|
|
|
return;
|
|
|
|
}
|
2000-08-03 12:44:40 +00:00
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
/* Create a new filter that matches all packets in the TCP stream,
|
|
|
|
and set the display filter entry accordingly */
|
|
|
|
reset_tcp_reassembly();
|
2001-11-21 23:16:26 +00:00
|
|
|
follow_filter = build_follow_filter(&cfile.edt->pi);
|
2000-08-03 12:44:40 +00:00
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
/* Set the display filter entry accordingly */
|
2002-11-10 11:00:29 +00:00
|
|
|
filter_te = OBJECT_GET_DATA(w, E_DFILTER_TE_KEY);
|
2003-04-06 22:41:34 +00:00
|
|
|
|
|
|
|
/* needed in follow_filter_out_stream(), is there a better way? */
|
|
|
|
follow_info->filter_te = filter_te;
|
|
|
|
|
|
|
|
/* save previous filter, const since we're not supposed to alter */
|
|
|
|
previous_filter =
|
|
|
|
(const gchar *)gtk_entry_get_text(GTK_ENTRY(filter_te));
|
|
|
|
|
|
|
|
/* allocate our new filter. API claims g_malloc terminates program on failure */
|
|
|
|
/* my calc for max alloc needed is really +10 but when did a few extra bytes hurt ? */
|
|
|
|
follow_info->filter_out_filter =
|
|
|
|
(gchar *)g_malloc(strlen(follow_filter) + strlen(previous_filter) + 16);
|
|
|
|
|
|
|
|
/* append the negation */
|
|
|
|
if(strlen(previous_filter)) {
|
|
|
|
sprintf(follow_info->filter_out_filter, "%s \nand !(%s)", previous_filter, follow_filter);
|
|
|
|
} else {
|
|
|
|
sprintf(follow_info->filter_out_filter, "!(%s)", follow_filter);
|
|
|
|
}
|
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(filter_te), follow_filter);
|
2000-08-03 12:44:40 +00:00
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
/* Run the display filter so it goes in effect. */
|
|
|
|
filter_packets(&cfile, follow_filter);
|
2000-08-03 12:44:40 +00:00
|
|
|
|
Clean up the handling of filter strings:
have "filter_packets()" make a copy of the filter string handed
to it, as it may save the filter string in the "capture_file"
structure, and the caller of "filter_packets()" shouldn't have
to worry about the string it passed to "filter_packets()" being
stashed away somewhere so that it can't just free that string or
change it;
have callers of "filter_packets()" free up the string they
handed to it, if the string was allocated and they're done with
it;
plug some memory leaks in "match_selected_cb_do()".
Check for an illegal "action" argument being passed to
"match_selected_cb_do()".
Move some keys out of "keys.h" into "gtk/main.c", as they're only used
in "gtk/main.c".
Make the pointer to the filter list a data item for the combo box, as
it's a copy of the list of strings for the combo box, rather than
attaching it to the widgets that activate the filter (a pointer to the
combo box *itself* is a data item for those widgets).
In "filter_activate_cb()", make a copy of the text from the text entry
field as soon as we fetch it, and use that copy. Free that copy if
we didn't add the filter to the filter list.
Don't make a copy of the entire filter list and use that to set the
combo box's list of items - just use the list itself. Also, when the
list is changed, make the new value the data for the combo box (the list
pointer will actually not be changed, because we happen to be using
"g_list_append()", but let's not rely on that).
svn path=/trunk/; revision=5368
2002-05-03 03:24:47 +00:00
|
|
|
/* Free the filter string, as we're done with it. */
|
|
|
|
g_free(follow_filter);
|
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
/* The data_out_file should now be full of the streams information */
|
|
|
|
fclose(data_out_file);
|
|
|
|
|
|
|
|
/* The data_out_filename file now has all the text that was in the session */
|
|
|
|
streamwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
2003-04-06 22:41:34 +00:00
|
|
|
|
|
|
|
/* needed in follow_filter_out_stream(), is there a better way? */
|
|
|
|
follow_info->streamwindow = streamwindow;
|
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_widget_set_name(streamwindow, "TCP stream window");
|
|
|
|
|
2002-11-10 11:00:29 +00:00
|
|
|
SIGNAL_CONNECT(streamwindow, "destroy", follow_destroy_cb, NULL);
|
|
|
|
SIGNAL_CONNECT(streamwindow, "realize", window_icon_realize_cb, NULL);
|
2000-08-09 05:18:45 +00:00
|
|
|
if (incomplete_tcp_stream) {
|
|
|
|
gtk_window_set_title(GTK_WINDOW(streamwindow),
|
|
|
|
"Contents of TCP stream (incomplete)");
|
|
|
|
} else {
|
|
|
|
gtk_window_set_title(GTK_WINDOW(streamwindow),
|
|
|
|
"Contents of TCP stream");
|
|
|
|
}
|
2002-11-10 11:00:29 +00:00
|
|
|
WIDGET_SET_SIZE(streamwindow, DEF_WIDTH, DEF_HEIGHT);
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_container_border_width(GTK_CONTAINER(streamwindow), 2);
|
|
|
|
|
|
|
|
/* setup the container */
|
|
|
|
vbox = gtk_vbox_new(FALSE, 0);
|
|
|
|
gtk_container_add(GTK_CONTAINER(streamwindow), vbox);
|
|
|
|
|
|
|
|
/* create a scrolled window for the text */
|
2002-01-11 07:40:32 +00:00
|
|
|
txt_scrollw = scrolled_window_new(NULL, NULL);
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), txt_scrollw, TRUE, TRUE, 0);
|
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scrollw),
|
2002-11-03 17:38:45 +00:00
|
|
|
GTK_POLICY_AUTOMATIC,
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
2000-08-09 05:18:45 +00:00
|
|
|
|
|
|
|
/* create a text box */
|
2002-11-03 17:38:45 +00:00
|
|
|
#if GTK_MAJOR_VERSION < 2
|
2000-08-09 05:18:45 +00:00
|
|
|
text = gtk_text_new(NULL, NULL);
|
|
|
|
gtk_text_set_editable(GTK_TEXT(text), FALSE);
|
2002-11-03 17:38:45 +00:00
|
|
|
#else
|
|
|
|
text = gtk_text_view_new();
|
|
|
|
gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
|
|
|
|
#endif
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(txt_scrollw), text);
|
|
|
|
follow_info->text = text;
|
|
|
|
|
|
|
|
/* Create hbox */
|
|
|
|
hbox = gtk_hbox_new(FALSE, 1);
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
|
|
|
|
/* Stream to show */
|
|
|
|
follow_tcp_stats(&stats);
|
|
|
|
|
2000-08-11 22:18:22 +00:00
|
|
|
if (stats.is_ipv6) {
|
|
|
|
struct e_in6_addr ipaddr;
|
|
|
|
memcpy(&ipaddr, stats.ip_address[0], 16);
|
|
|
|
hostname0 = get_hostname6(&ipaddr);
|
|
|
|
memcpy(&ipaddr, stats.ip_address[0], 16);
|
|
|
|
hostname1 = get_hostname6(&ipaddr);
|
|
|
|
} else {
|
|
|
|
guint32 ipaddr;
|
|
|
|
memcpy(&ipaddr, stats.ip_address[0], 4);
|
|
|
|
hostname0 = get_hostname(ipaddr);
|
|
|
|
memcpy(&ipaddr, stats.ip_address[1], 4);
|
|
|
|
hostname1 = get_hostname(ipaddr);
|
|
|
|
}
|
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
port0 = get_tcp_port(stats.tcp_port[0]);
|
|
|
|
port1 = get_tcp_port(stats.tcp_port[1]);
|
|
|
|
|
2000-08-11 22:18:22 +00:00
|
|
|
follow_info->is_ipv6 = stats.is_ipv6;
|
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
stream_om = gtk_option_menu_new();
|
|
|
|
stream_menu = gtk_menu_new();
|
|
|
|
|
|
|
|
/* Both Hosts */
|
|
|
|
snprintf(string, sizeof(string),
|
|
|
|
"Entire conversation (%u bytes)",
|
|
|
|
stats.bytes_written[0] + stats.bytes_written[1]);
|
|
|
|
stream_mi = gtk_menu_item_new_with_label(string);
|
2002-11-10 11:00:29 +00:00
|
|
|
SIGNAL_CONNECT(stream_mi, "activate", follow_stream_om_both,
|
|
|
|
follow_info);
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_menu_append(GTK_MENU(stream_menu), stream_mi);
|
|
|
|
gtk_widget_show(stream_mi);
|
2000-08-09 05:26:11 +00:00
|
|
|
follow_info->show_stream = BOTH_HOSTS;
|
2000-08-09 05:18:45 +00:00
|
|
|
|
|
|
|
/* Host 0 --> Host 1 */
|
|
|
|
snprintf(string, sizeof(string), "%s:%s --> %s:%s (%u bytes)",
|
|
|
|
hostname0, port0, hostname1, port1,
|
|
|
|
stats.bytes_written[0]);
|
|
|
|
stream_mi = gtk_menu_item_new_with_label(string);
|
2002-11-10 11:00:29 +00:00
|
|
|
SIGNAL_CONNECT(stream_mi, "activate", follow_stream_om_client,
|
|
|
|
follow_info);
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_menu_append(GTK_MENU(stream_menu), stream_mi);
|
|
|
|
gtk_widget_show(stream_mi);
|
|
|
|
|
|
|
|
/* Host 1 --> Host 0 */
|
|
|
|
snprintf(string, sizeof(string), "%s:%s --> %s:%s (%u bytes)",
|
|
|
|
hostname1, port1, hostname0, port0,
|
|
|
|
stats.bytes_written[1]);
|
|
|
|
stream_mi = gtk_menu_item_new_with_label(string);
|
2002-11-10 11:00:29 +00:00
|
|
|
SIGNAL_CONNECT(stream_mi, "activate", follow_stream_om_server,
|
|
|
|
follow_info);
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_menu_append(GTK_MENU(stream_menu), stream_mi);
|
|
|
|
gtk_widget_show(stream_mi);
|
|
|
|
|
|
|
|
gtk_option_menu_set_menu(GTK_OPTION_MENU(stream_om), stream_menu);
|
|
|
|
/* Set history to 0th item, i.e., the first item. */
|
|
|
|
gtk_option_menu_set_history(GTK_OPTION_MENU(stream_om), 0);
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), stream_om, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
/* ASCII radio button */
|
|
|
|
radio_bt = gtk_radio_button_new_with_label(NULL, "ASCII");
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_bt), TRUE);
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), radio_bt, FALSE, FALSE, 0);
|
2002-11-10 11:00:29 +00:00
|
|
|
SIGNAL_CONNECT(radio_bt, "toggled", follow_charset_toggle_cb,
|
|
|
|
follow_info);
|
2000-08-09 05:18:45 +00:00
|
|
|
follow_info->ascii_bt = radio_bt;
|
|
|
|
follow_info->show_type = SHOW_ASCII;
|
|
|
|
|
|
|
|
/* EBCDIC radio button */
|
|
|
|
radio_bt = gtk_radio_button_new_with_label(gtk_radio_button_group
|
|
|
|
(GTK_RADIO_BUTTON(radio_bt)),
|
|
|
|
"EBCDIC");
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_bt), FALSE);
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), radio_bt, FALSE, FALSE, 0);
|
2002-11-10 11:00:29 +00:00
|
|
|
SIGNAL_CONNECT(radio_bt, "toggled", follow_charset_toggle_cb,
|
|
|
|
follow_info);
|
2000-08-09 05:18:45 +00:00
|
|
|
follow_info->ebcdic_bt = radio_bt;
|
|
|
|
|
|
|
|
/* HEX DUMP radio button */
|
|
|
|
radio_bt = gtk_radio_button_new_with_label(gtk_radio_button_group
|
|
|
|
(GTK_RADIO_BUTTON(radio_bt)),
|
|
|
|
"Hex Dump");
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_bt), FALSE);
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), radio_bt, FALSE, FALSE, 0);
|
2002-11-10 11:00:29 +00:00
|
|
|
SIGNAL_CONNECT(radio_bt, "toggled", follow_charset_toggle_cb,
|
|
|
|
follow_info);
|
2000-08-09 05:18:45 +00:00
|
|
|
follow_info->hexdump_bt = radio_bt;
|
|
|
|
|
2003-03-06 04:23:51 +00:00
|
|
|
/* C Array radio button */
|
|
|
|
radio_bt = gtk_radio_button_new_with_label(gtk_radio_button_group
|
|
|
|
(GTK_RADIO_BUTTON(radio_bt)),
|
|
|
|
"C Arrays");
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_bt), FALSE);
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), radio_bt, FALSE, FALSE, 0);
|
|
|
|
SIGNAL_CONNECT(radio_bt, "toggled", follow_charset_toggle_cb,
|
|
|
|
follow_info);
|
|
|
|
follow_info->carray_bt = radio_bt;
|
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
/* Create Close Button */
|
2004-01-10 16:27:43 +00:00
|
|
|
button = BUTTON_NEW_FROM_STOCK(GTK_STOCK_CLOSE);
|
2002-11-10 11:00:29 +00:00
|
|
|
SIGNAL_CONNECT_OBJECT(button, "clicked", gtk_widget_destroy,
|
|
|
|
streamwindow);
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
/* Catch the "key_press_event" signal in the window, so that we can catch
|
|
|
|
the ESC key being pressed and act as if the "Cancel" button had
|
|
|
|
been selected. */
|
|
|
|
dlg_set_cancel(streamwindow, button);
|
|
|
|
|
2003-04-06 22:41:34 +00:00
|
|
|
/* Create exclude stream button */
|
|
|
|
button = gtk_button_new_with_label("Filter out this stream");
|
|
|
|
SIGNAL_CONNECT(button, "clicked", follow_filter_out_stream, follow_info);
|
|
|
|
|
|
|
|
gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
|
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
/* Create Save As Button */
|
2004-01-10 16:27:43 +00:00
|
|
|
button = BUTTON_NEW_FROM_STOCK(GTK_STOCK_SAVE_AS);
|
2002-11-10 11:00:29 +00:00
|
|
|
SIGNAL_CONNECT(button, "clicked", follow_save_as_cmd_cb, follow_info);
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
/* Create Print Button */
|
2004-01-10 16:27:43 +00:00
|
|
|
button = BUTTON_NEW_FROM_STOCK(GTK_STOCK_PRINT);
|
2002-11-10 11:00:29 +00:00
|
|
|
SIGNAL_CONNECT(button, "clicked", follow_print_stream, follow_info);
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
|
|
|
|
/* Tuck away the follow_info object into the window */
|
2002-11-10 11:00:29 +00:00
|
|
|
OBJECT_SET_DATA(streamwindow, E_FOLLOW_INFO_KEY, follow_info);
|
2000-08-09 05:18:45 +00:00
|
|
|
|
|
|
|
follow_load_text(follow_info);
|
2000-09-08 10:59:21 +00:00
|
|
|
remember_follow_info(follow_info);
|
2000-08-09 05:18:45 +00:00
|
|
|
|
|
|
|
data_out_file = NULL;
|
|
|
|
|
|
|
|
/* Make sure this widget gets destroyed if we quit the main loop,
|
|
|
|
so that if we exit, we clean up any temporary files we have
|
|
|
|
for "Follow TCP Stream" windows. */
|
|
|
|
gtk_quit_add_destroy(gtk_main_level(), GTK_OBJECT(streamwindow));
|
|
|
|
gtk_widget_show_all(streamwindow);
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The destroy call back has the responsibility of
|
2003-04-06 22:41:34 +00:00
|
|
|
* unlinking the temporary file
|
|
|
|
* and freeing the filter_out_filter */
|
2000-08-03 12:44:40 +00:00
|
|
|
static void
|
2002-03-05 11:56:00 +00:00
|
|
|
follow_destroy_cb(GtkWidget *w, gpointer data _U_)
|
2000-08-09 05:18:45 +00:00
|
|
|
{
|
|
|
|
follow_info_t *follow_info;
|
|
|
|
|
2002-11-10 11:00:29 +00:00
|
|
|
follow_info = OBJECT_GET_DATA(w, E_FOLLOW_INFO_KEY);
|
2000-08-09 05:18:45 +00:00
|
|
|
unlink(follow_info->data_out_filename);
|
2003-04-06 22:41:34 +00:00
|
|
|
g_free(follow_info->filter_out_filter);
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_widget_destroy(w);
|
2000-09-08 10:59:21 +00:00
|
|
|
forget_follow_info(follow_info);
|
2000-08-09 05:18:45 +00:00
|
|
|
g_free(follow_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX - can I emulate follow_charset_toggle_cb() instead of having
|
|
|
|
* 3 different functions here? */
|
|
|
|
static void
|
2002-03-05 11:56:00 +00:00
|
|
|
follow_stream_om_both(GtkWidget *w _U_, gpointer data)
|
2000-08-09 05:18:45 +00:00
|
|
|
{
|
|
|
|
follow_info_t *follow_info = data;
|
|
|
|
follow_info->show_stream = BOTH_HOSTS;
|
|
|
|
follow_load_text(follow_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-03-05 11:56:00 +00:00
|
|
|
follow_stream_om_client(GtkWidget *w _U_, gpointer data)
|
2000-08-09 05:18:45 +00:00
|
|
|
{
|
|
|
|
follow_info_t *follow_info = data;
|
|
|
|
follow_info->show_stream = FROM_CLIENT;
|
|
|
|
follow_load_text(follow_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-03-05 11:56:00 +00:00
|
|
|
follow_stream_om_server(GtkWidget *w _U_, gpointer data)
|
2000-08-03 12:44:40 +00:00
|
|
|
{
|
2000-08-09 05:18:45 +00:00
|
|
|
follow_info_t *follow_info = data;
|
|
|
|
follow_info->show_stream = FROM_SERVER;
|
|
|
|
follow_load_text(follow_info);
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Handles the ASCII/EBCDIC toggling */
|
|
|
|
static void
|
2002-03-05 11:56:00 +00:00
|
|
|
follow_charset_toggle_cb(GtkWidget * w _U_, gpointer data)
|
2000-08-03 12:44:40 +00:00
|
|
|
{
|
2000-08-09 05:18:45 +00:00
|
|
|
follow_info_t *follow_info = data;
|
|
|
|
|
|
|
|
if (GTK_TOGGLE_BUTTON(follow_info->ebcdic_bt)->active)
|
|
|
|
follow_info->show_type = SHOW_EBCDIC;
|
|
|
|
else if (GTK_TOGGLE_BUTTON(follow_info->hexdump_bt)->active)
|
|
|
|
follow_info->show_type = SHOW_HEXDUMP;
|
2003-03-06 04:23:51 +00:00
|
|
|
else if (GTK_TOGGLE_BUTTON(follow_info->carray_bt)->active)
|
|
|
|
follow_info->show_type = SHOW_CARRAY;
|
2000-08-09 05:18:45 +00:00
|
|
|
else if (GTK_TOGGLE_BUTTON(follow_info->ascii_bt)->active)
|
|
|
|
follow_info->show_type = SHOW_ASCII;
|
|
|
|
else
|
|
|
|
g_assert_not_reached();
|
|
|
|
|
|
|
|
follow_load_text(follow_info);
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define FLT_BUF_SIZE 1024
|
2004-01-25 01:53:24 +00:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
FRS_OK,
|
|
|
|
FRS_OPEN_ERROR,
|
|
|
|
FRS_READ_ERROR,
|
|
|
|
FRS_PRINT_ERROR
|
|
|
|
} frs_return_t;
|
|
|
|
|
|
|
|
static frs_return_t
|
2000-08-09 05:18:45 +00:00
|
|
|
follow_read_stream(follow_info_t *follow_info,
|
2004-01-24 10:53:25 +00:00
|
|
|
gboolean (*print_line) (char *, int, gboolean, void *),
|
2000-08-09 05:18:45 +00:00
|
|
|
void *arg)
|
2000-08-03 12:44:40 +00:00
|
|
|
{
|
2000-08-09 05:18:45 +00:00
|
|
|
tcp_stream_chunk sc;
|
2000-08-11 22:18:22 +00:00
|
|
|
int bcount, iplen;
|
|
|
|
guint8 client_addr[MAX_IPADDR_LEN];
|
2000-08-09 05:18:45 +00:00
|
|
|
guint16 client_port = 0;
|
|
|
|
gboolean is_server;
|
|
|
|
guint16 current_pos, global_client_pos = 0, global_server_pos = 0;
|
|
|
|
guint16 *global_pos;
|
|
|
|
gboolean skip;
|
2003-03-06 04:23:51 +00:00
|
|
|
gchar initbuf[256];
|
|
|
|
guint32 server_packet_count = 0;
|
|
|
|
guint32 client_packet_count = 0;
|
2004-01-25 01:53:24 +00:00
|
|
|
char buffer[FLT_BUF_SIZE];
|
|
|
|
int nchars;
|
2000-08-09 05:18:45 +00:00
|
|
|
|
2000-08-11 22:18:22 +00:00
|
|
|
iplen = (follow_info->is_ipv6) ? 16 : 4;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
data_out_file = fopen(follow_info->data_out_filename, "rb");
|
2004-01-25 01:53:24 +00:00
|
|
|
if (data_out_file == NULL) {
|
|
|
|
simple_dialog(ESD_TYPE_WARN, NULL,
|
|
|
|
"Could not open temporary file %s: %s", follow_info->data_out_filename,
|
|
|
|
strerror(errno));
|
|
|
|
return FRS_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (fread(&sc, 1, sizeof(sc), data_out_file)) {
|
|
|
|
if (client_port == 0) {
|
|
|
|
memcpy(client_addr, sc.src_addr, iplen);
|
|
|
|
client_port = sc.src_port;
|
|
|
|
}
|
|
|
|
skip = FALSE;
|
|
|
|
if (memcmp(client_addr, sc.src_addr, iplen) == 0 &&
|
|
|
|
client_port == sc.src_port) {
|
|
|
|
is_server = FALSE;
|
|
|
|
global_pos = &global_client_pos;
|
|
|
|
if (follow_info->show_stream == FROM_SERVER) {
|
|
|
|
skip = TRUE;
|
2000-08-09 05:18:45 +00:00
|
|
|
}
|
2004-01-25 01:53:24 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
is_server = TRUE;
|
|
|
|
global_pos = &global_server_pos;
|
|
|
|
if (follow_info->show_stream == FROM_CLIENT) {
|
|
|
|
skip = TRUE;
|
2000-08-09 05:18:45 +00:00
|
|
|
}
|
2004-01-25 01:53:24 +00:00
|
|
|
}
|
2000-08-09 05:18:45 +00:00
|
|
|
|
2004-01-25 01:53:24 +00:00
|
|
|
while (sc.dlen > 0) {
|
|
|
|
bcount = (sc.dlen < FLT_BUF_SIZE) ? sc.dlen : FLT_BUF_SIZE;
|
|
|
|
nchars = fread(buffer, 1, bcount, data_out_file);
|
|
|
|
if (nchars == 0)
|
|
|
|
break;
|
|
|
|
sc.dlen -= bcount;
|
|
|
|
if (!skip) {
|
|
|
|
switch (follow_info->show_type) {
|
|
|
|
|
|
|
|
case SHOW_EBCDIC:
|
|
|
|
/* If our native arch is ASCII, call: */
|
|
|
|
EBCDIC_to_ASCII(buffer, nchars);
|
|
|
|
if (!(*print_line) (buffer, nchars, is_server, arg))
|
|
|
|
goto print_error;
|
2000-08-09 05:18:45 +00:00
|
|
|
break;
|
2002-01-18 07:25:22 +00:00
|
|
|
|
2004-01-25 01:53:24 +00:00
|
|
|
case SHOW_ASCII:
|
|
|
|
/* If our native arch is EBCDIC, call:
|
|
|
|
* ASCII_TO_EBCDIC(buffer, nchars);
|
|
|
|
*/
|
|
|
|
if (!(*print_line) (buffer, nchars, is_server, arg))
|
|
|
|
goto print_error;
|
|
|
|
break;
|
2003-03-06 04:23:51 +00:00
|
|
|
|
2004-01-25 01:53:24 +00:00
|
|
|
case SHOW_HEXDUMP:
|
|
|
|
current_pos = 0;
|
|
|
|
while (current_pos < nchars) {
|
|
|
|
gchar hexbuf[256];
|
|
|
|
gchar hexchars[] = "0123456789abcdef";
|
|
|
|
int i, cur;
|
|
|
|
|
|
|
|
/* is_server indentation : put 63 spaces at the
|
|
|
|
* beginning of the string */
|
|
|
|
sprintf(hexbuf, (is_server &&
|
|
|
|
follow_info->show_stream == BOTH_HOSTS) ?
|
|
|
|
" "
|
|
|
|
" %08X " :
|
|
|
|
"%08X ", *global_pos);
|
|
|
|
cur = strlen(hexbuf);
|
|
|
|
for (i = 0; i < 16 && current_pos + i < nchars; i++) {
|
|
|
|
hexbuf[cur++] =
|
|
|
|
hexchars[(buffer[current_pos + i] & 0xf0) >> 4];
|
|
|
|
hexbuf[cur++] =
|
|
|
|
hexchars[buffer[current_pos + i] & 0x0f];
|
|
|
|
if (i == 7) {
|
|
|
|
hexbuf[cur++] = ' ';
|
|
|
|
hexbuf[cur++] = ' ';
|
|
|
|
} else if (i != 15)
|
|
|
|
hexbuf[cur++] = ' ';
|
|
|
|
}
|
|
|
|
/* Fill it up if column isn't complete */
|
|
|
|
if (i < 16) {
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = i; j < 16; j++) {
|
|
|
|
if (j == 7)
|
2003-03-06 04:23:51 +00:00
|
|
|
hexbuf[cur++] = ' ';
|
2004-01-25 01:53:24 +00:00
|
|
|
hexbuf[cur++] = ' ';
|
|
|
|
hexbuf[cur++] = ' ';
|
|
|
|
hexbuf[cur++] = ' ';
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
hexbuf[cur++] = ' ';
|
|
|
|
|
|
|
|
/* Now dump bytes as text */
|
|
|
|
for (i = 0; i < 16 && current_pos + i < nchars; i++) {
|
|
|
|
hexbuf[cur++] =
|
|
|
|
(isprint((guchar)buffer[current_pos + i]) ?
|
|
|
|
buffer[current_pos + i] : '.' );
|
|
|
|
if (i == 7) {
|
|
|
|
hexbuf[cur++] = ' ';
|
2003-03-06 04:23:51 +00:00
|
|
|
}
|
2004-01-25 01:53:24 +00:00
|
|
|
}
|
|
|
|
current_pos += i;
|
|
|
|
(*global_pos) += i;
|
|
|
|
hexbuf[cur++] = '\n';
|
|
|
|
hexbuf[cur] = 0;
|
|
|
|
if (!(*print_line) (hexbuf, strlen(hexbuf), is_server, arg))
|
|
|
|
goto print_error;
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
2004-01-25 01:53:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHOW_CARRAY:
|
|
|
|
current_pos = 0;
|
|
|
|
sprintf(initbuf, "char peer%d_%d[] = {\n", is_server ? 1 : 0,
|
|
|
|
is_server ? server_packet_count++ : client_packet_count++);
|
|
|
|
if (!(*print_line) (initbuf, strlen(initbuf), is_server, arg))
|
|
|
|
goto print_error;
|
|
|
|
while (current_pos < nchars) {
|
|
|
|
gchar hexbuf[256];
|
|
|
|
gchar hexchars[] = "0123456789abcdef";
|
|
|
|
int i, cur;
|
|
|
|
|
|
|
|
cur = 0;
|
|
|
|
for (i = 0; i < 8 && current_pos + i < nchars; i++) {
|
|
|
|
/* Prepend entries with "0x" */
|
|
|
|
hexbuf[cur++] = '0';
|
|
|
|
hexbuf[cur++] = 'x';
|
|
|
|
hexbuf[cur++] =
|
|
|
|
hexchars[(buffer[current_pos + i] & 0xf0) >> 4];
|
|
|
|
hexbuf[cur++] =
|
|
|
|
hexchars[buffer[current_pos + i] & 0x0f];
|
|
|
|
|
|
|
|
/* Delimit array entries with a comma */
|
|
|
|
if (current_pos + i + 1 < nchars)
|
|
|
|
hexbuf[cur++] = ',';
|
|
|
|
|
|
|
|
hexbuf[cur++] = ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Terminate the array if we are at the end */
|
|
|
|
if (current_pos + i == nchars) {
|
|
|
|
hexbuf[cur++] = '}';
|
|
|
|
hexbuf[cur++] = ';';
|
|
|
|
}
|
|
|
|
|
|
|
|
current_pos += i;
|
|
|
|
(*global_pos) += i;
|
|
|
|
hexbuf[cur++] = '\n';
|
|
|
|
hexbuf[cur] = 0;
|
|
|
|
if (!(*print_line) (hexbuf, strlen(hexbuf), is_server, arg))
|
|
|
|
goto print_error;
|
|
|
|
}
|
|
|
|
break;
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
2000-08-09 05:18:45 +00:00
|
|
|
}
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
2004-01-25 01:53:24 +00:00
|
|
|
}
|
|
|
|
if (ferror(data_out_file)) {
|
2000-08-09 05:18:45 +00:00
|
|
|
simple_dialog(ESD_TYPE_WARN, NULL,
|
2004-01-25 01:53:24 +00:00
|
|
|
"Error reading temporary file %s: %s", follow_info->data_out_filename,
|
2000-08-09 05:18:45 +00:00
|
|
|
strerror(errno));
|
2004-01-25 01:53:24 +00:00
|
|
|
fclose(data_out_file);
|
|
|
|
data_out_file = NULL;
|
|
|
|
return FRS_READ_ERROR;
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
2004-01-25 01:53:24 +00:00
|
|
|
|
|
|
|
return FRS_OK;
|
|
|
|
|
|
|
|
print_error:
|
|
|
|
fclose(data_out_file);
|
|
|
|
data_out_file = NULL;
|
|
|
|
return FRS_PRINT_ERROR;
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX - for text printing, we probably want to wrap lines at 80 characters;
|
|
|
|
* for PostScript printing, we probably want to wrap them at the appropriate
|
|
|
|
* width, and perhaps put some kind of dingbat (to use the technical term)
|
|
|
|
* to indicate a wrapped line, along the lines of what's done when displaying
|
|
|
|
* this in a window, as per Warren Young's suggestion.
|
|
|
|
*
|
|
|
|
* For now, we support only text printing.
|
|
|
|
*/
|
2004-01-24 10:53:25 +00:00
|
|
|
static gboolean
|
2002-03-05 11:56:00 +00:00
|
|
|
follow_print_text(char *buffer, int nchars, gboolean is_server _U_, void *arg)
|
2000-08-03 12:44:40 +00:00
|
|
|
{
|
2004-01-25 01:53:24 +00:00
|
|
|
FILE *fh = arg;
|
|
|
|
|
|
|
|
if (fwrite(buffer, nchars, 1, fh) != 1)
|
2004-01-24 10:53:25 +00:00
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
|
|
|
|
2003-04-06 22:41:34 +00:00
|
|
|
static void
|
|
|
|
follow_filter_out_stream(GtkWidget * w _U_, gpointer data)
|
|
|
|
{
|
|
|
|
follow_info_t *follow_info = data;
|
|
|
|
|
|
|
|
/* Lock out user from messing with us. (ie. don't free our data!) */
|
|
|
|
gtk_widget_set_sensitive(follow_info->streamwindow, FALSE);
|
|
|
|
|
|
|
|
/* Set the display filter. */
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(follow_info->filter_te), follow_info->filter_out_filter);
|
|
|
|
|
|
|
|
/* Run the display filter so it goes in effect. */
|
|
|
|
filter_packets(&cfile, follow_info->filter_out_filter);
|
|
|
|
|
|
|
|
/* we force a subsequent close */
|
|
|
|
gtk_widget_destroy(follow_info->streamwindow);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-08-03 12:44:40 +00:00
|
|
|
static void
|
2002-03-05 11:56:00 +00:00
|
|
|
follow_print_stream(GtkWidget * w _U_, gpointer data)
|
2000-08-03 12:44:40 +00:00
|
|
|
{
|
2000-08-09 05:18:45 +00:00
|
|
|
FILE *fh;
|
|
|
|
gboolean to_file;
|
|
|
|
char *print_dest;
|
|
|
|
follow_info_t *follow_info = data;
|
|
|
|
|
|
|
|
switch (prefs.pr_dest) {
|
|
|
|
case PR_DEST_CMD:
|
|
|
|
print_dest = prefs.pr_cmd;
|
|
|
|
to_file = FALSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PR_DEST_FILE:
|
|
|
|
print_dest = prefs.pr_file;
|
|
|
|
to_file = TRUE;
|
|
|
|
break;
|
|
|
|
default: /* "Can't happen" */
|
|
|
|
simple_dialog(ESD_TYPE_CRIT, NULL,
|
|
|
|
"Couldn't figure out where to send the print "
|
|
|
|
"job. Check your preferences.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fh = open_print_dest(to_file, print_dest);
|
|
|
|
if (fh == NULL) {
|
2004-01-24 10:53:25 +00:00
|
|
|
if (to_file) {
|
2004-01-25 01:53:24 +00:00
|
|
|
simple_dialog(ESD_TYPE_CRIT, NULL,
|
|
|
|
file_open_error_message(errno, TRUE), prefs.pr_file);
|
2004-01-24 10:53:25 +00:00
|
|
|
} else {
|
2004-01-25 01:53:24 +00:00
|
|
|
simple_dialog(ESD_TYPE_CRIT, NULL,
|
2000-08-09 05:18:45 +00:00
|
|
|
"Couldn't run print command %s.", prefs.pr_cmd);
|
2004-01-24 10:53:25 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2000-08-09 05:18:45 +00:00
|
|
|
|
2004-01-25 00:58:13 +00:00
|
|
|
print_preamble(fh, PR_FMT_TEXT);
|
2004-01-25 01:53:24 +00:00
|
|
|
if (ferror(fh))
|
|
|
|
goto print_error;
|
|
|
|
switch (follow_read_stream(follow_info, follow_print_text, fh)) {
|
|
|
|
|
|
|
|
case FRS_OK:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FRS_OPEN_ERROR:
|
|
|
|
case FRS_READ_ERROR:
|
2004-01-24 10:53:25 +00:00
|
|
|
/* XXX - cancel printing? */
|
|
|
|
close_print_dest(to_file, fh);
|
2000-08-09 05:18:45 +00:00
|
|
|
return;
|
2004-01-25 01:53:24 +00:00
|
|
|
|
|
|
|
case FRS_PRINT_ERROR:
|
|
|
|
goto print_error;
|
2000-08-09 05:18:45 +00:00
|
|
|
}
|
2004-01-25 00:58:13 +00:00
|
|
|
print_finale(fh, PR_FMT_TEXT);
|
2004-01-25 01:53:24 +00:00
|
|
|
if (ferror(fh))
|
|
|
|
goto print_error;
|
2004-01-24 10:53:25 +00:00
|
|
|
if (!close_print_dest(to_file, fh)) {
|
|
|
|
if (to_file) {
|
2004-01-25 01:53:24 +00:00
|
|
|
simple_dialog(ESD_TYPE_CRIT, NULL,
|
2004-01-24 10:53:25 +00:00
|
|
|
file_write_error_message(errno), prefs.pr_file);
|
|
|
|
} else {
|
2004-01-25 01:53:24 +00:00
|
|
|
simple_dialog(ESD_TYPE_CRIT, NULL,
|
2004-01-24 10:53:25 +00:00
|
|
|
"Error closing print destination.");
|
|
|
|
}
|
|
|
|
}
|
2004-01-25 01:53:24 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
print_error:
|
|
|
|
if (to_file) {
|
|
|
|
simple_dialog(ESD_TYPE_CRIT, NULL,
|
|
|
|
file_write_error_message(errno), prefs.pr_file);
|
|
|
|
} else {
|
|
|
|
simple_dialog(ESD_TYPE_CRIT, NULL,
|
|
|
|
"Error writing to print command: %s", strerror(errno));
|
|
|
|
}
|
|
|
|
/* XXX - cancel printing? */
|
|
|
|
close_print_dest(to_file, fh);
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
|
|
|
|
2004-01-24 10:53:25 +00:00
|
|
|
static gboolean
|
2000-08-09 05:18:45 +00:00
|
|
|
follow_add_to_gtk_text(char *buffer, int nchars, gboolean is_server,
|
|
|
|
void *arg)
|
2000-08-03 12:44:40 +00:00
|
|
|
{
|
2000-08-09 05:18:45 +00:00
|
|
|
GtkWidget *text = arg;
|
2000-11-21 23:54:10 +00:00
|
|
|
GdkColor fg, bg;
|
2002-11-03 17:38:45 +00:00
|
|
|
#if GTK_MAJOR_VERSION >= 2
|
|
|
|
GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
|
|
|
|
GtkTextIter iter;
|
|
|
|
GtkTextTag *tag;
|
|
|
|
gsize outbytes;
|
|
|
|
gchar *convbuf;
|
|
|
|
#endif
|
2000-08-09 05:18:45 +00:00
|
|
|
|
2003-12-24 01:21:32 +00:00
|
|
|
#if GTK_MAJOR_VERSION >= 2 || GTK_MINOR_VERSION >= 3
|
2001-04-10 12:07:40 +00:00
|
|
|
/* While our isprint() hack is in place, we
|
|
|
|
* have to use convert some chars to '.' in order
|
|
|
|
* to be able to see the data we *should* see
|
|
|
|
* in the GtkText widget.
|
|
|
|
*/
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < nchars; i++) {
|
2003-12-24 01:21:32 +00:00
|
|
|
if (buffer[i] == '\n' || buffer[i] == '\r')
|
2002-11-03 17:38:45 +00:00
|
|
|
continue;
|
|
|
|
if (! isprint(buffer[i])) {
|
|
|
|
buffer[i] = '.';
|
|
|
|
}
|
|
|
|
}
|
2001-04-10 12:07:40 +00:00
|
|
|
#endif
|
|
|
|
|
2000-11-21 23:54:10 +00:00
|
|
|
if (is_server) {
|
|
|
|
color_t_to_gdkcolor(&fg, &prefs.st_server_fg);
|
|
|
|
color_t_to_gdkcolor(&bg, &prefs.st_server_bg);
|
|
|
|
} else {
|
|
|
|
color_t_to_gdkcolor(&fg, &prefs.st_client_fg);
|
|
|
|
color_t_to_gdkcolor(&bg, &prefs.st_client_bg);
|
|
|
|
}
|
2002-11-03 17:38:45 +00:00
|
|
|
#if GTK_MAJOR_VERSION < 2
|
2000-11-21 23:54:10 +00:00
|
|
|
gtk_text_insert(GTK_TEXT(text), m_r_font, &fg, &bg, buffer, nchars);
|
2002-11-03 17:38:45 +00:00
|
|
|
#else
|
|
|
|
gtk_text_buffer_get_end_iter(buf, &iter);
|
|
|
|
tag = gtk_text_buffer_create_tag(buf, NULL, "foreground-gdk", &fg,
|
|
|
|
"background-gdk", &bg, "font-desc",
|
|
|
|
m_r_font, NULL);
|
|
|
|
convbuf = g_locale_to_utf8(buffer, nchars, NULL, &outbytes, NULL);
|
|
|
|
gtk_text_buffer_insert_with_tags(buf, &iter, convbuf, outbytes, tag,
|
|
|
|
NULL);
|
|
|
|
g_free(convbuf);
|
|
|
|
#endif
|
2004-01-24 10:53:25 +00:00
|
|
|
return TRUE;
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-08-09 05:18:45 +00:00
|
|
|
follow_load_text(follow_info_t *follow_info)
|
2000-08-03 12:44:40 +00:00
|
|
|
{
|
2002-11-03 17:38:45 +00:00
|
|
|
#if GTK_MAJOR_VERSION < 2
|
2000-08-09 05:18:45 +00:00
|
|
|
int bytes_already;
|
2002-11-03 17:38:45 +00:00
|
|
|
#else
|
|
|
|
GtkTextBuffer *buf;
|
|
|
|
|
|
|
|
buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(follow_info->text));
|
|
|
|
#endif
|
2000-08-09 05:18:45 +00:00
|
|
|
|
|
|
|
/* Delete any info already in text box */
|
2002-11-03 17:38:45 +00:00
|
|
|
#if GTK_MAJOR_VERSION < 2
|
2000-08-09 05:18:45 +00:00
|
|
|
bytes_already = gtk_text_get_length(GTK_TEXT(follow_info->text));
|
|
|
|
if (bytes_already > 0) {
|
|
|
|
gtk_text_set_point(GTK_TEXT(follow_info->text), 0);
|
|
|
|
gtk_text_forward_delete(GTK_TEXT(follow_info->text), bytes_already);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* stop the updates while we fill the text box */
|
|
|
|
gtk_text_freeze(GTK_TEXT(follow_info->text));
|
2002-11-03 17:38:45 +00:00
|
|
|
#else
|
|
|
|
gtk_text_buffer_set_text(buf, "", -1);
|
|
|
|
#endif
|
2000-08-09 05:18:45 +00:00
|
|
|
follow_read_stream(follow_info, follow_add_to_gtk_text, follow_info->text);
|
2002-11-03 17:38:45 +00:00
|
|
|
#if GTK_MAJOR_VERSION < 2
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_text_thaw(GTK_TEXT(follow_info->text));
|
2002-11-03 17:38:45 +00:00
|
|
|
#endif
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
|
2000-08-03 12:44:40 +00:00
|
|
|
/*
|
|
|
|
* Keep a static pointer to the current "Save TCP Follow Stream As" window, if
|
|
|
|
* any, so that if somebody tries to do "Save"
|
|
|
|
* while there's already a "Save TCP Follow Stream" window up, we just pop
|
|
|
|
* up the existing one, rather than creating a new one.
|
|
|
|
*/
|
|
|
|
static void
|
2002-03-05 11:56:00 +00:00
|
|
|
follow_save_as_cmd_cb(GtkWidget *w _U_, gpointer data)
|
2000-08-03 12:44:40 +00:00
|
|
|
{
|
2000-08-09 05:18:45 +00:00
|
|
|
GtkWidget *ok_bt, *new_win;
|
|
|
|
follow_info_t *follow_info = data;
|
|
|
|
|
|
|
|
if (follow_info->follow_save_as_w != NULL) {
|
|
|
|
/* There's already a dialog box; reactivate it. */
|
|
|
|
reactivate_window(follow_info->follow_save_as_w);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_win = gtk_file_selection_new("Ethereal: Save TCP Follow Stream As");
|
|
|
|
follow_info->follow_save_as_w = new_win;
|
2002-11-10 11:00:29 +00:00
|
|
|
SIGNAL_CONNECT(new_win, "destroy", follow_save_as_destroy_cb, follow_info);
|
2000-08-09 05:18:45 +00:00
|
|
|
|
|
|
|
/* Tuck away the follow_info object into the window */
|
2002-11-10 11:00:29 +00:00
|
|
|
OBJECT_SET_DATA(new_win, E_FOLLOW_INFO_KEY, follow_info);
|
2000-08-09 05:18:45 +00:00
|
|
|
|
|
|
|
/* If we've opened a file, start out by showing the files in the directory
|
|
|
|
in which that file resided. */
|
|
|
|
if (last_open_dir)
|
2002-09-09 20:39:01 +00:00
|
|
|
gtk_file_selection_set_filename(GTK_FILE_SELECTION(new_win),
|
2000-08-09 05:18:45 +00:00
|
|
|
last_open_dir);
|
|
|
|
|
|
|
|
/* Connect the ok_button to file_save_as_ok_cb function and pass along a
|
|
|
|
pointer to the file selection box widget */
|
|
|
|
ok_bt = GTK_FILE_SELECTION(new_win)->ok_button;
|
2002-11-10 11:00:29 +00:00
|
|
|
SIGNAL_CONNECT(ok_bt, "clicked", follow_save_as_ok_cb, new_win);
|
2000-08-09 05:18:45 +00:00
|
|
|
|
|
|
|
/* Connect the cancel_button to destroy the widget */
|
2002-11-10 11:00:29 +00:00
|
|
|
SIGNAL_CONNECT_OBJECT(GTK_FILE_SELECTION(new_win)->cancel_button, "clicked",
|
|
|
|
gtk_widget_destroy, new_win);
|
2000-08-09 05:18:45 +00:00
|
|
|
|
|
|
|
/* Catch the "key_press_event" signal in the window, so that we can catch
|
|
|
|
the ESC key being pressed and act as if the "Cancel" button had
|
|
|
|
been selected. */
|
|
|
|
dlg_set_cancel(new_win,
|
|
|
|
GTK_FILE_SELECTION(new_win)->cancel_button);
|
|
|
|
|
|
|
|
gtk_file_selection_set_filename(GTK_FILE_SELECTION(new_win), "");
|
|
|
|
gtk_widget_show_all(new_win);
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
|
2000-08-03 12:44:40 +00:00
|
|
|
static void
|
2002-03-05 11:56:00 +00:00
|
|
|
follow_save_as_ok_cb(GtkWidget * w _U_, GtkFileSelection * fs)
|
2000-08-03 12:44:40 +00:00
|
|
|
{
|
2000-08-09 05:18:45 +00:00
|
|
|
gchar *to_name;
|
|
|
|
follow_info_t *follow_info;
|
|
|
|
FILE *fh;
|
2002-09-09 20:39:01 +00:00
|
|
|
gchar *dirname;
|
2000-08-03 12:44:40 +00:00
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
to_name = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(fs)));
|
2000-08-03 12:44:40 +00:00
|
|
|
|
2002-09-09 20:39:01 +00:00
|
|
|
/* Perhaps the user specified a directory instead of a file.
|
|
|
|
Check whether they did. */
|
|
|
|
if (test_for_directory(to_name) == EISDIR) {
|
|
|
|
/* It's a directory - set the file selection box to display that
|
|
|
|
directory, and leave the selection box displayed. */
|
|
|
|
set_last_open_dir(to_name);
|
|
|
|
g_free(to_name);
|
|
|
|
gtk_file_selection_set_filename(GTK_FILE_SELECTION(fs),
|
|
|
|
last_open_dir);
|
|
|
|
return;
|
|
|
|
}
|
2000-08-03 12:44:40 +00:00
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
fh = fopen(to_name, "wb");
|
|
|
|
if (fh == NULL) {
|
|
|
|
simple_dialog(ESD_TYPE_WARN, NULL,
|
2004-01-24 02:01:44 +00:00
|
|
|
file_open_error_message(errno, TRUE), to_name);
|
2002-09-09 20:39:01 +00:00
|
|
|
g_free(to_name);
|
2000-08-09 05:18:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-09-09 20:39:01 +00:00
|
|
|
gtk_widget_hide(GTK_WIDGET(fs));
|
2002-11-10 11:00:29 +00:00
|
|
|
follow_info = OBJECT_GET_DATA(fs, E_FOLLOW_INFO_KEY);
|
2002-09-09 20:39:01 +00:00
|
|
|
gtk_widget_destroy(GTK_WIDGET(fs));
|
|
|
|
|
2004-01-25 01:53:24 +00:00
|
|
|
switch (follow_read_stream(follow_info, follow_print_text, fh)) {
|
|
|
|
|
|
|
|
case FRS_OK:
|
|
|
|
if (fclose(fh) == EOF) {
|
|
|
|
simple_dialog(ESD_TYPE_WARN, NULL,
|
|
|
|
file_write_error_message(errno), to_name);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FRS_OPEN_ERROR:
|
|
|
|
case FRS_READ_ERROR:
|
|
|
|
fclose(fh);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FRS_PRINT_ERROR:
|
|
|
|
simple_dialog(ESD_TYPE_WARN, NULL,
|
|
|
|
file_write_error_message(errno), to_name);
|
|
|
|
fclose(fh);
|
|
|
|
break;
|
2004-01-24 10:53:25 +00:00
|
|
|
}
|
2002-09-09 20:39:01 +00:00
|
|
|
|
|
|
|
/* Save the directory name for future file dialogs. */
|
|
|
|
dirname = get_dirname(to_name); /* Overwrites to_name */
|
|
|
|
set_last_open_dir(dirname);
|
2000-08-09 05:18:45 +00:00
|
|
|
g_free(to_name);
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-03-05 11:56:00 +00:00
|
|
|
follow_save_as_destroy_cb(GtkWidget * win _U_, gpointer data)
|
2000-08-03 12:44:40 +00:00
|
|
|
{
|
2000-08-09 05:18:45 +00:00
|
|
|
follow_info_t *follow_info = data;
|
|
|
|
|
|
|
|
/* Note that we no longer have a dialog box. */
|
|
|
|
follow_info->follow_save_as_w = NULL;
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|