Capturing packets from ethereal now saves the capture in an "anonymous" buffer. That is, it's

a random name chosen by tempnam(), unknown to the user. If the user decides to save that
trace, he then uses File | Save to save it to a file. File | Save As lets him make a copy
of his named trace file as well. I also updated my e-mail address in the various credit
locations.

svn path=/trunk/; revision=242
This commit is contained in:
Gilbert Ramirez 1999-04-06 16:24:50 +00:00
parent bad78f629a
commit 2870ce29ce
12 changed files with 323 additions and 107 deletions

View File

@ -5,7 +5,7 @@ Gerald Combs <gerald@zing.org>
Contributors
------------
Gilbert Ramirez Jr. <gram@verdict.uthscsa.edu> {
Gilbert Ramirez <gramirez@tivoli.com> {
http://verdict.uthscsa.edu/gram/
Wiretap

View File

@ -1,7 +1,7 @@
/* capture.c
* Routines for packet capture windows
*
* $Id: capture.c,v 1.20 1999/02/11 07:11:45 guy Exp $
* $Id: capture.c,v 1.21 1999/04/06 16:24:47 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -36,6 +36,7 @@
#include <pcap.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
@ -59,6 +60,7 @@
#include "ethereal.h"
#include "packet.h"
#include "file.h"
#include "menu.h"
#include "capture.h"
#include "etypes.h"
#include "util.h"
@ -75,7 +77,6 @@ extern guint file_ctx;
/* Capture callback data keys */
#define E_CAP_IFACE_KEY "cap_iface"
#define E_CAP_FILT_KEY "cap_filter"
#define E_CAP_FILE_KEY "cap_file"
#define E_CAP_COUNT_KEY "cap_count"
#define E_CAP_OPEN_KEY "cap_open"
#define E_CAP_SNAP_KEY "cap_snap"
@ -141,10 +142,10 @@ get_interface_list() {
void
capture_prep_cb(GtkWidget *w, gpointer d) {
GtkWidget *cap_open_w, *if_cb, *if_lb, *file_te, *file_bt,
GtkWidget *cap_open_w, *if_cb, *if_lb,
*count_lb, *count_cb, *main_vb, *if_hb, *count_hb,
*filter_hb, *filter_bt, *filter_te, *file_hb, *caplen_hb,
*bbox, *ok_bt, *cancel_bt, *capfile_ck, *snap_lb,
*filter_hb, *filter_bt, *filter_te, *caplen_hb,
*bbox, *ok_bt, *cancel_bt, *snap_lb,
*snap_sb;
GtkAdjustment *adj;
GList *if_list, *count_list = NULL;
@ -223,35 +224,12 @@ capture_prep_cb(GtkWidget *w, gpointer d) {
gtk_object_set_data(GTK_OBJECT(filter_bt), E_FILT_TE_PTR_KEY, filter_te);
gtk_box_pack_start(GTK_BOX(filter_hb), filter_te, TRUE, TRUE, 0);
gtk_widget_show(filter_te);
/* File row: File: button and text entry */
file_hb = gtk_hbox_new(FALSE, 3);
gtk_container_add(GTK_CONTAINER(main_vb), file_hb);
gtk_widget_show(file_hb);
file_bt = gtk_button_new_with_label("File:");
gtk_box_pack_start(GTK_BOX(file_hb), file_bt, FALSE, FALSE, 0);
gtk_widget_show(file_bt);
file_te = gtk_entry_new();
if (cf.save_file)
gtk_entry_set_text(GTK_ENTRY(file_te), cf.save_file);
gtk_box_pack_start(GTK_BOX(file_hb), file_te, TRUE, TRUE, 0);
gtk_widget_show(file_te);
gtk_signal_connect_object(GTK_OBJECT(file_bt), "clicked",
GTK_SIGNAL_FUNC(capture_prep_file_cb), GTK_OBJECT(file_te));
/* Misc row: Capture file checkbox and snap spinbutton */
caplen_hb = gtk_hbox_new(FALSE, 3);
gtk_container_add(GTK_CONTAINER(main_vb), caplen_hb);
gtk_widget_show(caplen_hb);
capfile_ck = gtk_check_button_new_with_label("Open file after capture");
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(capfile_ck), TRUE);
gtk_box_pack_start(GTK_BOX(caplen_hb), capfile_ck, FALSE, FALSE, 3);
gtk_widget_show(capfile_ck);
snap_lb = gtk_label_new("Capture length");
gtk_misc_set_alignment(GTK_MISC(snap_lb), 0, 0.5);
gtk_box_pack_start(GTK_BOX(caplen_hb), snap_lb, FALSE, FALSE, 6);
@ -290,9 +268,7 @@ capture_prep_cb(GtkWidget *w, gpointer d) {
/* Attach pointers to needed widgets to the capture prefs window/object */
gtk_object_set_data(GTK_OBJECT(cap_open_w), E_CAP_IFACE_KEY, if_cb);
gtk_object_set_data(GTK_OBJECT(cap_open_w), E_CAP_FILT_KEY, filter_te);
gtk_object_set_data(GTK_OBJECT(cap_open_w), E_CAP_FILE_KEY, file_te);
gtk_object_set_data(GTK_OBJECT(cap_open_w), E_CAP_COUNT_KEY, count_cb);
gtk_object_set_data(GTK_OBJECT(cap_open_w), E_CAP_OPEN_KEY, capfile_ck);
gtk_object_set_data(GTK_OBJECT(cap_open_w), E_CAP_SNAP_KEY, snap_sb);
gtk_widget_show(cap_open_w);
@ -340,29 +316,28 @@ cap_prep_fs_cancel_cb(GtkWidget *w, gpointer data) {
void
capture_prep_ok_cb(GtkWidget *w, gpointer data) {
GtkWidget *if_cb, *filter_te, *file_te, *count_cb, *open_ck, *snap_sb;
gint open;
GtkWidget *if_cb, *filter_te, *count_cb, *snap_sb;
gchar *filter_text;
#ifdef GTK_HAVE_FEATURES_1_1_0
data = w;
#endif
if_cb = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(data), E_CAP_IFACE_KEY);
filter_te = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(data), E_CAP_FILT_KEY);
file_te = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(data), E_CAP_FILE_KEY);
count_cb = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(data), E_CAP_COUNT_KEY);
open_ck = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(data), E_CAP_OPEN_KEY);
snap_sb = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(data), E_CAP_SNAP_KEY);
if (cf.iface) g_free(cf.iface);
cf.iface =
g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry)));
filter_text = gtk_entry_get_text(GTK_ENTRY(filter_te));
if (cf.cfilter) g_free(cf.cfilter);
cf.cfilter = g_strdup(gtk_entry_get_text(GTK_ENTRY(filter_te)));
if (cf.save_file) g_free(cf.save_file);
cf.save_file = g_strdup(gtk_entry_get_text(GTK_ENTRY(file_te)));
if (filter_text && filter_text[0]) {
cf.cfilter = g_strdup(gtk_entry_get_text(GTK_ENTRY(filter_te)));
}
cf.count =
atoi(g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(count_cb)->entry))));
open = GTK_TOGGLE_BUTTON(open_ck)->active;
cf.snap = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(snap_sb));
if (cf.snap < 1)
cf.snap = MAX_PACKET_SIZE;
@ -370,8 +345,16 @@ capture_prep_ok_cb(GtkWidget *w, gpointer data) {
cf.snap = MIN_PACKET_SIZE;
gtk_widget_destroy(GTK_WIDGET(data));
/* Choose a random name for the capture buffer */
if (cf.save_file && !cf.user_saved) {
unlink(cf.save_file); /* silently ignore error */
g_free(cf.save_file);
}
cf.save_file = tempnam(NULL, "ether");
cf.user_saved = 0;
capture(open);
capture();
}
void
@ -385,7 +368,7 @@ capture_prep_close_cb(GtkWidget *w, gpointer win) {
}
void
capture(gint open) {
capture(void) {
GtkWidget *cap_w, *main_vb, *count_lb, *tcp_lb, *udp_lb,
*ospf_lb, *other_lb, *stop_bt;
pcap_t *pch;
@ -409,17 +392,14 @@ capture(gint open) {
pch = pcap_open_live(cf.iface, cf.snap, 1, 250, err_str);
if (pch) {
if (cf.save_file[0]) {
ld.pdh = pcap_dump_open(pch, cf.save_file);
if (ld.pdh == NULL) { /* We have an error */
snprintf(err_str, PCAP_ERRBUF_SIZE, "Error trying to open dump "
"file:\n%s", pcap_geterr(pch));
simple_dialog(ESD_TYPE_WARN, NULL, err_str);
g_free(cf.save_file);
cf.save_file = NULL;
pcap_close(pch);
return;
}
ld.pdh = pcap_dump_open(pch, cf.save_file);
if (ld.pdh == NULL) { /* We have an error */
snprintf(err_str, PCAP_ERRBUF_SIZE, "Error trying to save capture to "
"file:\n%s", pcap_geterr(pch));
simple_dialog(ESD_TYPE_WARN, NULL, err_str);
pcap_close(pch);
return;
}
ld.linktype = pcap_datalink(pch);
@ -522,11 +502,16 @@ capture(gint open) {
"The capture session could not be initiated. Please\n"
"check to make sure you have sufficient permissions, and\n"
"that you have the proper interface specified.");
g_free(cf.save_file);
cf.save_file = NULL;
}
if (cf.save_file && open) load_cap_file(cf.save_file, &cf);
if (cf.save_file) load_cap_file(cf.save_file, &cf);
#ifdef USE_ITEM
set_menu_sensitivity("/File/Save", TRUE);
set_menu_sensitivity("/File/Save as", FALSE);
#else
set_menu_sensitivity("<Main>/File/Save", TRUE);
set_menu_sensitivity("<Main>/File/Save as", FALSE);
#endif
}
float

View File

@ -1,7 +1,7 @@
/* capture.h
* Definitions for packet capture windows
*
* $Id: capture.h,v 1.4 1999/02/09 00:35:35 guy Exp $
* $Id: capture.h,v 1.5 1999/04/06 16:24:48 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -41,7 +41,7 @@ void cap_prep_fs_ok_cb(GtkWidget *, gpointer);
void cap_prep_fs_cancel_cb(GtkWidget *, gpointer);
void capture_prep_ok_cb(GtkWidget *, gpointer);
void capture_prep_close_cb(GtkWidget *, gpointer);
void capture(gint);
void capture(void);
float pct(gint, gint);
void capture_stop_cb(GtkWidget *, gpointer);
void capture_pcap_cb(u_char *, const struct pcap_pkthdr *, const u_char *);

View File

@ -311,13 +311,19 @@ B<http://ethereal.zing.org>.
Contributors
------------
Gilbert Ramirez Jr. <gram@verdict.uthscsa.edu>
Hannes R. Boehm <hannes@boehm.org>
Mike Hall <mlh@io.com>
Bobo Rajec <bobo@bsp-consulting.sk>
Laurent Deniel <deniel@worldnet.fr>
Don Lafontaine <lafont02@cn.ca>
Gilbert Ramirez <gramirez@tivoli.com>
Hannes R. Boehm <hannes@boehm.org>
Mike Hall <mlh@io.com>
Bobo Rajec <bobo@bsp-consulting.sk>
Laurent Deniel <deniel@worldnet.fr>
Don Lafontaine <lafont02@cn.ca>
Guy Harris <guy@netapp.com>
Simon Wilkinson <sxw@dcs.ed.ac.uk>
Joerg Mayer <jmayer@telemation.de>
Martin Maciaszek <fastjack@i-s-o.net>
Didier Jorand <Didier.Jorand@alcatel.fr>
Jun-ichiro itojun Hagino <itojun@iijlab.net>
Richard Sharpe <sharpe@ns.aus.com>
Alain Magloire <alainm@rcsm.ece.mcgill.ca> was kind enough to give his
permission to use his version of snprintf.c.

View File

@ -1,6 +1,6 @@
/* ethereal.c
*
* $Id: ethereal.c,v 1.28 1999/04/05 21:54:39 guy Exp $
* $Id: ethereal.c,v 1.29 1999/04/06 16:24:48 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -32,7 +32,6 @@
* - Playback window
* - Multiple window support
* - Add cut/copy/paste
* - Handle snoop files
* - Fix progress/status bar glitches? (GTK+ bug?)
* - Create header parsing routines
* - Check fopens, freads, fwrites
@ -80,6 +79,9 @@
#include "util.h"
#include "gtkpacket.h"
static void file_save_ok_cb(GtkWidget *w, GtkFileSelection *fs);
static void file_save_as_ok_cb(GtkWidget *w, GtkFileSelection *fs);
FILE *data_out_file = NULL;
packet_info pi;
capture_file cf;
@ -105,7 +107,8 @@ about_ethereal( GtkWidget *w, gpointer data ) {
"Version %s (C) 1998 Gerald Combs <gerald@zing.org>\n"
"Compiled with %s\n\n"
"Contributors:\n"
"Gilbert Ramirez Jr. <gram@verdict.uthscsa.edu>\n"
"Gilbert Ramirez <gramirez@tivoli.com>\n"
"Hannes R. Boehm <hannes@boehm.org>\n"
"Mike Hall <mlh@io.com>\n"
"Bobo Rajec <bobo@bsp-consulting.sk>\n"
@ -117,8 +120,9 @@ about_ethereal( GtkWidget *w, gpointer data ) {
"Martin Maciaszek <fastjack@i-s-o.net>\n"
"Didier Jorand <Didier.Jorand@alcatel.fr>\n"
"Jun-ichiro itojun Hagino <itojun@iijlab.net>\n"
"Richard Sharpe <sharpe@ns.aus.com>\n\n"
"See http://ethereal.zing.org for more information",
"Richard Sharpe <sharpe@ns.aus.com>\n"
"\nSee http://ethereal.zing.org for more information",
VERSION, comp_info_str);
}
@ -127,23 +131,35 @@ void
file_sel_ok_cb(GtkWidget *w, GtkFileSelection *fs) {
gchar *cf_name;
int err;
#if 0
GtkWidget *filter_te = NULL;
/* Gilbert --- I added this if statement. Is this right? */
if (w)
filter_te = gtk_object_get_data(GTK_OBJECT(w), E_DFILTER_TE_KEY);
#endif
cf_name = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION (fs)));
gtk_widget_hide(GTK_WIDGET (fs));
gtk_widget_destroy(GTK_WIDGET (fs));
#if 0
if (w && cf.dfilter) {
g_free(cf.dfilter);
cf.dfilter = g_strdup(gtk_entry_get_text(GTK_ENTRY(filter_te)));
}
#endif
/* this depends upon load_cap_file removing the filename from
* cf_name, leaving only the path to the directory. */
if ((err = load_cap_file(cf_name, &cf)) == 0)
chdir(cf_name);
g_free(cf_name);
#ifdef USE_ITEM
set_menu_sensitivity("/File/Save", FALSE);
set_menu_sensitivity("/File/Save as", TRUE);
#else
set_menu_sensitivity("<Main>/File/Save", FALSE);
set_menu_sensitivity("<Main>/File/Save as", TRUE);
#endif
}
/* Update the progress bar */
@ -295,10 +311,96 @@ file_close_cmd_cb(GtkWidget *widget, gpointer data) {
#endif
}
void
file_save_cmd_cb(GtkWidget *w, gpointer data) {
file_sel = gtk_file_selection_new ("Ethereal: Save Capture File");
/* Connect the ok_button to file_ok_sel_cb function and pass along the
pointer to the filter entry */
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (file_sel)->ok_button),
"clicked", (GtkSignalFunc) file_save_ok_cb, file_sel );
/* Connect the cancel_button to destroy the widget */
gtk_signal_connect_object(GTK_OBJECT (GTK_FILE_SELECTION
(file_sel)->cancel_button), "clicked", (GtkSignalFunc)
gtk_widget_destroy, GTK_OBJECT (file_sel));
gtk_file_selection_set_filename(GTK_FILE_SELECTION(file_sel), "");
gtk_widget_show(file_sel);
}
void
file_save_as_cmd_cb(GtkWidget *w, gpointer data) {
file_sel = gtk_file_selection_new ("Ethereal: Save Capture File as");
/* Connect the ok_button to file_ok_sel_cb function and pass along the
pointer to the filter entry */
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (file_sel)->ok_button),
"clicked", (GtkSignalFunc) file_save_as_ok_cb, file_sel );
/* Connect the cancel_button to destroy the widget */
gtk_signal_connect_object(GTK_OBJECT (GTK_FILE_SELECTION
(file_sel)->cancel_button), "clicked", (GtkSignalFunc)
gtk_widget_destroy, GTK_OBJECT (file_sel));
gtk_file_selection_set_filename(GTK_FILE_SELECTION(file_sel), "");
gtk_widget_show(file_sel);
}
static void
file_save_ok_cb(GtkWidget *w, GtkFileSelection *fs) {
gchar *cf_name;
cf_name = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(fs)));
gtk_widget_hide(GTK_WIDGET (fs));
gtk_widget_destroy(GTK_WIDGET (fs));
if (!file_mv(cf.save_file, cf_name))
return;
g_free(cf.save_file);
cf.save_file = g_strdup(cf_name);
cf.user_saved = 1;
load_cap_file(cf_name, &cf);
#ifdef USE_ITEM
set_menu_sensitivity("/File/Save", FALSE);
set_menu_sensitivity("/File/Save as", TRUE);
#else
set_menu_sensitivity("<Main>/File/Save", FALSE);
set_menu_sensitivity("<Main>/File/Save as", TRUE);
#endif
}
static void
file_save_as_ok_cb(GtkWidget *w, GtkFileSelection *fs) {
gchar *cf_name;
cf_name = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(fs)));
gtk_widget_hide(GTK_WIDGET (fs));
gtk_widget_destroy(GTK_WIDGET (fs));
if (!file_cp(cf.save_file, cf_name))
return;
g_free(cf.save_file);
cf.save_file = g_strdup(cf_name);
cf.user_saved = 1;
load_cap_file(cf_name, &cf);
#ifdef USE_ITEM
set_menu_sensitivity("/File/Save", FALSE);
set_menu_sensitivity("/File/Save as", TRUE);
#else
set_menu_sensitivity("<Main>/File/Save", FALSE);
set_menu_sensitivity("<Main>/File/Save as", TRUE);
#endif
}
/* Reload a file using the current display filter */
void
file_reload_cmd_cb(GtkWidget *w, gpointer data) {
GtkWidget *filter_te = gtk_object_get_data(GTK_OBJECT(w), E_DFILTER_TE_KEY);
/*GtkWidget *filter_te = gtk_object_get_data(GTK_OBJECT(w), E_DFILTER_TE_KEY);*/
GtkWidget *filter_te;
filter_te = gtk_object_get_data(GTK_OBJECT(w), E_DFILTER_TE_KEY);
@ -391,12 +493,17 @@ main_realize_cb(GtkWidget *w, gpointer data) {
if (cf_name) {
err = load_cap_file(cf_name, &cf);
cf_name[0] = '\0';
#ifdef USE_ITEM
set_menu_sensitivity("/File/Save as", TRUE);
#else
set_menu_sensitivity("<Main>/File/Save as", TRUE);
#endif
}
if (start_capture) {
if (cf.save_file)
capture(1);
capture();
else
capture(0);
capture();
start_capture = 0;
}
}
@ -453,24 +560,23 @@ main(int argc, char *argv[])
prefs = read_prefs();
/* Initialize the capture file struct */
cf.plist = NULL;
cf.plist = NULL;
#ifdef WITH_WIRETAP
cf.wth = NULL;
cf.wth = NULL;
#else
cf.pfh = NULL;
cf.pfh = NULL;
#endif
cf.fh = NULL;
cf.dfilter = NULL;
cf.cfilter = NULL;
cf.iface = NULL;
cf.save_file = NULL;
cf.snap = MIN_PACKET_SIZE;
cf.count = 0;
cf.cinfo.num_cols = prefs->num_cols;
cf.cinfo.fmt_matx = (gboolean **) g_malloc(sizeof(gboolean *) *
cf.cinfo.num_cols);
cf.cinfo.col_data = (gchar **) g_malloc(sizeof(gchar *) *
cf.cinfo.num_cols);
cf.fh = NULL;
cf.dfilter = NULL;
cf.cfilter = NULL;
cf.iface = NULL;
cf.save_file = NULL;
cf.user_saved = 0;
cf.snap = MIN_PACKET_SIZE;
cf.count = 0;
cf.cinfo.num_cols = prefs->num_cols;
cf.cinfo.fmt_matx = (gboolean **) g_malloc(sizeof(gboolean *) * cf.cinfo.num_cols);
cf.cinfo.col_data = (gchar **) g_malloc(sizeof(gchar *) * cf.cinfo.num_cols);
/* Assemble the compile-time options */
snprintf(comp_info_str, 256,
@ -749,6 +855,7 @@ main(int argc, char *argv[])
ethereal_proto_init(); /* Init anything that needs initializing */
gtk_widget_show(window);
gtk_main();
exit(0);

View File

@ -1,7 +1,7 @@
/* ethereal.h
* Global defines, etc.
*
* $Id: ethereal.h,v 1.12 1999/03/23 03:14:33 gram Exp $
* $Id: ethereal.h,v 1.13 1999/04/06 16:24:48 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -109,6 +109,8 @@ void blank_packetinfo();
gint file_progress_cb(gpointer);
void follow_stream_cb( GtkWidget *, gpointer);
void file_open_cmd_cb(GtkWidget *, gpointer);
void file_save_cmd_cb(GtkWidget *, gpointer);
void file_save_as_cmd_cb(GtkWidget *, gpointer);
void file_close_cmd_cb(GtkWidget *, gpointer);
void file_quit_cmd_cb(GtkWidget *, gpointer);
void file_reload_cmd_cb(GtkWidget *, gpointer);

21
file.c
View File

@ -1,7 +1,7 @@
/* file.c
* File I/O routines
*
* $Id: file.c,v 1.22 1999/03/23 03:14:34 gram Exp $
* $Id: file.c,v 1.23 1999/04/06 16:24:48 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -119,8 +119,8 @@ open_cap_file(char *fname, capture_file *cf) {
#else
cf->cd_t = CD_UNKNOWN;
cf->lnk_t = DLT_NULL;
#endif
cf->swap = 0;
#endif
cf->count = 0;
cf->drops = 0;
cf->esec = 0;
@ -240,6 +240,7 @@ load_cap_file(char *fname, capture_file *cf) {
close_cap_file(cf, info_bar, file_ctx);
/* Initialize protocol-speficic variables */
ncp_init_protocol();
if ((name_ptr = (gchar *) strrchr(fname, '/')) == NULL)
@ -281,11 +282,14 @@ load_cap_file(char *fname, capture_file *cf) {
if (err == 0) {
msg_len = strlen(name_ptr) + strlen(done_fmt) + 64;
load_msg = g_realloc(load_msg, msg_len);
snprintf(load_msg, msg_len, done_fmt, name_ptr, cf->drops);
if (cf->user_saved)
snprintf(load_msg, msg_len, done_fmt, name_ptr, cf->drops);
else
snprintf(load_msg, msg_len, done_fmt, "<none>", cf->drops);
gtk_statusbar_push(GTK_STATUSBAR(info_bar), file_ctx, load_msg);
g_free(load_msg);
name_ptr[-1] = '\0';
/* name_ptr[-1] = '\0'; Why is this here? It causes problems with capture files */
#ifdef USE_ITEM
set_menu_sensitivity("/File/Close", TRUE);
set_menu_sensitivity("/File/Reload", TRUE);
@ -300,14 +304,17 @@ load_cap_file(char *fname, capture_file *cf) {
gtk_statusbar_push(GTK_STATUSBAR(info_bar), file_ctx, load_msg);
g_free(load_msg);
#ifdef USE_ITEM
set_menu_sensitivity("<Main>/File/Close", FALSE);
set_menu_sensitivity("<Main>/File/Reload", FALSE);
set_menu_sensitivity("/File/Close", FALSE);
set_menu_sensitivity("/File/Save", FALSE);
set_menu_sensitivity("/File/Save as", FALSE);
set_menu_sensitivity("/File/Reload", FALSE);
#else
set_menu_sensitivity("<Main>/File/Close", FALSE);
set_menu_sensitivity("<Main>/File/Save", FALSE);
set_menu_sensitivity("<Main>/File/Save as", FALSE);
set_menu_sensitivity("<Main>/File/Reload", FALSE);
#endif
}
return err;
}

7
file.h
View File

@ -1,7 +1,7 @@
/* file.h
* Definitions for file structures and routines
*
* $Id: file.h,v 1.11 1999/03/23 03:14:34 gram Exp $
* $Id: file.h,v 1.12 1999/04/06 16:24:49 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -61,7 +61,9 @@ typedef struct _capture_file {
FILE *fh; /* Capture file */
gchar *filename; /* filename */
long f_len; /* File length */
#ifndef WITH_WIRETAP
int swap; /* Swap data bytes? */
#endif
guint16 cd_t; /* Capture data type */
guint32 vers; /* Version. For tcpdump minor is appended to major */
#ifndef WITH_WIRETAP
@ -73,7 +75,8 @@ typedef struct _capture_file {
guint32 eusec; /* Elapsed microseconds */
guint32 snap; /* Captured packet length */
gchar *iface; /* Interface */
gchar *save_file; /* File to write capture data */
gchar *save_file; /* File that user saved capture to */
gint user_saved;/* Was capture file saved by user yet? */
#ifdef WITH_WIRETAP
wtap *wth; /* Wiretap session */
#else

12
menu.c
View File

@ -1,7 +1,7 @@
/* menu.c
* Menu routines
*
* $Id: menu.c,v 1.16 1999/04/05 22:51:43 guy Exp $
* $Id: menu.c,v 1.17 1999/04/06 16:24:49 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -62,8 +62,8 @@ static GtkItemFactoryEntry menu_items[] =
{"/_File", NULL, NULL, 0, "<Branch>" },
{"/File/_Open", "<control>O", GTK_MENU_FUNC(file_open_cmd_cb), 0, NULL},
{"/File/_Close", "<control>W", GTK_MENU_FUNC(file_close_cmd_cb), 0, NULL},
{"/File/_Save", "<control>S", NULL, 0, NULL},
{"/File/Save _as", NULL, NULL, 0, NULL},
{"/File/_Save", "<control>S", GTK_MENU_FUNC(file_save_cmd_cb), 0, NULL},
{"/File/Save as", NULL, GTK_MENU_FUNC(file_save_as_cmd_cb), 0, NULL},
{"/File/_Reload", "<control>R", GTK_MENU_FUNC(file_reload_cmd_cb), 0, NULL},
{"/File/<separator>", NULL, NULL, 0, "<Separator>"},
{"/File/_Print Packet", "<control>P", GTK_MENU_FUNC(file_print_cmd_cb), 0, NULL},
@ -89,8 +89,8 @@ static GtkMenuEntry menu_items[] =
{
{"<Main>/File/Open", "<control>O", file_open_cmd_cb, NULL},
{"<Main>/File/Close", "<control>W", file_close_cmd_cb, NULL},
{"<Main>/File/Save", "<control>S", NULL, NULL},
{"<Main>/File/Save as", NULL, NULL, NULL},
{"<Main>/File/Save", "<control>S", file_save_cmd_cb, NULL},
{"<Main>/File/Save as", NULL, file_save_as_cmd_cb, NULL},
{"<Main>/File/Reload", "<control>R", file_reload_cmd_cb, NULL},
{"<Main>/File/<separator>", NULL, NULL, NULL},
{"<Main>/File/Print Packet", "<control>P", file_print_cmd_cb, NULL},
@ -167,8 +167,6 @@ menus_init(void) {
#ifdef USE_ITEM
factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", grp);
/*gtk_item_factory_create_items(factory, nmenu_items, menu_items,
*NULL);grj*/
gtk_item_factory_create_items_ac(factory, nmenu_items, menu_items, NULL,2);
set_menu_sensitivity("/File/Close", FALSE);
set_menu_sensitivity("/File/Save", FALSE);

View File

@ -1,3 +1,28 @@
/* packet-ipv6.h
* Definitions for IPv6 packet disassembly
*
* $Id: packet-ipv6.h,v 1.3 1999/04/06 16:24:49 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
* 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.
*/
#ifndef __PACKET_IPV6_H_DEFINED__
#define __PACKET_IPV6_H_DEFINED__

79
util.c
View File

@ -1,7 +1,7 @@
/* util.c
* Utility routines
*
* $Id: util.c,v 1.13 1999/04/05 22:51:44 guy Exp $
* $Id: util.c,v 1.14 1999/04/06 16:24:49 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -34,6 +34,14 @@
#include <stdarg.h>
#include <stdio.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef NEED_SNPRINTF_H
# ifdef HAVE_STDARG_H
# include <stdarg.h>
@ -166,3 +174,72 @@ simple_dialog_cancel_cb(GtkWidget *w, gpointer win) {
*btn_mask = ESD_BTN_CANCEL;
gtk_widget_destroy(GTK_WIDGET(win));
}
/* Tries to mv a file. If unsuccessful, tries to cp the file.
* Returns 0 on failure to do either, 1 on success of either
*/
int
file_mv(char *from, char *to)
{
#define COPY_BUFFER_SIZE 8192
int retval;
/* try a hard link */
retval = link(from, to);
/* or try a copy */
if (retval < 0) {
retval = file_cp(from, to);
if (!retval) {
return 0;
}
}
unlink(from);
return 1;
}
/* Copies a file.
* Returns 0 on failure to do either, 1 on success of either
*/
int
file_cp(char *from, char *to)
{
#define COPY_BUFFER_SIZE 8192
int from_fd, to_fd, nread;
char *buffer;
gint dialogue_button = ESD_BTN_OK;
buffer = g_malloc(COPY_BUFFER_SIZE);
from_fd = open(from, O_RDONLY);
if (from_fd < 0) {
simple_dialog(ESD_TYPE_WARN, &dialogue_button,
"Cannot open from-file for copying.");
return 0;
}
to_fd = creat(to, 0644);
if (to_fd < 0) {
simple_dialog(ESD_TYPE_WARN, &dialogue_button,
"Cannot open to-file for copying.");
close(from_fd);
return 0;
}
while( (nread = read(from_fd, buffer, COPY_BUFFER_SIZE)) > 0) {
if (write(to_fd, buffer, nread) < nread) {
close(from_fd);
close(to_fd);
return 0;
}
}
close(from_fd);
close(to_fd);
return 1;
}

8
util.h
View File

@ -1,7 +1,7 @@
/* util.h
* Utility definitions
*
* $Id: util.h,v 1.8 1999/03/31 08:20:28 guy Exp $
* $Id: util.h,v 1.9 1999/04/06 16:24:50 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -46,6 +46,12 @@ void simple_dialog(gint, gint *, gchar *, ...)
void simple_dialog(gint, gint *, gchar *, ...);
#endif
/* Moves or copies a file. Returns 0 on failure, 1 on success */
int file_mv(char *from, char *to);
/* Copies a file. Returns 0 on failure, 1 on success */
int file_cp(char *from, char *to);
#ifdef __cplusplus
}
#endif /* __cplusplus */