summaryrefslogtreecommitdiff
path: root/wiretap
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2011-05-09 08:12:26 +0000
committerGuy Harris <guy@alum.mit.edu>2011-05-09 08:12:26 +0000
commit3de2b1be7405adac31bd796f3380b9d8edbe0f99 (patch)
treeb444b752e4435e0b436bbf8eef5c96af9f35a2de /wiretap
parent88a1ed85e3156e80c3fed4848d651aae433dc8d8 (diff)
downloadwireshark-3de2b1be7405adac31bd796f3380b9d8edbe0f99.tar.gz
Get rid of the fd member of a wth structure; the FILE_T's in that
structure include a file descriptor. Add a wtap_fstat() for the file readers that use file times to generate time stamps (we really need a way to say "this file has no time stamps" or "this file has only relative time stamps). svn path=/trunk/; revision=37026
Diffstat (limited to 'wiretap')
-rw-r--r--wiretap/ascendtext.c5
-rw-r--r--wiretap/ber.c6
-rw-r--r--wiretap/file_access.c11
-rw-r--r--wiretap/file_wrappers.c16
-rw-r--r--wiretap/file_wrappers.h2
-rw-r--r--wiretap/tnef.c6
-rw-r--r--wiretap/wtap-int.h5
-rw-r--r--wiretap/wtap.c18
8 files changed, 45 insertions, 24 deletions
diff --git a/wiretap/ascendtext.c b/wiretap/ascendtext.c
index 801a01fe9b..dd8e750dd8 100644
--- a/wiretap/ascendtext.c
+++ b/wiretap/ascendtext.c
@@ -176,7 +176,7 @@ found:
int ascend_open(wtap *wth, int *err, gchar **err_info)
{
gint64 offset;
- struct stat statbuf;
+ ws_statb64 statbuf;
guint8 buf[ASCEND_MAX_PKT_LEN];
ascend_pkthdr header;
gint64 dummy_seek_start;
@@ -235,8 +235,7 @@ int ascend_open(wtap *wth, int *err, gchar **err_info)
packet's timestamp from the capture file's ctime, which gives us an
offset that we can apply to each packet.
*/
- if (fstat(wth->fd, &statbuf) == -1) {
- *err = errno;
+ if (wtap_fstat(wth, &statbuf, err) == -1) {
g_free(ascend);
return -1;
}
diff --git a/wiretap/ber.c b/wiretap/ber.c
index 11a37432ba..fba02f240f 100644
--- a/wiretap/ber.c
+++ b/wiretap/ber.c
@@ -47,7 +47,7 @@ static gboolean ber_read(wtap *wth, int *err, gchar **err_info, gint64 *data_off
guint8 *buf;
gint64 file_size;
int packet_size;
- struct stat statb;
+ ws_statb64 statb;
*err = 0;
@@ -82,10 +82,8 @@ static gboolean ber_read(wtap *wth, int *err, gchar **err_info, gint64 *data_off
wth->phdr.caplen = packet_size;
wth->phdr.len = packet_size;
- if (fstat(wth->fd, &statb) == -1) {
- *err = errno;
+ if (wtap_fstat(wth, &statb, err) == -1)
return FALSE;
- }
wth->phdr.ts.secs = statb.st_mtime;
wth->phdr.ts.nsecs = 0;
diff --git a/wiretap/file_access.c b/wiretap/file_access.c
index ed213e6df8..c66a149ad2 100644
--- a/wiretap/file_access.c
+++ b/wiretap/file_access.c
@@ -222,6 +222,7 @@ void wtap_register_open_routine(wtap_open_routine_t open_routine, gboolean has_m
wtap* wtap_open_offline(const char *filename, int *err, char **err_info,
gboolean do_random)
{
+ int fd;
ws_statb64 statb;
wtap *wth;
unsigned int i;
@@ -296,23 +297,23 @@ wtap* wtap_open_offline(const char *filename, int *err, char **err_info,
* a file_close of wth->fh closing the standard
* input of the process.
*/
- wth->fd = ws_dup(0);
- if (wth->fd < 0) {
+ fd = ws_dup(0);
+ if (fd < 0) {
*err = errno;
g_free(wth);
return NULL;
}
#ifdef _WIN32
- if (_setmode(wth->fd, O_BINARY) == -1) {
+ if (_setmode(fd, O_BINARY) == -1) {
/* "Shouldn't happen" */
*err = errno;
g_free(wth);
return NULL;
}
#endif
- if (!(wth->fh = filed_open(wth->fd))) {
+ if (!(wth->fh = filed_open(fd))) {
*err = errno;
- ws_close(wth->fd);
+ ws_close(fd);
g_free(wth);
return NULL;
}
diff --git a/wiretap/file_wrappers.c b/wiretap/file_wrappers.c
index ee3ead8099..bd4207d885 100644
--- a/wiretap/file_wrappers.c
+++ b/wiretap/file_wrappers.c
@@ -1006,11 +1006,23 @@ file_tell(FILE_T stream)
return stream->pos + (stream->seek ? stream->skip : 0);
}
-gint64 file_tell_raw(FILE_T stream)
+gint64
+file_tell_raw(FILE_T stream)
{
return stream->raw_pos;
}
+int
+file_fstat(FILE_T stream, ws_statb64 *statb, int *err)
+{
+ if (ws_fstat64(stream->fd, statb) == -1) {
+ if (err != NULL)
+ *err = errno;
+ return -1;
+ }
+ return 0;
+}
+
int
file_read(void *buf, unsigned int len, FILE_T file)
{
@@ -1206,7 +1218,7 @@ file_close(FILE_T file)
file->err = 0;
file->err_info = NULL;
g_free(file);
- return close(fd);
+ return ws_close(fd);
}
#ifdef HAVE_LIBZ
diff --git a/wiretap/file_wrappers.h b/wiretap/file_wrappers.h
index 7929319a61..cf223f4332 100644
--- a/wiretap/file_wrappers.h
+++ b/wiretap/file_wrappers.h
@@ -18,7 +18,6 @@
* 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 __FILE_H__
@@ -27,6 +26,7 @@
extern gint64 file_seek(FILE_T stream, gint64 offset, int whence, 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 int file_error(FILE_T fh, gchar **err_info);
extern FILE_T file_open(const char *path);
diff --git a/wiretap/tnef.c b/wiretap/tnef.c
index ce839fcc13..1fca687805 100644
--- a/wiretap/tnef.c
+++ b/wiretap/tnef.c
@@ -40,7 +40,7 @@ static gboolean tnef_read(wtap *wth, int *err, gchar **err_info, gint64 *data_of
guint8 *buf;
gint64 file_size;
int packet_size;
- struct stat statb;
+ ws_statb64 statb;
*err = 0;
@@ -75,10 +75,8 @@ static gboolean tnef_read(wtap *wth, int *err, gchar **err_info, gint64 *data_of
wth->phdr.caplen = packet_size;
wth->phdr.len = packet_size;
- if (fstat(wth->fd, &statb) == -1) {
- *err = errno;
+ if (wtap_fstat(wth, &statb, err) == -1)
return FALSE;
- }
wth->phdr.ts.secs = statb.st_mtime;
wth->phdr.ts.nsecs = 0;
diff --git a/wiretap/wtap-int.h b/wiretap/wtap-int.h
index 9691ce8eff..96e3a68ba5 100644
--- a/wiretap/wtap-int.h
+++ b/wiretap/wtap-int.h
@@ -39,16 +39,19 @@
#include <zlib.h>
#endif /* HAVE_LIBZ */
+#include <wsutil/file_util.h>
+
typedef struct wtap_reader *FILE_T;
#include "wtap.h"
+int wtap_fstat(wtap *wth, ws_statb64 *statb, int *err);
+
typedef gboolean (*subtype_read_func)(struct wtap*, int*, char**, gint64*);
typedef gboolean (*subtype_seek_read_func)(struct wtap*, gint64, union wtap_pseudo_header*,
guint8*, int, int *, char **);
struct wtap {
FILE_T fh;
- int fd; /* File descriptor for cap file */
FILE_T random_fh; /* Secondary FILE_T for random access */
int file_type;
int snapshot_length;
diff --git a/wiretap/wtap.c b/wiretap/wtap.c
index 145567a975..e494a9e757 100644
--- a/wiretap/wtap.c
+++ b/wiretap/wtap.c
@@ -54,14 +54,24 @@ wtap_file_size(wtap *wth, int *err)
{
ws_statb64 statb;
- if (ws_fstat64(wth->fd, &statb) == -1) {
- if (err != NULL)
- *err = errno;
+ if (file_fstat((wth->fh == NULL) ? wth->random_fh : wth->fh,
+ &statb, err) == -1)
return -1;
- }
return statb.st_size;
}
+/*
+ * Do an fstat on the file.
+ */
+int
+wtap_fstat(wtap *wth, ws_statb64 *statb, int *err)
+{
+ if (file_fstat((wth->fh == NULL) ? wth->random_fh : wth->fh,
+ statb, err) == -1)
+ return -1;
+ return 0;
+}
+
int
wtap_file_type(wtap *wth)
{