aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/erf.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/erf.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/erf.c')
-rw-r--r--wiretap/erf.c88
1 files changed, 46 insertions, 42 deletions
diff --git a/wiretap/erf.c b/wiretap/erf.c
index 9edef0ecbb..5ea6084449 100644
--- a/wiretap/erf.c
+++ b/wiretap/erf.c
@@ -1,4 +1,4 @@
-/*
+/* erf.c
* Copyright (c) 2003 Endace Technology Ltd, Hamilton, New Zealand.
* All rights reserved.
*
@@ -50,6 +50,7 @@
#include <wsutil/crc32.h>
+#include "wftap-int.h"
#include "wtap-int.h"
#include "file_wrappers.h"
#include "buffer.h"
@@ -64,10 +65,10 @@ static int erf_read_header(FILE_T fh,
gchar **err_info,
guint32 *bytes_read,
guint32 *packet_size);
-static gboolean erf_read(wtap *wth, int *err, gchar **err_info,
+static gboolean erf_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset);
-static gboolean erf_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, Buffer *buf,
+static gboolean erf_seek_read(wftap *wfth, gint64 seek_off,
+ void* header, Buffer *buf,
int *err, gchar **err_info);
static const struct {
@@ -86,7 +87,7 @@ static const struct {
#define NUM_ERF_ENCAPS (sizeof erf_to_wtap_map / sizeof erf_to_wtap_map[0])
-extern int erf_open(wtap *wth, int *err, gchar **err_info)
+extern int erf_open(wftap *wfth, int *err, gchar **err_info)
{
int i, n, records_for_erf_check = RECORDS_FOR_ERF_CHECK;
int valid_prev = 0;
@@ -101,6 +102,7 @@ extern int erf_open(wtap *wth, int *err, gchar **err_info)
guint8 type;
size_t r;
gchar * buffer;
+ wtap* wth = (wtap*)wfth->tap_specific_data;
memset(&prevts, 0, sizeof(prevts));
@@ -119,11 +121,11 @@ extern int erf_open(wtap *wth, int *err, gchar **err_info)
for (i = 0; i < records_for_erf_check; i++) { /* records_for_erf_check */
- r = file_read(&header,sizeof(header),wth->fh);
+ r = file_read(&header,sizeof(header),wfth->fh);
if (r == 0 ) break;
if (r != sizeof(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;
} else {
@@ -158,7 +160,7 @@ extern int erf_open(wtap *wth, int *err, gchar **err_info)
/* Skip PAD records, timestamps may not be set */
if ((header.type & 0x7F) == ERF_TYPE_PAD) {
- if (file_seek(wth->fh, packet_size, SEEK_CUR, err) == -1) {
+ if (file_seek(wfth->fh, packet_size, SEEK_CUR, err) == -1) {
return -1;
}
continue;
@@ -192,8 +194,8 @@ extern int erf_open(wtap *wth, int *err, gchar **err_info)
/* Read over the extension headers */
type = header.type;
while (type & 0x80){
- if (file_read(&erf_ext_header, sizeof(erf_ext_header),wth->fh) != sizeof(erf_ext_header)) {
- *err = file_error(wth->fh, err_info);
+ if (file_read(&erf_ext_header, sizeof(erf_ext_header),wfth->fh) != sizeof(erf_ext_header)) {
+ *err = file_error(wfth->fh, err_info);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
return -1;
@@ -213,8 +215,8 @@ extern int erf_open(wtap *wth, int *err, gchar **err_info)
case ERF_TYPE_MC_AAL2:
case ERF_TYPE_COLOR_MC_HDLC_POS:
case ERF_TYPE_AAL2: /* not an MC type but has a similar 'AAL2 ext' header */
- if (file_read(&mc_hdr,sizeof(mc_hdr),wth->fh) != sizeof(mc_hdr)) {
- *err = file_error(wth->fh, err_info);
+ if (file_read(&mc_hdr,sizeof(mc_hdr),wfth->fh) != sizeof(mc_hdr)) {
+ *err = file_error(wfth->fh, err_info);
return -1;
}
packet_size -= (guint32)sizeof(mc_hdr);
@@ -222,8 +224,8 @@ extern int erf_open(wtap *wth, int *err, gchar **err_info)
case ERF_TYPE_ETH:
case ERF_TYPE_COLOR_ETH:
case ERF_TYPE_DSM_COLOR_ETH:
- if (file_read(&eth_hdr,sizeof(eth_hdr),wth->fh) != sizeof(eth_hdr)) {
- *err = file_error(wth->fh, err_info);
+ if (file_read(&eth_hdr,sizeof(eth_hdr),wfth->fh) != sizeof(eth_hdr)) {
+ *err = file_error(wfth->fh, err_info);
return -1;
}
packet_size -= (guint32)sizeof(eth_hdr);
@@ -242,7 +244,7 @@ extern int erf_open(wtap *wth, int *err, gchar **err_info)
return 0;
}
buffer=(gchar *)g_malloc(packet_size);
- r = file_read(buffer, packet_size, wth->fh);
+ r = file_read(buffer, packet_size, wfth->fh);
g_free(buffer);
if (r != packet_size) {
@@ -257,22 +259,22 @@ extern int erf_open(wtap *wth, int *err, gchar **err_info)
} /* records_for_erf_check */
- if (file_seek(wth->fh, 0L, SEEK_SET, err) == -1) { /* rewind */
+ if (file_seek(wfth->fh, 0L, SEEK_SET, err) == -1) { /* rewind */
return -1;
}
/* This is an ERF file */
- wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_ERF;
- wth->snapshot_length = 0; /* not available in header, only in frame */
+ wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_ERF;
+ wfth->snapshot_length = 0; /* not available in header, only in frame */
/*
* Use the encapsulation for ERF records.
*/
- wth->file_encap = WTAP_ENCAP_ERF;
+ wfth->file_encap = WTAP_ENCAP_ERF;
- wth->subtype_read = erf_read;
- wth->subtype_seek_read = erf_seek_read;
- wth->tsprecision = WTAP_FILE_TSPREC_NSEC;
+ wfth->subtype_read = erf_read;
+ wfth->subtype_seek_read = erf_seek_read;
+ wfth->tsprecision = WTAP_FILE_TSPREC_NSEC;
erf_populate_interfaces(wth);
@@ -280,22 +282,23 @@ extern int erf_open(wtap *wth, int *err, gchar **err_info)
}
/* Read the next packet */
-static gboolean erf_read(wtap *wth, int *err, gchar **err_info,
+static gboolean erf_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset)
{
erf_header_t erf_header;
guint32 packet_size, bytes_read;
+ wtap* wth = (wtap*)wfth->tap_specific_data;
- *data_offset = file_tell(wth->fh);
+ *data_offset = file_tell(wfth->fh);
do {
- if (!erf_read_header(wth->fh,
+ if (!erf_read_header(wfth->fh,
&wth->phdr, &erf_header,
err, err_info, &bytes_read, &packet_size)) {
return FALSE;
}
- if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer, packet_size,
+ if (!wtap_read_packet_bytes(wfth->fh, wfth->frame_buffer, packet_size,
err, err_info))
return FALSE;
@@ -304,23 +307,24 @@ static gboolean erf_read(wtap *wth, int *err, gchar **err_info,
return TRUE;
}
-static gboolean erf_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, Buffer *buf,
+static gboolean erf_seek_read(wftap *wfth, gint64 seek_off,
+ void* header, Buffer *buf,
int *err, gchar **err_info)
{
erf_header_t erf_header;
guint32 packet_size;
+ 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;
do {
- if (!erf_read_header(wth->random_fh, phdr, &erf_header,
+ if (!erf_read_header(wfth->random_fh, phdr, &erf_header,
err, err_info, NULL, &packet_size))
return FALSE;
} while ( erf_header.type == ERF_TYPE_PAD );
- return wtap_read_packet_bytes(wth->random_fh, buf, packet_size,
+ return wtap_read_packet_bytes(wfth->random_fh, buf, packet_size,
err, err_info);
}
@@ -502,7 +506,7 @@ static int wtap_wtap_encap_to_erf_encap(int encap)
return -1;
}
-static gboolean erf_write_phdr(wtap_dumper *wdh, int encap, const union wtap_pseudo_header *pseudo_header, int * err)
+static gboolean erf_write_phdr(wftap_dumper *wdh, int encap, const union wtap_pseudo_header *pseudo_header, int * err)
{
guint8 erf_hdr[sizeof(struct erf_mc_phdr)];
guint8 erf_subhdr[((sizeof(struct erf_mc_hdr) > sizeof(struct erf_eth_hdr))?
@@ -549,7 +553,7 @@ static gboolean erf_write_phdr(wtap_dumper *wdh, int encap, const union wtap_pse
return FALSE;
}
- if (!wtap_dump_file_write(wdh, erf_hdr, size, err))
+ if (!wftap_dump_file_write(wdh, erf_hdr, size, err))
return FALSE;
wdh->bytes_dumped += size;
@@ -562,12 +566,12 @@ static gboolean erf_write_phdr(wtap_dumper *wdh, int encap, const union wtap_pse
has_more = ehdr[i*8] & 0x80;
i++;
}while(has_more && i < MAX_ERF_EHDR);
- if (!wtap_dump_file_write(wdh, ehdr, 8*i, err))
+ if (!wftap_dump_file_write(wdh, ehdr, 8*i, err))
return FALSE;
wdh->bytes_dumped += 8*i;
}
- if(!wtap_dump_file_write(wdh, erf_subhdr, subhdr_size, err))
+ if(!wftap_dump_file_write(wdh, erf_subhdr, subhdr_size, err))
return FALSE;
wdh->bytes_dumped += subhdr_size;
@@ -575,7 +579,7 @@ static gboolean erf_write_phdr(wtap_dumper *wdh, int encap, const union wtap_pse
}
static gboolean erf_dump(
- wtap_dumper *wdh,
+ wftap_dumper *wdh,
const struct wtap_pkthdr *phdr,
const guint8 *pd,
int *err)
@@ -607,7 +611,7 @@ static gboolean erf_dump(
if(!erf_write_phdr(wdh, encap, pseudo_header, err)) return FALSE;
- if(!wtap_dump_file_write(wdh, pd, phdr->caplen, err)) return FALSE;
+ if(!wftap_dump_file_write(wdh, pd, phdr->caplen, err)) return FALSE;
wdh->bytes_dumped += phdr->caplen;
/*XXX: this pads the record to its original length, which is fine in most
@@ -616,7 +620,7 @@ static gboolean erf_dump(
* More than 8 extension headers is unusual though, only the first 8 are
* written out anyway and fixing properly would require major refactor.*/
while(wdh->bytes_dumped < alignbytes){
- if(!wtap_dump_file_write(wdh, "", 1, err)) return FALSE;
+ if(!wftap_dump_file_write(wdh, "", 1, err)) return FALSE;
wdh->bytes_dumped++;
}
return TRUE;
@@ -669,18 +673,18 @@ static gboolean erf_dump(
}
if(!erf_write_phdr(wdh, WTAP_ENCAP_ERF, &other_phdr, err)) return FALSE;
- if(!wtap_dump_file_write(wdh, pd, phdr->caplen - round_down, err)) return FALSE;
+ if(!wftap_dump_file_write(wdh, pd, phdr->caplen - round_down, err)) return FALSE;
wdh->bytes_dumped += phdr->caplen - round_down;
/*add the 4 byte CRC if necessary*/
if(must_add_crc){
- if(!wtap_dump_file_write(wdh, &crc32, 4, err)) return FALSE;
+ if(!wftap_dump_file_write(wdh, &crc32, 4, err)) return FALSE;
wdh->bytes_dumped += 4;
}
/*records should be 8byte aligned, so we add padding*/
if(round_down == 0){
for(i = (gint16)alignbytes; i > 0; i--){
- if(!wtap_dump_file_write(wdh, "", 1, err)) return FALSE;
+ if(!wftap_dump_file_write(wdh, "", 1, err)) return FALSE;
wdh->bytes_dumped++;
}
}
@@ -700,7 +704,7 @@ int erf_dump_can_write_encap(int encap)
return 0;
}
-int erf_dump_open(wtap_dumper *wdh, int *err)
+int erf_dump_open(wftap_dumper *wdh, int *err)
{
wdh->subtype_write = erf_dump;
wdh->subtype_close = NULL;