aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2012-05-24 05:05:29 +0000
committerGuy Harris <guy@alum.mit.edu>2012-05-24 05:05:29 +0000
commitcf6d9841e37906448ad1a571a648140325efcae0 (patch)
tree8e14522dbdae5295fd41a236e7f9e49daab36c4e /wiretap
parent73888ed977e7ba3356d3c5e31c182508d576dfc1 (diff)
Keep track, in Wiretap, of whether the file is compressed, and provide
an API to fetch that. When doing "Save" on a compressed file, write it out compressed. In the Statistics -> Summary dialog and in capinfos, report whether the file is gzip-compressed. svn path=/trunk/; revision=42818
Diffstat (limited to 'wiretap')
-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
5 files changed, 23 insertions, 3 deletions
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);