aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/visual.c
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2014-05-08 22:59:19 -0400
committerMichael Mann <mmann78@netscape.net>2014-05-09 03:04:39 +0000
commit1abeb277f5e6bd27fbaebfecc8184e37ba9d008a (patch)
tree8cc6eaa5a6982454a00adc600fa4aab02bec3d73 /wiretap/visual.c
parentaa3a968eb6e85c47014a4cec4a2b955357b0e77f (diff)
Refactor Wiretap
Start of refactoring Wiretap and breaking structures down into "generally useful fields for dissection" and "capture specific". Since this in intended as a "base" for Wiretap and Filetap, the "wft" prefix is used for "common" functionality. The "architectural" changes can be found in cfile.h, wtap.h, wtap-int.h and (new file) wftap-int.h. Most of the other (painstaking) changes were really just the result of compiling those new architecture changes. bug:9607 Change-Id: Ife858a61760d7a8a03be073546c0e7e582cab2ae Reviewed-on: https://code.wireshark.org/review/1485 Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'wiretap/visual.c')
-rw-r--r--wiretap/visual.c89
1 files changed, 46 insertions, 43 deletions
diff --git a/wiretap/visual.c b/wiretap/visual.c
index cfa03bceac..c6c21dcfb4 100644
--- a/wiretap/visual.c
+++ b/wiretap/visual.c
@@ -23,6 +23,7 @@
#include "config.h"
#include <errno.h>
#include <string.h>
+#include "wftap-int.h"
#include "wtap-int.h"
#include "file_wrappers.h"
#include "buffer.h"
@@ -158,20 +159,20 @@ struct visual_write_info
/* Local functions to handle file reads and writes */
-static gboolean visual_read(wtap *wth, int *err, gchar **err_info,
+static gboolean visual_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset);
-static gboolean visual_seek_read(wtap *wth, gint64 seek_off,
+static gboolean visual_seek_read(wftap *wfth, gint64 seek_off,
+ void* header, Buffer *buf, int *err, gchar **err_info);
+static gboolean visual_read_packet(wftap *wfth, FILE_T fh,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
-static gboolean visual_read_packet(wtap *wth, FILE_T fh,
- struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
-static gboolean visual_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
+static gboolean visual_dump(wftap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err);
-static gboolean visual_dump_close(wtap_dumper *wdh, int *err);
-static void visual_dump_free(wtap_dumper *wdh);
+static gboolean visual_dump_close(wftap_dumper *wdh, int *err);
+static void visual_dump_free(wftap_dumper *wdh);
/* Open a file for reading */
-int visual_open(wtap *wth, int *err, gchar **err_info)
+int visual_open(wftap *wfth, int *err, gchar **err_info)
{
int bytes_read;
char magic[sizeof visual_magic];
@@ -181,10 +182,10 @@ int visual_open(wtap *wth, int *err, gchar **err_info)
/* Check the magic string at the start of the file */
errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read(magic, sizeof magic, wth->fh);
+ bytes_read = file_read(magic, sizeof magic, wfth->fh);
if (bytes_read != sizeof magic)
{
- *err = file_error(wth->fh, err_info);
+ *err = file_error(wfth->fh, err_info);
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
return -1;
return 0;
@@ -196,10 +197,10 @@ int visual_open(wtap *wth, int *err, gchar **err_info)
/* Read the rest of the file header. */
errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read(&vfile_hdr, sizeof vfile_hdr, wth->fh);
+ bytes_read = file_read(&vfile_hdr, sizeof vfile_hdr, wfth->fh);
if (bytes_read != sizeof vfile_hdr)
{
- *err = file_error(wth->fh, err_info);
+ *err = file_error(wfth->fh, err_info);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
return -1;
@@ -257,18 +258,18 @@ int visual_open(wtap *wth, int *err, gchar **err_info)
}
/* Fill in the wiretap struct with data from the file header */
- wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_VISUAL_NETWORKS;
- wth->file_encap = encap;
- wth->snapshot_length = pletoh16(&vfile_hdr.max_length);
+ wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_VISUAL_NETWORKS;
+ wfth->file_encap = encap;
+ wfth->snapshot_length = pletoh16(&vfile_hdr.max_length);
/* Set up the pointers to the handlers for this file type */
- wth->subtype_read = visual_read;
- wth->subtype_seek_read = visual_seek_read;
- wth->tsprecision = WTAP_FILE_TSPREC_USEC;
+ wfth->subtype_read = visual_read;
+ wfth->subtype_seek_read = visual_seek_read;
+ wfth->tsprecision = WTAP_FILE_TSPREC_USEC;
/* Add Visual-specific information to the wiretap struct for later use. */
visual = (struct visual_read_info *)g_malloc(sizeof(struct visual_read_info));
- wth->priv = (void *)visual;
+ wfth->priv = (void *)visual;
visual->num_pkts = pletoh32(&vfile_hdr.num_pkts);
visual->start_time = ((double) pletoh32(&vfile_hdr.start_time)) * 1000000;
visual->current_pkt = 1;
@@ -281,10 +282,11 @@ int visual_open(wtap *wth, int *err, gchar **err_info)
in a loop to sequentially read the entire file one time. After
the file has been read once, any Future access to the packets is
done through seek_read. */
-static gboolean visual_read(wtap *wth, int *err, gchar **err_info,
+static gboolean visual_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset)
{
- struct visual_read_info *visual = (struct visual_read_info *)wth->priv;
+ struct visual_read_info *visual = (struct visual_read_info *)wfth->priv;
+ wtap* wth = (wtap*)wfth->tap_specific_data;
/* Check for the end of the packet data. Note that a check for file EOF
will not work because there are index values stored after the last
@@ -296,22 +298,23 @@ static gboolean visual_read(wtap *wth, int *err, gchar **err_info,
}
visual->current_pkt++;
- *data_offset = file_tell(wth->fh);
+ *data_offset = file_tell(wfth->fh);
- return visual_read_packet(wth, wth->fh, &wth->phdr, wth->frame_buffer,
+ return visual_read_packet(wfth, wfth->fh, &wth->phdr, wfth->frame_buffer,
err, err_info);
}
/* Read packet header and data for random access. */
-static gboolean visual_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
+static gboolean visual_seek_read(wftap *wfth, gint64 seek_off,
+ void* header, Buffer *buf, int *err, gchar **err_info)
{
+ struct wtap_pkthdr *phdr = (struct wtap_pkthdr *)header;
/* Seek to the packet header */
- if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
+ if (file_seek(wfth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
/* Read the packet. */
- if (!visual_read_packet(wth, wth->random_fh, phdr, buf, err, err_info)) {
+ if (!visual_read_packet(wfth, wfth->random_fh, phdr, buf, err, err_info)) {
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
return FALSE;
@@ -320,10 +323,10 @@ static gboolean visual_seek_read(wtap *wth, gint64 seek_off,
}
static gboolean
-visual_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
+visual_read_packet(wftap *wfth, FILE_T fh, struct wtap_pkthdr *phdr,
Buffer *buf, int *err, gchar **err_info)
{
- struct visual_read_info *visual = (struct visual_read_info *)wth->priv;
+ struct visual_read_info *visual = (struct visual_read_info *)wfth->priv;
struct visual_pkt_hdr vpkt_hdr;
int bytes_read;
guint32 packet_size;
@@ -383,7 +386,7 @@ visual_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
all encapsulations is direction. This either goes in the p2p or the
X.25 pseudo header. It would probably be better to move this up
into the phdr. */
- switch (wth->file_encap)
+ switch (wfth->file_encap)
{
case WTAP_ENCAP_ETHERNET:
/* Ethernet has a 4-byte FCS. */
@@ -554,7 +557,7 @@ visual_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
if (!wtap_read_packet_bytes(fh, buf, packet_size, err, err_info))
return FALSE;
- if (wth->file_encap == WTAP_ENCAP_CHDLC_WITH_PHDR)
+ if (wfth->file_encap == WTAP_ENCAP_CHDLC_WITH_PHDR)
{
/* Fill in the encapsulation. Visual files have a media type in the
file header and an encapsulation type in each packet header. Files
@@ -635,7 +638,7 @@ int visual_dump_can_write_encap(int encap)
/* Open a file for writing.
Returns TRUE on success, FALSE on failure; sets "*err" to an
error code on failure */
-gboolean visual_dump_open(wtap_dumper *wdh, int *err)
+gboolean visual_dump_open(wftap_dumper *wdh, int *err)
{
struct visual_write_info *visual;
@@ -655,7 +658,7 @@ gboolean visual_dump_open(wtap_dumper *wdh, int *err)
/* All of the fields in the file header aren't known yet so
just skip over it for now. It will be created after all
of the packets have been written. */
- if (wtap_dump_file_seek(wdh, CAPTUREFILE_HEADER_SIZE, SEEK_SET, err) == -1)
+ if (wftap_dump_file_seek(wdh, CAPTUREFILE_HEADER_SIZE, SEEK_SET, err) == -1)
return FALSE;
return TRUE;
@@ -664,7 +667,7 @@ gboolean visual_dump_open(wtap_dumper *wdh, int *err)
/* Write a packet to a Visual dump file.
Returns TRUE on success, FALSE on failure. */
-static gboolean visual_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
+static gboolean visual_dump(wftap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err)
{
const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header;
@@ -756,11 +759,11 @@ static gboolean visual_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
vpkt_hdr.status = GUINT32_TO_LE(packet_status);
/* Write the packet header. */
- if (!wtap_dump_file_write(wdh, &vpkt_hdr, hdr_size, err))
+ if (!wftap_dump_file_write(wdh, &vpkt_hdr, hdr_size, err))
return FALSE;
/* Write the packet data */
- if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err))
+ if (!wftap_dump_file_write(wdh, pd, phdr->caplen, err))
return FALSE;
/* Store the frame offset in the index table. */
@@ -783,7 +786,7 @@ static gboolean visual_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
/* Finish writing to a dump file.
Returns TRUE on success, FALSE on failure. */
-static gboolean visual_dump_close(wtap_dumper *wdh, int *err)
+static gboolean visual_dump_close(wftap_dumper *wdh, int *err)
{
struct visual_write_info * visual = (struct visual_write_info *)wdh->priv;
size_t n_to_write;
@@ -801,7 +804,7 @@ static gboolean visual_dump_close(wtap_dumper *wdh, int *err)
{
/* Write the index table to the file. */
n_to_write = visual->index_table_index * sizeof *visual->index_table;
- if (!wtap_dump_file_write(wdh, visual->index_table, n_to_write, err))
+ if (!wftap_dump_file_write(wdh, visual->index_table, n_to_write, err))
{
visual_dump_free(wdh);
return FALSE;
@@ -809,11 +812,11 @@ static gboolean visual_dump_close(wtap_dumper *wdh, int *err)
}
/* Write the magic number at the start of the file. */
- if (wtap_dump_file_seek(wdh, 0, SEEK_SET, err) == -1)
- return FALSE;
+ if (wftap_dump_file_seek(wdh, 0, SEEK_SET, err) == -1)
+ return FALSE;
magicp = visual_magic;
magic_size = sizeof visual_magic;
- if (!wtap_dump_file_write(wdh, magicp, magic_size, err))
+ if (!wftap_dump_file_write(wdh, magicp, magic_size, err))
{
visual_dump_free(wdh);
return FALSE;
@@ -855,7 +858,7 @@ static gboolean visual_dump_close(wtap_dumper *wdh, int *err)
}
/* Write the file header following the magic bytes. */
- if (!wtap_dump_file_write(wdh, &vfile_hdr, sizeof vfile_hdr, err))
+ if (!wftap_dump_file_write(wdh, &vfile_hdr, sizeof vfile_hdr, err))
{
visual_dump_free(wdh);
return FALSE;
@@ -868,7 +871,7 @@ static gboolean visual_dump_close(wtap_dumper *wdh, int *err)
/* Free the memory allocated by a visual file writer. */
-static void visual_dump_free(wtap_dumper *wdh)
+static void visual_dump_free(wftap_dumper *wdh)
{
struct visual_write_info * visual = (struct visual_write_info *)wdh->priv;