summaryrefslogtreecommitdiff
path: root/wiretap/csids.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/csids.c
parentaa3a968eb6e85c47014a4cec4a2b955357b0e77f (diff)
downloadwireshark-1abeb277f5e6bd27fbaebfecc8184e37ba9d008a.tar.gz
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/csids.c')
-rw-r--r--wiretap/csids.c59
1 files changed, 31 insertions, 28 deletions
diff --git a/wiretap/csids.c b/wiretap/csids.c
index bc640f639d..7c2a4f1f87 100644
--- a/wiretap/csids.c
+++ b/wiretap/csids.c
@@ -19,6 +19,7 @@
*/
#include "config.h"
+#include "wftap-int.h"
#include "wtap-int.h"
#include "buffer.h"
#include "csids.h"
@@ -44,10 +45,10 @@ typedef struct {
gboolean byteswapped;
} csids_t;
-static gboolean csids_read(wtap *wth, int *err, gchar **err_info,
+static gboolean csids_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset);
-static gboolean csids_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
+static gboolean csids_seek_read(wftap *wfth, gint64 seek_off,
+ void* header, Buffer *buf, int *err, gchar **err_info);
static gboolean csids_read_packet(FILE_T fh, csids_t *csids,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
@@ -58,7 +59,7 @@ struct csids_header {
};
/* XXX - return -1 on I/O error and actually do something with 'err'. */
-int csids_open(wtap *wth, int *err, gchar **err_info)
+int csids_open(wftap *wfth, int *err, gchar **err_info)
{
/* There is no file header. There is only a header for each packet
* so we read a packet header and compare the caplen with iplen. They
@@ -75,30 +76,30 @@ int csids_open(wtap *wth, int *err, gchar **err_info)
csids_t *csids;
/* check the file to make sure it is a csids file. */
- bytesRead = file_read( &hdr, sizeof( struct csids_header), wth->fh );
+ bytesRead = file_read( &hdr, sizeof( struct csids_header), wfth->fh );
if( bytesRead != sizeof( struct csids_header) ) {
- *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;
}
if( hdr.zeropad != 0 || hdr.caplen == 0 ) {
- return 0;
+ return 0;
}
hdr.seconds = pntoh32( &hdr.seconds );
hdr.caplen = pntoh16( &hdr.caplen );
- bytesRead = file_read( &tmp, 2, wth->fh );
+ bytesRead = file_read( &tmp, 2, wfth->fh );
if( bytesRead != 2 ) {
- *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;
}
- bytesRead = file_read( &iplen, 2, wth->fh );
+ bytesRead = file_read( &iplen, 2, wfth->fh );
if( bytesRead != 2 ) {
- *err = file_error( wth->fh, err_info );
+ *err = file_error( wfth->fh, err_info );
if( *err != 0 && *err != WTAP_ERR_SHORT_READ ) {
return -1;
}
@@ -127,49 +128,51 @@ int csids_open(wtap *wth, int *err, gchar **err_info)
}
/* no file header. So reset the fh to 0 so we can read the first packet */
- if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
+ if (file_seek(wfth->fh, 0, SEEK_SET, err) == -1)
return -1;
csids = (csids_t *)g_malloc(sizeof(csids_t));
- wth->priv = (void *)csids;
+ wfth->priv = (void *)csids;
csids->byteswapped = byteswap;
- wth->file_encap = WTAP_ENCAP_RAW_IP;
- wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_CSIDS;
- wth->snapshot_length = 0; /* not known */
- wth->subtype_read = csids_read;
- wth->subtype_seek_read = csids_seek_read;
- wth->tsprecision = WTAP_FILE_TSPREC_SEC;
+ wfth->file_encap = WTAP_ENCAP_RAW_IP;
+ wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_CSIDS;
+ wfth->snapshot_length = 0; /* not known */
+ wfth->subtype_read = csids_read;
+ wfth->subtype_seek_read = csids_seek_read;
+ wfth->tsprecision = WTAP_FILE_TSPREC_SEC;
return 1;
}
/* Find the next packet and parse it; called from wtap_read(). */
-static gboolean csids_read(wtap *wth, int *err, gchar **err_info,
+static gboolean csids_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset)
{
- csids_t *csids = (csids_t *)wth->priv;
+ csids_t *csids = (csids_t *)wfth->priv;
+ wtap* wth = (wtap*)wfth->tap_specific_data;
- *data_offset = file_tell(wth->fh);
+ *data_offset = file_tell(wfth->fh);
- return csids_read_packet( wth->fh, csids, &wth->phdr, wth->frame_buffer,
+ return csids_read_packet( wfth->fh, csids, &wth->phdr, wfth->frame_buffer,
err, err_info );
}
/* Used to read packets in random-access fashion */
static gboolean
-csids_seek_read(wtap *wth,
+csids_seek_read(wftap *wfth,
gint64 seek_off,
- struct wtap_pkthdr *phdr,
+ void* header,
Buffer *buf,
int *err,
gchar **err_info)
{
- csids_t *csids = (csids_t *)wth->priv;
+ csids_t *csids = (csids_t *)wfth->priv;
+ struct wtap_pkthdr *phdr = (struct wtap_pkthdr *)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;
- if( !csids_read_packet( wth->random_fh, csids, phdr, buf, err, err_info ) ) {
+ if( !csids_read_packet( wfth->random_fh, csids, phdr, buf, err, err_info ) ) {
if( *err == 0 )
*err = WTAP_ERR_SHORT_READ;
return FALSE;