aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--capture.c31
-rw-r--r--file.c143
-rw-r--r--file.h20
-rw-r--r--gtk/file_dlg.c26
-rw-r--r--gtk/main.c14
-rw-r--r--tethereal.c6
6 files changed, 119 insertions, 121 deletions
diff --git a/capture.c b/capture.c
index 98fad09bca..9257125759 100644
--- a/capture.c
+++ b/capture.c
@@ -1,7 +1,7 @@
/* capture.c
* Routines for packet capture windows
*
- * $Id: capture.c,v 1.208 2003/07/23 05:01:15 guy Exp $
+ * $Id: capture.c,v 1.209 2003/09/15 22:48:41 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -340,7 +340,7 @@ do_capture(const char *save_file)
g_free(capfile_name);
return;
}
- close_cap_file(&cfile);
+ cf_close(&cfile);
g_assert(cfile.save_file == NULL);
cfile.save_file = capfile_name;
/* cfile.save_file is "g_free"ed below, which is equivalent to
@@ -561,7 +561,7 @@ do_capture(const char *save_file)
}
if (c == SP_CAPSTART) {
/* Success. Open the capture file, and set up to read it. */
- err = start_tail_cap_file(cfile.save_file, is_tempfile, &cfile);
+ err = cf_start_tail(cfile.save_file, is_tempfile, &cfile);
if (err == 0) {
/* We were able to open and set up to read the capture file;
arrange that our callback be called whenever it's possible
@@ -639,7 +639,7 @@ do_capture(const char *save_file)
}
if (capture_succeeded) {
/* Capture succeeded; read in the capture file. */
- if ((err = open_cap_file(cfile.save_file, is_tempfile, &cfile)) == 0) {
+ if ((err = cf_open(cfile.save_file, is_tempfile, &cfile)) == 0) {
/* Set the read filter to NULL. */
cfile.rfcode = NULL;
@@ -650,18 +650,17 @@ do_capture(const char *save_file)
At some point, we will add support in Wiretap to return
packet-drop statistics for capture file formats that store it,
- and will make "read_cap_file()" get those statistics from
- Wiretap. We clear the statistics (marking them as "not known")
- in "open_cap_file()", and "read_cap_file()" will only fetch
- them and mark them as known if Wiretap supplies them, so if
- we get the statistics now, after calling "open_cap_file()" but
- before calling "read_cap_file()", the values we store will
- be used by "read_cap_file()".
+ and will make "cf_read()" get those statistics from Wiretap.
+ We clear the statistics (marking them as "not known") in
+ "cf_open()", and "cf_read()" will only fetch them and mark
+ them as known if Wiretap supplies them, so if we get the
+ statistics now, after calling "cf_open()" but before calling
+ "cf_read()", the values we store will be used by "cf_read()".
If a future libpcap capture file format stores the statistics,
we'll put them into the capture file that we write, and will
- thus not have to set them here - "read_cap_file()" will get
- them from the file and use them. */
+ thus not have to set them here - "cf_read()" will get them from
+ the file and use them. */
if (stats_known) {
cfile.drops_known = TRUE;
@@ -675,7 +674,7 @@ do_capture(const char *save_file)
supplies, allowing us to display only the ones it does. */
cfile.drops = stats.ps_drop;
}
- switch (read_cap_file(&cfile, &err)) {
+ switch (cf_read(&cfile, &err)) {
case READ_SUCCESS:
case READ_ERROR:
@@ -771,7 +770,7 @@ cap_file_input_cb(gpointer data, gint source _U_,
/* Read what remains of the capture file, and finish the capture.
XXX - do something if this fails? */
- switch (finish_tail_cap_file(cf, &err)) {
+ switch (cf_finish_tail(cf, &err)) {
case READ_SUCCESS:
case READ_ERROR:
@@ -853,7 +852,7 @@ cap_file_input_cb(gpointer data, gint source _U_,
/* Read from the capture file the number of records the child told us
it added.
XXX - do something if this fails? */
- switch (continue_tail_cap_file(cf, to_read, &err)) {
+ switch (cf_continue_tail(cf, to_read, &err)) {
case READ_SUCCESS:
case READ_ERROR:
diff --git a/file.c b/file.c
index 1b0e3e62f4..ea7e90e13f 100644
--- a/file.c
+++ b/file.c
@@ -1,7 +1,7 @@
/* file.c
* File I/O routines
*
- * $Id: file.c,v 1.312 2003/09/15 22:16:07 guy Exp $
+ * $Id: file.c,v 1.313 2003/09/15 22:48:41 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -145,7 +145,7 @@ typedef struct {
int
-open_cap_file(char *fname, gboolean is_tempfile, capture_file *cf)
+cf_open(char *fname, gboolean is_tempfile, capture_file *cf)
{
wtap *wth;
int err;
@@ -166,7 +166,7 @@ open_cap_file(char *fname, gboolean is_tempfile, capture_file *cf)
/* The open succeeded. Close whatever capture file we had open,
and fill in the information for this file. */
- close_cap_file(cf);
+ cf_close(cf);
/* Initialize all data structures used for dissection. */
init_dissection();
@@ -224,7 +224,7 @@ fail:
/* Reset everything to a pristine state */
void
-close_cap_file(capture_file *cf)
+cf_close(capture_file *cf)
{
/* Die if we're in the middle of reading a file. */
g_assert(cf->state != FILE_READ_IN_PROGRESS);
@@ -321,7 +321,7 @@ set_display_filename(capture_file *cf)
}
read_status_t
-read_cap_file(capture_file *cf, int *err)
+cf_read(capture_file *cf, int *err)
{
gchar *name_ptr, *load_msg, *load_fmt = "%s";
size_t msg_len;
@@ -413,7 +413,7 @@ read_cap_file(capture_file *cf, int *err)
destroy_progress_dlg(progbar);
cf->state = FILE_READ_ABORTED; /* so that we're allowed to close it */
packet_list_thaw(); /* undo our freeze */
- close_cap_file(cf);
+ cf_close(cf);
return (READ_ABORTED);
}
read_packet(cf, data_offset);
@@ -500,12 +500,12 @@ read_cap_file(capture_file *cf, int *err)
#ifdef HAVE_LIBPCAP
int
-start_tail_cap_file(char *fname, gboolean is_tempfile, capture_file *cf)
+cf_start_tail(char *fname, gboolean is_tempfile, capture_file *cf)
{
int err;
int i;
- err = open_cap_file(fname, is_tempfile, cf);
+ err = cf_open(fname, is_tempfile, cf);
if (err == 0) {
/* Disable menu items that make no sense if you're currently running
a capture. */
@@ -531,7 +531,7 @@ start_tail_cap_file(char *fname, gboolean is_tempfile, capture_file *cf)
}
read_status_t
-continue_tail_cap_file(capture_file *cf, int to_read, int *err)
+cf_continue_tail(capture_file *cf, int to_read, int *err)
{
long data_offset = 0;
@@ -561,7 +561,7 @@ continue_tail_cap_file(capture_file *cf, int to_read, int *err)
/* Well, the user decided to exit Ethereal. Return READ_ABORTED
so that our caller can kill off the capture child process;
this will cause an EOF on the pipe from the child, so
- "finish_tail_cap_file()" will be called, and it will clean up
+ "cf_finish_tail()" will be called, and it will clean up
and exit. */
return READ_ABORTED;
} else if (*err != 0) {
@@ -573,7 +573,7 @@ continue_tail_cap_file(capture_file *cf, int to_read, int *err)
}
read_status_t
-finish_tail_cap_file(capture_file *cf, int *err)
+cf_finish_tail(capture_file *cf, int *err)
{
long data_offset;
@@ -595,7 +595,7 @@ finish_tail_cap_file(capture_file *cf, int *err)
it's probably exited), so we can just close the capture
file; we return READ_ABORTED so our caller can do whatever
is appropriate when that happens. */
- close_cap_file(cf);
+ cf_close(cf);
return READ_ABORTED;
}
@@ -2159,7 +2159,7 @@ thaw_plist(capture_file *cf)
* up a message box for the failure.
*/
gboolean
-save_cap_file(char *fname, capture_file *cf, gboolean save_filtered,
+cf_save(char *fname, capture_file *cf, gboolean save_filtered,
gboolean save_marked, guint save_format)
{
gchar *from_filename;
@@ -2321,10 +2321,10 @@ save_cap_file(char *fname, capture_file *cf, gboolean save_filtered,
time if the file is large. */
cf->user_saved = TRUE;
- if ((err = open_cap_file(fname, FALSE, cf)) == 0) {
+ if ((err = cf_open(fname, FALSE, cf)) == 0) {
/* XXX - report errors if this fails?
What should we return if it fails or is aborted? */
- switch (read_cap_file(cf, &err)) {
+ switch (cf_read(cf, &err)) {
case READ_SUCCESS:
case READ_ERROR:
@@ -2336,7 +2336,7 @@ save_cap_file(char *fname, capture_file *cf, gboolean save_filtered,
case READ_ABORTED:
/* The user bailed out of re-reading the capture file; the
capture file has been closed - just return (without
- changing any menu settings; "close_cap_file()" set them
+ changing any menu settings; "cf_close()" set them
correctly for the "no capture file open" state). */
break;
}
@@ -2558,65 +2558,64 @@ file_close_error_message(int err)
static gboolean
copy_binary_file(char *from_filename, char *to_filename)
{
- int from_fd, to_fd, nread, nwritten, err;
- guint8 pd[65536]; /* XXX - Hmm, 64K here, 64K in save_cap_file(),
- perhaps we should make just one 64K buffer. */
-
- /* Copy the raw bytes of the file. */
- from_fd = open(from_filename, O_RDONLY | O_BINARY);
- if (from_fd < 0) {
- err = errno;
- simple_dialog(ESD_TYPE_CRIT, NULL,
- file_open_error_message(err, TRUE, 0), from_filename);
- goto done;
- }
+ int from_fd, to_fd, nread, nwritten, err;
+ guint8 pd[65536];
- /* Use open() instead of creat() so that we can pass the O_BINARY
- flag, which is relevant on Win32; it appears that "creat()"
- may open the file in text mode, not binary mode, but we want
- to copy the raw bytes of the file, so we need the output file
- to be open in binary mode. */
- to_fd = open(to_filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
- if (to_fd < 0) {
- err = errno;
- simple_dialog(ESD_TYPE_CRIT, NULL,
- file_open_error_message(err, TRUE, 0), to_filename);
- close(from_fd);
- goto done;
- }
+ /* Copy the raw bytes of the file. */
+ from_fd = open(from_filename, O_RDONLY | O_BINARY);
+ if (from_fd < 0) {
+ err = errno;
+ simple_dialog(ESD_TYPE_CRIT, NULL,
+ file_open_error_message(err, TRUE, 0), from_filename);
+ goto done;
+ }
- while ((nread = read(from_fd, pd, sizeof pd)) > 0) {
- nwritten = write(to_fd, pd, nread);
- if (nwritten < nread) {
- if (nwritten < 0)
- err = errno;
- else
- err = WTAP_ERR_SHORT_WRITE;
- simple_dialog(ESD_TYPE_CRIT, NULL,
- file_write_error_message(err), to_filename);
- close(from_fd);
- close(to_fd);
- goto done;
- }
- }
- if (nread < 0) {
- err = errno;
- simple_dialog(ESD_TYPE_CRIT, NULL,
- file_read_error_message(err), from_filename);
- close(from_fd);
- close(to_fd);
- goto done;
- }
+ /* Use open() instead of creat() so that we can pass the O_BINARY
+ flag, which is relevant on Win32; it appears that "creat()"
+ may open the file in text mode, not binary mode, but we want
+ to copy the raw bytes of the file, so we need the output file
+ to be open in binary mode. */
+ to_fd = open(to_filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
+ if (to_fd < 0) {
+ err = errno;
+ simple_dialog(ESD_TYPE_CRIT, NULL,
+ file_open_error_message(err, TRUE, 0), to_filename);
+ close(from_fd);
+ goto done;
+ }
+
+ while ((nread = read(from_fd, pd, sizeof pd)) > 0) {
+ nwritten = write(to_fd, pd, nread);
+ if (nwritten < nread) {
+ if (nwritten < 0)
+ err = errno;
+ else
+ err = WTAP_ERR_SHORT_WRITE;
+ simple_dialog(ESD_TYPE_CRIT, NULL,
+ file_write_error_message(err), to_filename);
close(from_fd);
- if (close(to_fd) < 0) {
- err = errno;
- simple_dialog(ESD_TYPE_CRIT, NULL,
- file_close_error_message(err), to_filename);
- goto done;
- }
+ close(to_fd);
+ goto done;
+ }
+ }
+ if (nread < 0) {
+ err = errno;
+ simple_dialog(ESD_TYPE_CRIT, NULL,
+ file_read_error_message(err), from_filename);
+ close(from_fd);
+ close(to_fd);
+ goto done;
+ }
+ close(from_fd);
+ if (close(to_fd) < 0) {
+ err = errno;
+ simple_dialog(ESD_TYPE_CRIT, NULL,
+ file_close_error_message(err), to_filename);
+ goto done;
+ }
- return TRUE;
+ return TRUE;
- done:
- return FALSE;
+done:
+ return FALSE;
}
diff --git a/file.h b/file.h
index 4343bfa965..d5d1448f78 100644
--- a/file.h
+++ b/file.h
@@ -1,7 +1,7 @@
/* file.h
* Definitions for file structures and routines
*
- * $Id: file.h,v 1.106 2003/09/15 22:16:08 guy Exp $
+ * $Id: file.h,v 1.107 2003/09/15 22:48:41 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -33,22 +33,22 @@
#include "cfile.h"
-/* Return values from "read_cap_file()", "continue_tail_cap_file()",
- and "finish_tail_cap_file()". */
+/* Return values from "cf_read()", "cf_continue_tail()", and
+ "cf_finish_tail()". */
typedef enum {
READ_SUCCESS, /* read succeeded */
READ_ERROR, /* read got an error */
READ_ABORTED /* read aborted by user */
} read_status_t;
-int open_cap_file(char *, gboolean, capture_file *);
-void close_cap_file(capture_file *);
-read_status_t read_cap_file(capture_file *, int *);
-int start_tail_cap_file(char *, gboolean, capture_file *);
-read_status_t continue_tail_cap_file(capture_file *, int, int *);
-read_status_t finish_tail_cap_file(capture_file *, int *);
+int cf_open(char *, gboolean, capture_file *);
+void cf_close(capture_file *);
+read_status_t cf_read(capture_file *, int *);
+int cf_start_tail(char *, gboolean, capture_file *);
+read_status_t cf_continue_tail(capture_file *, int, int *);
+read_status_t cf_finish_tail(capture_file *, int *);
/* size_t read_frame_header(capture_file *); */
-gboolean save_cap_file(char *, capture_file *, gboolean, gboolean, guint);
+gboolean cf_save(char *, capture_file *, gboolean, gboolean, guint);
gchar *cf_get_display_name(capture_file *);
int filter_packets(capture_file *cf, gchar *dfilter);
diff --git a/gtk/file_dlg.c b/gtk/file_dlg.c
index b62497f5e8..3b6d9ccd8e 100644
--- a/gtk/file_dlg.c
+++ b/gtk/file_dlg.c
@@ -1,7 +1,7 @@
/* file_dlg.c
* Dialog boxes for handling files
*
- * $Id: file_dlg.c,v 1.58 2003/08/18 21:27:10 sahlberg Exp $
+ * $Id: file_dlg.c,v 1.59 2003/09/15 22:48:42 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -227,7 +227,7 @@ file_open_ok_cb(GtkWidget *w, GtkFileSelection *fs) {
}
/* Try to open the capture file. */
- if ((err = open_cap_file(cf_name, FALSE, &cfile)) != 0) {
+ if ((err = cf_open(cf_name, FALSE, &cfile)) != 0) {
/* We couldn't open it; don't dismiss the open dialog box,
just leave it around so that the user can, after they
dismiss the alert box popped up for the open error,
@@ -238,7 +238,7 @@ file_open_ok_cb(GtkWidget *w, GtkFileSelection *fs) {
return;
}
- /* Attach the new read filter to "cf" ("open_cap_file()" succeeded, so
+ /* Attach the new read filter to "cf" ("cf_open()" succeeded, so
it closed the previous capture file, and thus destroyed any
previous read filter attached to "cf"). */
cfile.rfcode = rfcode;
@@ -256,7 +256,7 @@ file_open_ok_cb(GtkWidget *w, GtkFileSelection *fs) {
gtk_widget_hide(GTK_WIDGET (fs));
gtk_widget_destroy(GTK_WIDGET (fs));
- switch (read_cap_file(&cfile, &err)) {
+ switch (cf_read(&cfile, &err)) {
case READ_SUCCESS:
case READ_ERROR:
@@ -294,7 +294,7 @@ file_open_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
/* Close a file */
void
file_close_cmd_cb(GtkWidget *widget _U_, gpointer data _U_) {
- close_cap_file(&cfile);
+ cf_close(&cfile);
}
void
@@ -591,7 +591,7 @@ file_save_as_ok_cb(GtkWidget *w _U_, GtkFileSelection *fs) {
/* Write out the packets (all, or only the ones that are currently
displayed or marked) to the file with the specified name. */
- if (! save_cap_file(cf_name, &cfile, filtered, marked, filetype)) {
+ if (! cf_save(cf_name, &cfile, filtered, marked, filetype)) {
/* The write failed; don't dismiss the open dialog box,
just leave it around so that the user can, after they
dismiss the alert box popped up for the error, try again. */
@@ -628,21 +628,21 @@ file_reload_cmd_cb(GtkWidget *w, gpointer data _U_) {
g_free(cfile.dfilter);
cfile.dfilter = g_strdup(gtk_entry_get_text(GTK_ENTRY(filter_te)));
- /* If the file could be opened, "open_cap_file()" calls "close_cap_file()"
+ /* If the file could be opened, "cf_open()" calls "cf_close()"
to get rid of state for the old capture file before filling in state
- for the new capture file. "close_cap_file()" will remove the file if
+ for the new capture file. "cf_close()" will remove the file if
it's a temporary file; we don't want that to happen (for one thing,
it'd prevent subsequent reopens from working). Remember whether it's
a temporary file, mark it as not being a temporary file, and then
reopen it as the type of file it was.
- Also, "close_cap_file()" will free "cfile.filename", so we must make
+ Also, "cf_close()" will free "cfile.filename", so we must make
a copy of it first. */
filename = g_strdup(cfile.filename);
is_tempfile = cfile.is_tempfile;
cfile.is_tempfile = FALSE;
- if (open_cap_file(filename, is_tempfile, &cfile) == 0) {
- switch (read_cap_file(&cfile, &err)) {
+ if (cf_open(filename, is_tempfile, &cfile) == 0) {
+ switch (cf_read(&cfile, &err)) {
case READ_SUCCESS:
case READ_ERROR:
@@ -664,11 +664,11 @@ file_reload_cmd_cb(GtkWidget *w, gpointer data _U_) {
Instead, the file was left open, so we should restore "cfile.is_tempfile"
ourselves.
- XXX - change the menu? Presumably "open_cap_file()" will do that;
+ XXX - change the menu? Presumably "cf_open()" will do that;
make sure it does! */
cfile.is_tempfile = is_tempfile;
}
- /* "open_cap_file()" made a copy of the file name we handed it, so
+ /* "cf_open()" made a copy of the file name we handed it, so
we should free up our copy. */
g_free(filename);
}
diff --git a/gtk/main.c b/gtk/main.c
index 1f1430f21f..f50b0912c4 100644
--- a/gtk/main.c
+++ b/gtk/main.c
@@ -1,6 +1,6 @@
/* main.c
*
- * $Id: main.c,v 1.312 2003/09/15 20:45:19 guy Exp $
+ * $Id: main.c,v 1.313 2003/09/15 22:48:42 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -1193,7 +1193,7 @@ do_quit(void)
/* Close any capture file we have open; on some OSes, you
can't unlink a temporary capture file if you have it
open.
- "close_cap_file()" will unlink it after closing it if
+ "cf_close()" will unlink it after closing it if
it's a temporary file.
We do this here, rather than after the main loop returns,
@@ -1201,7 +1201,7 @@ do_quit(void)
been destroyed (if this is called due to a "destroy"
even on the main window rather than due to the user
selecting a menu item), and there may be a crash
- or other problem when "close_cap_file()" tries to
+ or other problem when "cf_close()" tries to
clean up stuff in the main window.
XXX - is there a better place to put this?
@@ -1210,7 +1210,7 @@ do_quit(void)
which we'd call here, and another routine that
calls that routine and also cleans up the UI, which
we'd call elsewhere? */
- close_cap_file(&cfile);
+ cf_close(&cfile);
/* Exit by leaving the main loop, so that any quit functions
we registered get called. */
@@ -2276,12 +2276,12 @@ main(int argc, char *argv[])
}
}
if (!rfilter_parse_failed) {
- if ((err = open_cap_file(cf_name, FALSE, &cfile)) == 0) {
- /* "open_cap_file()" succeeded, so it closed the previous
+ if ((err = cf_open(cf_name, FALSE, &cfile)) == 0) {
+ /* "cf_open()" succeeded, so it closed the previous
capture file, and thus destroyed any previous read filter
attached to "cf". */
cfile.rfcode = rfcode;
- switch (read_cap_file(&cfile, &err)) {
+ switch (cf_read(&cfile, &err)) {
case READ_SUCCESS:
case READ_ERROR:
diff --git a/tethereal.c b/tethereal.c
index 3ca726f1cc..60b19ce93e 100644
--- a/tethereal.c
+++ b/tethereal.c
@@ -1,6 +1,6 @@
/* tethereal.c
*
- * $Id: tethereal.c,v 1.196 2003/09/10 22:23:58 guy Exp $
+ * $Id: tethereal.c,v 1.197 2003/09/15 22:48:41 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -1344,7 +1344,7 @@ main(int argc, char *argv[])
}
cfile.rfcode = rfcode;
if (cf_name) {
- err = open_cap_file(cf_name, FALSE, &cfile);
+ err = cf_open(cf_name, FALSE, &cfile);
if (err != 0) {
epan_cleanup();
exit(2);
@@ -2664,7 +2664,7 @@ file_open_error_message(int err, gboolean for_writing, int file_type)
}
int
-open_cap_file(char *fname, gboolean is_tempfile, capture_file *cf)
+cf_open(char *fname, gboolean is_tempfile, capture_file *cf)
{
wtap *wth;
int err;