aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--capinfos.c6
-rw-r--r--cfile.h1
-rw-r--r--file.c6
-rw-r--r--summary.c1
-rw-r--r--summary.h3
-rw-r--r--ui/gtk/capture_file_dlg.c5
-rw-r--r--ui/gtk/summary_dlg.c4
-rw-r--r--wiretap/file_wrappers.c17
-rw-r--r--wiretap/file_wrappers.h1
-rw-r--r--wiretap/wtap.c6
-rw-r--r--wiretap/wtap.def1
-rw-r--r--wiretap/wtap.h1
12 files changed, 41 insertions, 11 deletions
diff --git a/capinfos.c b/capinfos.c
index 4ffc0646f3..7c67bb2605 100644
--- a/capinfos.c
+++ b/capinfos.c
@@ -191,6 +191,7 @@ typedef enum {
typedef struct _capture_info {
const char *filename;
guint16 file_type;
+ gboolean iscompressed;
int file_encap;
gint64 filesize;
@@ -358,7 +359,9 @@ print_stats(const gchar *filename, capture_info *cf_info)
stop_time_t = (time_t)cf_info->stop_time;
if (filename) printf ("File name: %s\n", filename);
- if (cap_file_type) printf ("File type: %s\n", file_type_string);
+ if (cap_file_type) printf ("File type: %s%s\n",
+ file_type_string,
+ cf_info->iscompressed ? " (gzip compressed)" : "");
if (cap_file_encap) printf ("File encapsulation: %s\n", file_encap_string);
if (cap_file_encap && (cf_info->file_encap == WTAP_ENCAP_PER_PACKET)) {
int i;
@@ -749,6 +752,7 @@ process_cap_file(wtap *wth, const char *filename)
/* File Type */
cf_info.file_type = wtap_file_type(wth);
+ cf_info.iscompressed = wtap_iscompressed(wth);
/* File Encapsulation */
cf_info.file_encap = wtap_file_encap(wth);
diff --git a/cfile.h b/cfile.h
index 63bd0eee90..d33f361fb4 100644
--- a/cfile.h
+++ b/cfile.h
@@ -73,6 +73,7 @@ typedef struct _capture_file {
gboolean unsaved_changes; /* Does the capture file have changes that have not been saved? */
gint64 f_datalen; /* Size of capture file data (uncompressed) */
guint16 cd_t; /* File type of capture file */
+ gboolean iscompressed; /* TRUE if the file is compressed */
int lnk_t; /* Link-layer type with which to save capture */
guint32 count; /* Total number of frames */
guint32 displayed_count; /* Number of displayed frames */
diff --git a/file.c b/file.c
index e04d4a4194..bfbc293ab1 100644
--- a/file.c
+++ b/file.c
@@ -530,6 +530,9 @@ cf_read(capture_file *cf, gboolean reloading)
else
cf_callback_invoke(cf_cb_file_read_started, cf);
+ /* Record whether the file is compressed. */
+ cf->iscompressed = wtap_iscompressed(cf->wth);
+
/* Find the size of the file. */
size = wtap_file_size(cf->wth, NULL);
@@ -3818,7 +3821,8 @@ cf_save_packets(capture_file *cf, const char *fname, guint save_format,
cf_callback_invoke(cf_cb_file_save_started, (gpointer)fname);
- if (save_format == cf->cd_t && !cf->unsaved_changes) {
+ if (save_format == cf->cd_t && compressed == cf->iscompressed
+ && !cf->unsaved_changes) {
/* We're saving in the format it's already in, and there are no
changes we have in memory that aren't saved to the file, so
we can just move or copy the raw data. */
diff --git a/summary.c b/summary.c
index 3e3af32148..74f3874c58 100644
--- a/summary.c
+++ b/summary.c
@@ -141,6 +141,7 @@ summary_fill_in(capture_file *cf, summary_tally *st)
st->filename = cf->filename;
st->file_length = cf->f_datalen;
st->file_type = cf->cd_t;
+ st->iscompressed = cf->iscompressed;
st->is_tempfile = cf->is_tempfile;
st->encap_type = cf->lnk_t;
st->has_snap = cf->has_snap;
diff --git a/summary.h b/summary.h
index f359990345..ee3f712b6f 100644
--- a/summary.h
+++ b/summary.h
@@ -33,7 +33,7 @@ typedef struct iface_options_tag {
char *name;
char *descr;
char *cfilter;
- char *isb_comment;
+ char *isb_comment;
guint64 drops; /**< number of packet drops */
gboolean drops_known; /**< TRUE if number of packet drops is known */
gboolean has_snap; /**< TRUE if maximum capture packet length is known */
@@ -64,6 +64,7 @@ typedef struct _summary_tally {
const char *filename;
gint64 file_length; /**< file length in bytes */
int file_type; /**< wiretap file type */
+ int iscompressed; /**< TRUE if file is compressed */
int encap_type; /**< wiretap encapsulation type */
gboolean has_snap; /**< TRUE if maximum capture packet length is known */
int snap; /**< Maximum captured packet length */
diff --git a/ui/gtk/capture_file_dlg.c b/ui/gtk/capture_file_dlg.c
index 202d0ef373..9730443fcc 100644
--- a/ui/gtk/capture_file_dlg.c
+++ b/ui/gtk/capture_file_dlg.c
@@ -1190,10 +1190,7 @@ file_save_cmd(action_after_save_e action_after_save, gpointer action_after_save_
a copy and free it later. */
fname = g_strdup(cfile.filename);
- /* XXX - if we're editing a compressed capture file, we should
- remember that it's compressed, and write it out in compressed
- form. */
- cf_save_packets(&cfile, fname, cfile.cd_t, FALSE);
+ cf_save_packets(&cfile, fname, cfile.cd_t, cfile.iscompressed);
g_free(fname);
}
diff --git a/ui/gtk/summary_dlg.c b/ui/gtk/summary_dlg.c
index bf0ba04f96..18bd8831de 100644
--- a/ui/gtk/summary_dlg.c
+++ b/ui/gtk/summary_dlg.c
@@ -238,7 +238,9 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
add_string_to_table(table, &row, "Length:", string_buff);
/* format */
- g_snprintf(string_buff, SUM_STR_MAX, "%s", wtap_file_type_string(summary.file_type));
+ g_snprintf(string_buff, SUM_STR_MAX, "%s%s",
+ wtap_file_type_string(summary.file_type),
+ summary.iscompressed? " (gzip compressed)" : "");
add_string_to_table(table, &row, "Format:", string_buff);
/* encapsulation */
diff --git a/wiretap/file_wrappers.c b/wiretap/file_wrappers.c
index 94840f01bf..67437acee9 100644
--- a/wiretap/file_wrappers.c
+++ b/wiretap/file_wrappers.c
@@ -121,6 +121,7 @@ struct wtap_reader {
gint64 start; /* where the gzip data started, for rewinding */
gint64 raw; /* where the raw data started, for seeking */
int compression; /* 0: ?, 1: uncompressed, 2: zlib */
+ gboolean is_compressed; /* FALSE if completely uncompressed, TRUE otherwise */
/* seek request */
gint64 skip; /* amount to skip (already rewound if backwards) */
int seek; /* true if seek request pending */
@@ -128,8 +129,8 @@ struct wtap_reader {
int err; /* error code */
const char *err_info; /* additional error information string for some errors */
- unsigned int avail_in; /* number of bytes available at next_in */
- unsigned char *next_in; /* next input byte */
+ unsigned int avail_in; /* number of bytes available at next_in */
+ unsigned char *next_in; /* next input byte */
#ifdef HAVE_LIBZ
/* zlib inflate stream */
z_stream strm; /* stream structure in-place (not a pointer) */
@@ -140,7 +141,7 @@ struct wtap_reader {
void *fast_seek_cur;
};
-/* values for gz_state compression */
+/* values for wtap_reader compression */
#define UNKNOWN 0 /* look for a gzip header */
#define UNCOMPRESSED 1 /* copy input directly */
#ifdef HAVE_LIBZ
@@ -651,6 +652,7 @@ gz_head(FILE_T state)
inflateReset(&(state->strm));
state->strm.adler = crc32(0L, Z_NULL, 0);
state->compression = ZLIB;
+ state->is_compressed = TRUE;
#ifdef Z_BLOCK
if (state->fast_seek) {
struct zlib_cur_seek_point *cur = g_malloc(sizeof(struct zlib_cur_seek_point));
@@ -786,6 +788,9 @@ filed_open(int fd)
/* open the file with the appropriate mode (or just use fd) */
state->fd = fd;
+ /* we don't yet know whether it's compressed */
+ state->is_compressed = FALSE;
+
/* save the current position for rewinding (only if reading) */
state->start = ws_lseek64(state->fd, 0, SEEK_CUR);
if (state->start == -1) state->start = 0;
@@ -1085,6 +1090,12 @@ file_fstat(FILE_T stream, ws_statb64 *statb, int *err)
return 0;
}
+gboolean
+file_iscompressed(FILE_T stream)
+{
+ return stream->is_compressed;
+}
+
int
file_read(void *buf, unsigned int len, FILE_T file)
{
diff --git a/wiretap/file_wrappers.h b/wiretap/file_wrappers.h
index b594a7330b..4ef46fb297 100644
--- a/wiretap/file_wrappers.h
+++ b/wiretap/file_wrappers.h
@@ -35,6 +35,7 @@ extern gint64 file_skip(FILE_T file, gint64 delta, int *err);
extern gint64 file_tell(FILE_T stream);
extern gint64 file_tell_raw(FILE_T stream);
extern int file_fstat(FILE_T stream, ws_statb64 *statb, int *err);
+extern gboolean file_iscompressed(FILE_T stream);
extern int file_read(void *buf, unsigned int count, FILE_T file);
extern int file_getc(FILE_T stream);
extern char *file_gets(char *buf, int len, FILE_T stream);
diff --git a/wiretap/wtap.c b/wiretap/wtap.c
index 0d58ffa2b5..cf63c9c053 100644
--- a/wiretap/wtap.c
+++ b/wiretap/wtap.c
@@ -78,6 +78,12 @@ wtap_file_type(wtap *wth)
return wth->file_type;
}
+gboolean
+wtap_iscompressed(wtap *wth)
+{
+ return file_iscompressed((wth->fh == NULL) ? wth->random_fh : wth->fh);
+}
+
guint
wtap_snapshot_length(wtap *wth)
{
diff --git a/wiretap/wtap.def b/wiretap/wtap.def
index a677312e8a..48b8316265 100644
--- a/wiretap/wtap.def
+++ b/wiretap/wtap.def
@@ -61,6 +61,7 @@ wtap_fstat
wtap_get_bytes_dumped
wtap_get_num_encap_types
wtap_get_num_file_types
+wtap_iscompressed
wtap_open_offline
wtap_pcap_encap_to_wtap_encap
wtap_phdr
diff --git a/wiretap/wtap.h b/wiretap/wtap.h
index 45c26f4a17..2146344415 100644
--- a/wiretap/wtap.h
+++ b/wiretap/wtap.h
@@ -1074,6 +1074,7 @@ guint8 *wtap_buf_ptr(wtap *wth);
* from the file so far. */
gint64 wtap_read_so_far(wtap *wth);
gint64 wtap_file_size(wtap *wth, int *err);
+gboolean wtap_iscompressed(wtap *wth);
guint wtap_snapshot_length(wtap *wth); /* per file */
int wtap_file_type(wtap *wth);
int wtap_file_encap(wtap *wth);