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>
This commit is contained in:
Michael Mann 2014-05-08 22:59:19 -04:00
parent aa3a968eb6
commit 1abeb277f5
143 changed files with 3550 additions and 3082 deletions

View File

@ -408,7 +408,7 @@ time_string(time_t timer, capture_info *cf_info, gboolean want_lf)
g_snprintf(time_string_buf, 20, "%lu%s", (unsigned long)timer, lf);
return time_string_buf;
} else {
time_string_ctime = ctime(&timer);
time_string_ctime = asctime(localtime(&timer));
if (time_string_ctime == NULL) {
g_snprintf(time_string_buf, 20, "Not representable%s", lf);
return time_string_buf;
@ -800,7 +800,7 @@ print_stats_table(const gchar *filename, capture_info *cf_info)
}
static int
process_cap_file(wtap *wth, const char *filename)
process_cap_file(wftap *wth, const char *filename)
{
int status = 0;
int err;
@ -868,7 +868,7 @@ process_cap_file(wtap *wth, const char *filename)
}
/* Per-packet encapsulation */
if (wtap_file_encap(wth) == WTAP_ENCAP_PER_PACKET) {
if (wftap_file_encap(wth) == WTAP_ENCAP_PER_PACKET) {
if ((phdr->pkt_encap > 0) && (phdr->pkt_encap < WTAP_NUM_ENCAP_TYPES)) {
cf_info.encap_counts[phdr->pkt_encap] += 1;
} else {
@ -905,7 +905,7 @@ process_cap_file(wtap *wth, const char *filename)
}
/* File size */
size = wtap_file_size(wth, &err);
size = wftap_file_size(wth, &err);
if (size == -1) {
fprintf(stderr,
"capinfos: Can't get size of \"%s\": %s.\n",
@ -917,14 +917,14 @@ process_cap_file(wtap *wth, const char *filename)
cf_info.filesize = size;
/* File Type */
cf_info.file_type = wtap_file_type_subtype(wth);
cf_info.iscompressed = wtap_iscompressed(wth);
cf_info.file_type = wftap_file_type_subtype(wth);
cf_info.iscompressed = wftap_iscompressed(wth);
/* File Encapsulation */
cf_info.file_encap = wtap_file_encap(wth);
cf_info.file_encap = wftap_file_encap(wth);
/* Packet size limit (snaplen) */
cf_info.snaplen = wtap_snapshot_length(wth);
cf_info.snaplen = wftap_snapshot_length(wth);
if (cf_info.snaplen > 0)
cf_info.snap_set = TRUE;
else
@ -1098,7 +1098,7 @@ hash_to_str(const unsigned char *hash, size_t length, char *str) {
int
main(int argc, char *argv[])
{
wtap *wth;
wftap *wth;
int err;
gchar *err_info;
int opt;

View File

@ -68,7 +68,7 @@ packet_counts *counts, gint wtap_linktype, const guchar *pd, guint32 caplen, uni
typedef struct _info_data {
packet_counts counts; /* several packet type counters */
struct wtap* wtap; /* current wtap file */
struct wftap* wftap; /* current wftap file */
capture_info ui; /* user interface data */
} info_data_t;
@ -94,7 +94,7 @@ void capture_info_open(capture_session *cap_session)
info_data.counts.i2c_event = 0;
info_data.counts.i2c_data = 0;
info_data.wtap = NULL;
info_data.wftap = NULL;
info_data.ui.counts = &info_data.counts;
capture_info_ui_create(&info_data.ui, cap_session);
@ -216,12 +216,12 @@ gboolean capture_info_new_file(const char *new_filename)
gchar *err_msg;
if(info_data.wtap != NULL) {
wtap_close(info_data.wtap);
if(info_data.wftap != NULL) {
wftap_close(info_data.wftap);
}
info_data.wtap = wtap_open_offline(new_filename, WTAP_TYPE_AUTO, &err, &err_info, FALSE);
if (!info_data.wtap) {
info_data.wftap = wtap_open_offline(new_filename, WTAP_TYPE_AUTO, &err, &err_info, FALSE);
if (!info_data.wftap) {
err_msg = g_strdup_printf(cf_open_error_message(err, err_info, FALSE, WTAP_FILE_TYPE_SUBTYPE_UNKNOWN),
new_filename);
g_warning("capture_info_new_file: %d (%s)", err, err_msg);
@ -249,12 +249,12 @@ void capture_info_new_packets(int to_read)
/*g_warning("new packets: %u", to_read);*/
while (to_read > 0) {
wtap_cleareof(info_data.wtap);
if (wtap_read(info_data.wtap, &err, &err_info, &data_offset)) {
phdr = wtap_phdr(info_data.wtap);
wftap_cleareof(info_data.wftap);
if (wtap_read(info_data.wftap, &err, &err_info, &data_offset)) {
phdr = wtap_phdr(info_data.wftap);
pseudo_header = &phdr->pseudo_header;
wtap_linktype = phdr->pkt_encap;
buf = wtap_buf_ptr(info_data.wtap);
buf = wftap_buf_ptr(info_data.wftap);
capture_info_packet(&info_data.counts, wtap_linktype, buf, phdr->caplen, pseudo_header);
@ -271,8 +271,8 @@ void capture_info_new_packets(int to_read)
void capture_info_close(void)
{
capture_info_ui_destroy(&info_data.ui);
if(info_data.wtap)
wtap_close(info_data.wtap);
if(info_data.wftap)
wtap_close(info_data.wftap);
}

View File

@ -91,7 +91,7 @@ failure_message(const char *msg_format _U_, va_list ap _U_)
int
main(int argc, char *argv[])
{
wtap *wth;
wftap *wth;
int err;
gchar *err_info;
int i;
@ -145,8 +145,8 @@ main(int argc, char *argv[])
wth = wtap_open_offline(argv[i], WTAP_TYPE_AUTO, &err, &err_info, FALSE);
if(wth) {
printf("%s: %s\n", argv[i], wtap_file_type_subtype_short_string(wtap_file_type_subtype(wth)));
wtap_close(wth);
printf("%s: %s\n", argv[i], wtap_file_type_subtype_short_string(wftap_file_type_subtype(wth)));
wftap_close(wth);
} else {
if (err == WTAP_ERR_FILE_UNKNOWN_FORMAT)
printf("%s: unknown\n", argv[i]);

View File

@ -36,7 +36,7 @@ cap_file_get_interface_name(void *data, guint32 interface_id)
wtapng_iface_descriptions_t *idb_info;
const wtapng_if_descr_t *wtapng_if_descr = NULL;
idb_info = wtap_file_get_idb_info(cf->wth);
idb_info = wtap_file_get_idb_info(cf->wfth);
if (interface_id < idb_info->number_of_interfaces)
wtapng_if_descr = &g_array_index(idb_info->interface_data, wtapng_if_descr_t, interface_id);

10
cfile.h
View File

@ -63,6 +63,11 @@ typedef struct {
} modified_frame_data;
#endif
typedef union _phdr_t {
struct wtap_pkthdr wtap_hdr;
/*** Placeholder for ftap_pkthdr */
} phdr_t;
typedef struct _capture_file {
epan_t *epan;
file_state state; /* Current state of capture file */
@ -87,7 +92,7 @@ typedef struct _capture_file {
nstime_t elapsed_time; /* Elapsed time */
gboolean has_snap; /* TRUE if maximum capture packet length is known */
int snap; /* Maximum captured packet length */
wtap *wth; /* Wiretap session */
wftap *wfth; /* Tap session */
dfilter_t *rfcode; /* Compiled read filter program */
dfilter_t *dfcode; /* Compiled display filter program */
gchar *dfilter; /* Display filter string */
@ -104,8 +109,7 @@ typedef struct _capture_file {
search_charset_t scs_type; /* Character set for text search */
search_direction dir; /* Direction in which to do searches */
gboolean search_in_progress; /* TRUE if user just clicked OK in the Find dialog or hit <control>N/B */
/* packet data */
struct wtap_pkthdr phdr; /* Packet header */
phdr_t hdr; /* Packet/File header */
Buffer buf; /* Packet data */
/* frames */
frame_data_sequence *frames; /* Sequence of frames, if we're keeping that information */

View File

@ -310,9 +310,9 @@ selected(int recno)
/* is the packet in the selected timeframe */
static gboolean
check_timestamp(wtap *wth)
check_timestamp(wftap *wfth)
{
struct wtap_pkthdr *pkthdr = wtap_phdr(wth);
struct wtap_pkthdr *pkthdr = wtap_phdr(wfth);
return (pkthdr->ts.secs >= starttime) && (pkthdr->ts.secs < stoptime);
}
@ -838,7 +838,7 @@ failure_message(const char *msg_format _U_, va_list ap _U_)
int
main(int argc, char *argv[])
{
wtap *wth;
wftap *wth;
int i, j, err;
gchar *err_info;
int opt;
@ -847,7 +847,7 @@ main(int argc, char *argv[])
guint32 snaplen = 0; /* No limit */
chop_t chop = {0, 0, 0, 0, 0, 0}; /* No chop */
gboolean adjlen = FALSE;
wtap_dumper *pdh = NULL;
wftap_dumper *pdh = NULL;
unsigned int count = 1;
unsigned int duplicate_count = 0;
gint64 data_offset;
@ -1016,7 +1016,7 @@ main(int argc, char *argv[])
break;
case 'E':
err_prob = strtod(optarg, &p);
err_prob = g_strtod(optarg, &p);
if (p == optarg || err_prob < 0.0 || err_prob > 1.0) {
fprintf(stderr, "editcap: probability \"%s\" must be between 0.0 and 1.0\n",
optarg);
@ -1165,7 +1165,7 @@ main(int argc, char *argv[])
if (verbose) {
fprintf(stderr, "File %s is a %s capture file.\n", argv[optind],
wtap_file_type_subtype_string(wtap_file_type_subtype(wth)));
wtap_file_type_subtype_string(wftap_file_type_subtype(wth)));
}
shb_hdr = wtap_file_get_shb_info(wth);
@ -1178,7 +1178,7 @@ main(int argc, char *argv[])
if ((argc - optind) >= 2) {
if (out_frame_type == -2)
out_frame_type = wtap_file_encap(wth);
out_frame_type = wftap_file_encap(wth);
for (i = optind + 2; i < argc; i++)
if (add_selection(argv[i]) == FALSE)
@ -1196,7 +1196,7 @@ main(int argc, char *argv[])
read_count++;
phdr = wtap_phdr(wth);
buf = wtap_buf_ptr(wth);
buf = wftap_buf_ptr(wth);
if (nstime_is_unset(&block_start)) { /* should only be the first packet */
block_start.secs = phdr->ts.secs;
@ -1217,7 +1217,7 @@ main(int argc, char *argv[])
}
pdh = wtap_dump_open_ng(filename, out_file_type_subtype, out_frame_type,
snaplen ? MIN(snaplen, wtap_snapshot_length(wth)) : wtap_snapshot_length(wth),
snaplen ? MIN(snaplen, wftap_snapshot_length(wth)) : wftap_snapshot_length(wth),
FALSE /* compressed */, shb_hdr, idb_inf, &err);
if (pdh == NULL) {
@ -1234,7 +1234,7 @@ main(int argc, char *argv[])
|| (phdr->ts.secs - block_start.secs == secs_per_block
&& phdr->ts.nsecs >= block_start.nsecs )) { /* time for the next file */
if (!wtap_dump_close(pdh, &err)) {
if (!wftap_dump_close(pdh, &err)) {
fprintf(stderr, "editcap: Error writing to %s: %s\n",
filename, wtap_strerror(err));
exit(2);
@ -1248,7 +1248,7 @@ main(int argc, char *argv[])
fprintf(stderr, "Continuing writing in file %s\n", filename);
pdh = wtap_dump_open_ng(filename, out_file_type_subtype, out_frame_type,
snaplen ? MIN(snaplen, wtap_snapshot_length(wth)) : wtap_snapshot_length(wth),
snaplen ? MIN(snaplen, wftap_snapshot_length(wth)) : wftap_snapshot_length(wth),
FALSE /* compressed */, shb_hdr, idb_inf, &err);
if (pdh == NULL) {
@ -1262,7 +1262,7 @@ main(int argc, char *argv[])
if (split_packet_count > 0) {
/* time for the next file? */
if (written_count > 0 && written_count % split_packet_count == 0) {
if (!wtap_dump_close(pdh, &err)) {
if (!wftap_dump_close(pdh, &err)) {
fprintf(stderr, "editcap: Error writing to %s: %s\n",
filename, wtap_strerror(err));
exit(2);
@ -1276,7 +1276,7 @@ main(int argc, char *argv[])
fprintf(stderr, "Continuing writing in file %s\n", filename);
pdh = wtap_dump_open_ng(filename, out_file_type_subtype, out_frame_type,
snaplen ? MIN(snaplen, wtap_snapshot_length(wth)) : wtap_snapshot_length(wth),
snaplen ? MIN(snaplen, wftap_snapshot_length(wth)) : wftap_snapshot_length(wth),
FALSE /* compressed */, shb_hdr, idb_inf, &err);
if (pdh == NULL) {
fprintf(stderr, "editcap: Can't open or create %s: %s\n",
@ -1470,7 +1470,7 @@ main(int argc, char *argv[])
int real_data_start = 0;
/* Protect non-protocol data */
if (wtap_file_type_subtype(wth) == WTAP_FILE_TYPE_SUBTYPE_CATAPULT_DCT2000)
if (wftap_file_type_subtype(wth) == WTAP_FILE_TYPE_SUBTYPE_CATAPULT_DCT2000)
real_data_start = find_dct2000_real_data(buf);
for (i = real_data_start; i < (int) phdr->caplen; i++) {
@ -1581,7 +1581,7 @@ main(int argc, char *argv[])
filename = g_strdup(argv[optind+1]);
pdh = wtap_dump_open_ng(filename, out_file_type_subtype, out_frame_type,
snaplen ? MIN(snaplen, wtap_snapshot_length(wth)): wtap_snapshot_length(wth),
snaplen ? MIN(snaplen, wftap_snapshot_length(wth)): wftap_snapshot_length(wth),
FALSE /* compressed */, shb_hdr, idb_inf, &err);
if (pdh == NULL) {
fprintf(stderr, "editcap: Can't open or create %s: %s\n",
@ -1593,7 +1593,7 @@ main(int argc, char *argv[])
g_free(idb_inf);
idb_inf = NULL;
if (!wtap_dump_close(pdh, &err)) {
if (!wftap_dump_close(pdh, &err)) {
fprintf(stderr, "editcap: Error writing to %s: %s\n", filename,
wtap_strerror(err));
exit(2);

View File

@ -239,19 +239,19 @@ struct _wslua_tap {
/* a "File" object can be different things under the hood. It can either
be a FILE_T from wtap struct, which it is during read operations, or it
can be a wtap_dumper struct during write operations. A wtap_dumper struct
can be a wftap_dumper struct during write operations. A wtap_dumper struct
has a FILE_T member, but we can't only store its pointer here because
dump operations need the whole thing to write out with. Ugh. */
struct _wslua_file {
FILE_T file;
wtap_dumper *wdh; /* will be NULL during read usage */
wftap_dumper *wdh; /* will be NULL during read usage */
gboolean expired;
};
/* a "CaptureInfo" object can also be different things under the hood. */
struct _wslua_captureinfo {
wtap *wth; /* will be NULL during write usage */
wtap_dumper *wdh; /* will be NULL during read usage */
wftap *wfth; /* will be NULL during write usage */
wftap_dumper *wdh; /* will be NULL during read usage */
gboolean expired;
};
@ -334,7 +334,7 @@ typedef struct _wslua_captureinfo* CaptureInfoConst;
typedef struct _wslua_phdr* FrameInfo;
typedef struct _wslua_const_phdr* FrameInfoConst;
typedef struct _wslua_filehandler* FileHandler;
typedef wtap_dumper* Dumper;
typedef wftap_dumper* Dumper;
typedef struct lua_pseudo_header* PseudoHeader;
typedef tvbparse_t* Parser;
typedef tvbparse_wanted_t* Rule;

View File

@ -266,7 +266,7 @@ WSLUA_METHOD Dumper_close(lua_State* L) {
g_hash_table_remove(dumper_encaps,*dp);
if (!wtap_dump_close(*dp, &err)) {
if (!wftap_dump_close(*dp, &err)) {
luaL_error(L,"error closing: %s",
wtap_strerror(err));
}
@ -285,7 +285,7 @@ WSLUA_METHOD Dumper_flush(lua_State* L) {
if (!d) return 0;
wtap_dump_flush(d);
wftap_dump_flush(d);
return 0;
}
@ -455,7 +455,7 @@ static int Dumper__gc(lua_State* L) {
g_hash_table_remove(dumper_encaps,*dp);
if (!wtap_dump_close(*dp, &err)) {
if (!wftap_dump_close(*dp, &err)) {
luaL_error(L,"error closing: %s",
wtap_strerror(err));
}

View File

@ -29,6 +29,7 @@
#include "wslua.h"
#include <errno.h>
#include <wiretap/wftap-int.h>
#include <wiretap/wtap-int.h>
#include <wiretap/file_wrappers.h>
#include <epan/addr_resolv.h>
@ -97,7 +98,7 @@ WSLUA_CLASS_DEFINE(File,FAIL_ON_NULL_OR_EXPIRED("File"),NOP);
/* a "File" object can be different things under the hood. It can either
be a FILE_T from wtap struct, which it is during read operations, or it
can be a wtap_dumper struct during write operations. A wtap_dumper struct
can be a wftap_dumper struct during write operations. A wtap_dumper struct
has a FILE_T member, but we can't only store its pointer here because
dump operations need the whole thing to write out with. Ugh. */
static File* push_File(lua_State* L, FILE_T ft) {
@ -108,7 +109,7 @@ static File* push_File(lua_State* L, FILE_T ft) {
return pushFile(L,f);
}
static File* push_Wdh(lua_State* L, wtap_dumper *wdh) {
static File* push_Wdh(lua_State* L, wftap_dumper *wdh) {
File f = (File) g_malloc(sizeof(struct _wslua_file));
f->file = (FILE_T)wdh->fh;
f->wdh = wdh;
@ -357,7 +358,7 @@ WSLUA_METHOD File_seek(lua_State* L) {
lua_pushnumber(L, (lua_Number)(file_tell(f->file)));
}
else {
offset = wtap_dump_file_seek(f->wdh, offset, mode[op], &err);
offset = wftap_dump_file_seek(f->wdh, offset, mode[op], &err);
if (offset < 0) {
lua_pushnil(L); /* error */
@ -365,7 +366,7 @@ WSLUA_METHOD File_seek(lua_State* L) {
return 2;
}
offset = wtap_dump_file_tell(f->wdh, &err);
offset = wftap_dump_file_tell(f->wdh, &err);
if (offset < 0) {
lua_pushnil(L); /* error */
@ -434,7 +435,7 @@ WSLUA_METHOD File_write(lua_State* L) {
for (; nargs--; arg++) {
size_t len;
const char *s = luaL_checklstring(L, arg, &len);
status = wtap_dump_file_write(f->wdh, s, len, &err);
status = wftap_dump_file_write(f->wdh, s, len, &err);
if (!status) break;
f->wdh->bytes_dumped += len;
}
@ -515,7 +516,7 @@ int File_register(lua_State* L) {
/************
* The following is for handling private data for the duration of the file
* read_open/read/close cycle, or write_open/write/write_close cycle.
* In other words it handles the "priv" member of wtap and wtap_dumper,
* In other words it handles the "priv" member of wtap and wftap_dumper,
* but for the Lua script's use. A Lua script can set a Lua table
* to CaptureInfo/CaptureInfoConst and have it saved and retrievable this way.
* We need to offer that, because there needs to be a way for Lua scripts
@ -531,20 +532,20 @@ typedef struct _file_priv_t {
} file_priv_t;
/* create and set the wtap->priv private data for the file instance */
static void create_wth_priv(lua_State* L, wtap *wth) {
static void create_wth_priv(lua_State* L, wftap *wfth) {
file_priv_t *priv = (file_priv_t*)g_malloc(sizeof(file_priv_t));
if (wth->priv != NULL) {
if (wfth->priv != NULL) {
luaL_error(L, "Cannot create wtap private data because there already is private data");
return;
}
priv->table_ref = LUA_NOREF;
wth->priv = (void*) priv;
wfth->priv = (void*) priv;
}
/* gets the private data table from wtap */
static int get_wth_priv_table_ref(lua_State* L, wtap *wth) {
file_priv_t *priv = (file_priv_t*) wth->priv;
static int get_wth_priv_table_ref(lua_State* L, wftap *wfth) {
file_priv_t *priv = (file_priv_t*) wfth->priv;
if (!priv) {
/* shouldn't be possible */
@ -559,8 +560,8 @@ static int get_wth_priv_table_ref(lua_State* L, wtap *wth) {
}
/* sets the private data to wtap - the table is presumed on top of stack */
static int set_wth_priv_table_ref(lua_State* L, wtap *wth) {
file_priv_t *priv = (file_priv_t*) wth->priv;
static int set_wth_priv_table_ref(lua_State* L, wftap *wfth) {
file_priv_t *priv = (file_priv_t*) wfth->priv;
if (!priv) {
/* shouldn't be possible */
@ -591,8 +592,8 @@ static int set_wth_priv_table_ref(lua_State* L, wtap *wth) {
}
/* remove, deref, and free the wtap->priv data */
static void remove_wth_priv(lua_State* L, wtap *wth) {
file_priv_t *priv = (file_priv_t*) wth->priv;
static void remove_wth_priv(lua_State* L, wftap *wfth) {
file_priv_t *priv = (file_priv_t*) wfth->priv;
if (!priv) {
/* shouldn't be possible */
@ -602,29 +603,29 @@ static void remove_wth_priv(lua_State* L, wtap *wth) {
luaL_unref(L, LUA_REGISTRYINDEX, priv->table_ref);
g_free(wth->priv);
wth->priv = NULL;
g_free(wfth->priv);
wfth->priv = NULL;
}
/* create and set the wtap_dumper->priv private data for the file instance */
static void create_wdh_priv(lua_State* L, wtap_dumper *wdh) {
/* create and set the wftap_dumper->priv private data for the file instance */
static void create_wdh_priv(lua_State* L, wftap_dumper *wdh) {
file_priv_t *priv = (file_priv_t*)g_malloc(sizeof(file_priv_t));
if (wdh->priv != NULL) {
luaL_error(L, "Cannot create wtap_dumper private data because there already is private data");
luaL_error(L, "Cannot create wftap_dumper private data because there already is private data");
return;
}
priv->table_ref = LUA_NOREF;
wdh->priv = (void*) priv;
}
/* get the private data from wtap_dumper */
static int get_wdh_priv_table_ref(lua_State* L, wtap_dumper *wdh) {
/* get the private data from wftap_dumper */
static int get_wdh_priv_table_ref(lua_State* L, wftap_dumper *wdh) {
file_priv_t *priv = (file_priv_t*) wdh->priv;
if (!priv) {
/* shouldn't be possible */
luaL_error(L, "Cannot get wtap_dumper private data: it is null");
luaL_error(L, "Cannot get wftap_dumper private data: it is null");
return LUA_NOREF;
}
@ -635,7 +636,7 @@ static int get_wdh_priv_table_ref(lua_State* L, wtap_dumper *wdh) {
}
/* sets the private data to wtap - the table is presumed on top of stack */
static int set_wdh_priv_table_ref(lua_State* L, wtap_dumper *wdh) {
static int set_wdh_priv_table_ref(lua_State* L, wftap_dumper *wdh) {
file_priv_t *priv = (file_priv_t*) wdh->priv;
if (!priv) {
@ -666,22 +667,22 @@ static int set_wdh_priv_table_ref(lua_State* L, wtap_dumper *wdh) {
return 0;
}
/* remove and deref the wtap_dumper->priv data */
static void remove_wdh_priv(lua_State* L, wtap_dumper *wdh) {
/* remove and deref the wftap_dumper->priv data */
static void remove_wdh_priv(lua_State* L, wftap_dumper *wdh) {
file_priv_t *priv = (file_priv_t*) wdh->priv;
if (!priv) {
/* shouldn't be possible */
luaL_error(L, "Cannot remove wtap_dumper private data: it is null");
luaL_error(L, "Cannot remove wftap_dumper private data: it is null");
return;
}
luaL_unref(L, LUA_REGISTRYINDEX, priv->table_ref);
/* we do NOT free wtap_dumper's priv member - wtap_dump_close() free's it */
/* we do NOT free wftap_dumper's priv member - wftap_dump_close() free's it */
}
WSLUA_CLASS_DEFINE(CaptureInfo,FAIL_ON_NULL_MEMBER_OR_EXPIRED("CaptureInfo",wth),NOP);
WSLUA_CLASS_DEFINE(CaptureInfo,FAIL_ON_NULL_MEMBER_OR_EXPIRED("CaptureInfo",wfth),NOP);
/*
A `CaptureInfo` object, passed into Lua as an argument by `FileHandler` callback
function `read_open()`, `read()`, `seek_read()`, `seq_read_close()`, and `read_close()`.
@ -696,17 +697,17 @@ WSLUA_CLASS_DEFINE(CaptureInfo,FAIL_ON_NULL_MEMBER_OR_EXPIRED("CaptureInfo",wth)
@since 1.11.3
*/
static CaptureInfo* push_CaptureInfo(lua_State* L, wtap *wth, const gboolean first_time) {
static CaptureInfo* push_CaptureInfo(lua_State* L, wftap *wfth, const gboolean first_time) {
CaptureInfo f = (CaptureInfo) g_malloc0(sizeof(struct _wslua_captureinfo));
f->wth = wth;
f->wfth = wfth;
f->wdh = NULL;
f->expired = FALSE;
if (first_time) {
/* XXX: need to do this? */
wth->file_encap = WTAP_ENCAP_UNKNOWN;
wth->tsprecision = WTAP_FILE_TSPREC_SEC;
wth->snapshot_length = 0;
wfth->file_encap = WTAP_ENCAP_UNKNOWN;
wfth->tsprecision = WTAP_FILE_TSPREC_SEC;
wfth->snapshot_length = 0;
}
return pushCaptureInfo(L,f);
@ -716,12 +717,13 @@ WSLUA_METAMETHOD CaptureInfo__tostring(lua_State* L) {
/* Generates a string of debug info for the CaptureInfo */
CaptureInfo fi = toCaptureInfo(L,1);
if (!fi || !fi->wth) {
if (!fi || !fi->wfth) {
lua_pushstring(L,"CaptureInfo pointer is NULL!");
} else {
wtap *wth = fi->wth;
wftap *wfth = fi->wfth;
wtap* wth = (wtap*)wfth->tap_specific_data;
lua_pushfstring(L, "CaptureInfo: file_type_subtype=%d, snapshot_length=%d, pkt_encap=%d, tsprecision='%s'",
wth->file_type_subtype, wth->snapshot_length, wth->phdr.pkt_encap, wth->tsprecision);
wfth->file_type_subtype, wfth->snapshot_length, wth->phdr.pkt_encap, wfth->tsprecision);
}
WSLUA_RETURN(1); /* String of debug information. */
@ -740,23 +742,24 @@ static int CaptureInfo__gc(lua_State* L _U_) {
See `wtap_encaps` in `init.lua` for available types. Set to `wtap_encaps.PER_PACKET` if packets can
have different types, then later set `FrameInfo.encap` for each packet during `read()`/`seek_read()`.
*/
WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(CaptureInfo,encap,wth->file_encap);
WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(CaptureInfo,encap,wth->file_encap,int);
WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(CaptureInfo,encap,wfth->file_encap);
WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(CaptureInfo,encap,wfth->file_encap,int);
/* WSLUA_ATTRIBUTE CaptureInfo_time_precision RW The precision of the packet timestamps in the file.
See `wtap_file_tsprec` in `init.lua` for available precisions.
*/
WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(CaptureInfo,time_precision,wth->tsprecision);
WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(CaptureInfo,time_precision,wth->tsprecision,int);
WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(CaptureInfo,time_precision,wfth->tsprecision);
WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(CaptureInfo,time_precision,wfth->tsprecision,int);
/* WSLUA_ATTRIBUTE CaptureInfo_snapshot_length RW The maximum packet length that could be recorded.
Setting it to `0` means unknown. Wireshark cannot handle anything bigger than 65535 bytes.
*/
WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(CaptureInfo,snapshot_length,wth->snapshot_length);
WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(CaptureInfo,snapshot_length,wth->snapshot_length,guint);
WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(CaptureInfo,snapshot_length,wfth->snapshot_length);
WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(CaptureInfo,snapshot_length,wfth->snapshot_length,guint);
#if FILESHARK /* XXX - FIX ME PLEASE!!!!!! */
/* WSLUA_ATTRIBUTE CaptureInfo_comment RW A string comment for the whole capture file,
or nil if there is no `comment`. */
WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(CaptureInfo,comment,wth->shb_hdr.opt_comment);
@ -776,6 +779,7 @@ WSLUA_ATTRIBUTE_NAMED_STRING_SETTER(CaptureInfo,os,wth->shb_hdr.shb_os,TRUE);
the application used to create the capture, or nil if there is no `user_app` string. */
WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(CaptureInfo,user_app,wth->shb_hdr.shb_user_appl);
WSLUA_ATTRIBUTE_NAMED_STRING_SETTER(CaptureInfo,user_app,wth->shb_hdr.shb_user_appl,TRUE);
#endif
/* WSLUA_ATTRIBUTE CaptureInfo_hosts WO Sets resolved ip-to-hostname information.
@ -791,7 +795,8 @@ WSLUA_ATTRIBUTE_NAMED_STRING_SETTER(CaptureInfo,user_app,wth->shb_hdr.shb_user_a
*/
static int CaptureInfo_set_hosts(lua_State* L) {
CaptureInfo fi = checkCaptureInfo(L,1);
wtap *wth = fi->wth;
wftap *wfth = fi->wfth;
wtap *wth = (wtap*)wfth->tap_specific_data;
const char *addr = NULL;
const char *name = NULL;
size_t addr_len = 0;
@ -914,22 +919,24 @@ static int CaptureInfo_set_hosts(lua_State* L) {
*/
static int CaptureInfo_get_private_table(lua_State* L) {
CaptureInfo fi = checkCaptureInfo(L,1);
return get_wth_priv_table_ref(L, fi->wth);
return get_wth_priv_table_ref(L, fi->wfth);
}
static int CaptureInfo_set_private_table(lua_State* L) {
CaptureInfo fi = checkCaptureInfo(L,1);
return set_wth_priv_table_ref(L, fi->wth);
return set_wth_priv_table_ref(L, fi->wfth);
}
WSLUA_ATTRIBUTES CaptureInfo_attributes[] = {
WSLUA_ATTRIBUTE_RWREG(CaptureInfo,encap),
WSLUA_ATTRIBUTE_RWREG(CaptureInfo,time_precision),
WSLUA_ATTRIBUTE_RWREG(CaptureInfo,snapshot_length),
#if FILESHARK /* XXX - FIX ME PLEASE!!!!!! */
WSLUA_ATTRIBUTE_RWREG(CaptureInfo,comment),
WSLUA_ATTRIBUTE_RWREG(CaptureInfo,hardware),
WSLUA_ATTRIBUTE_RWREG(CaptureInfo,os),
WSLUA_ATTRIBUTE_RWREG(CaptureInfo,user_app),
#endif
WSLUA_ATTRIBUTE_WOREG(CaptureInfo,hosts),
WSLUA_ATTRIBUTE_RWREG(CaptureInfo,private_table),
{ NULL, NULL, NULL }
@ -963,9 +970,9 @@ WSLUA_CLASS_DEFINE(CaptureInfoConst,FAIL_ON_NULL_MEMBER_OR_EXPIRED("CaptureInfoC
@since 1.11.3
*/
static CaptureInfoConst* push_CaptureInfoConst(lua_State* L, wtap_dumper *wdh) {
static CaptureInfoConst* push_CaptureInfoConst(lua_State* L, wftap_dumper *wdh) {
CaptureInfoConst f = (CaptureInfoConst) g_malloc0(sizeof(struct _wslua_captureinfo));
f->wth = NULL;
f->wfth = NULL;
f->wdh = wdh;
f->expired = FALSE;
return pushCaptureInfoConst(L,f);
@ -978,7 +985,7 @@ WSLUA_METAMETHOD CaptureInfoConst__tostring(lua_State* L) {
if (!fi || !fi->wdh) {
lua_pushstring(L,"CaptureInfoConst pointer is NULL!");
} else {
wtap_dumper *wdh = fi->wdh;
wftap_dumper *wdh = fi->wdh;
lua_pushfstring(L, "CaptureInfoConst: file_type_subtype=%d, snaplen=%d, encap=%d, compressed=%d, tsprecision='%s'",
wdh->file_type_subtype, wdh->snaplen, wdh->encap, wdh->compressed, wdh->tsprecision);
}
@ -1000,6 +1007,7 @@ WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(CaptureInfoConst,snapshot_length,wdh->snaple
have different types, in which case each Frame identifies its type, in `FrameInfo.packet_encap`. */
WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(CaptureInfoConst,encap,wdh->encap);
#if FILESHARK /* XXX - FIX ME PLEASE!!!!!! */
/* WSLUA_ATTRIBUTE CaptureInfoConst_comment RW A comment for the whole capture file, if the
`wtap_presence_flags.COMMENTS` was set in the presence flags; nil if there is no comment. */
WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(CaptureInfoConst,comment,wth->shb_hdr.opt_comment);
@ -1015,6 +1023,7 @@ WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(CaptureInfoConst,os,wth->shb_hdr.shb_os);
/* WSLUA_ATTRIBUTE CaptureInfoConst_user_app RO A string containing the name of
the application used to create the capture, or nil if there is no user_app string. */
WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(CaptureInfoConst,user_app,wth->shb_hdr.shb_user_appl);
#endif
/* WSLUA_ATTRIBUTE CaptureInfoConst_hosts RO A ip-to-hostname Lua table of two key-ed names: `ipv4_addresses` and `ipv6_addresses`.
The value of each of these names are themselves array tables, of key-ed tables, such that the inner table has a key
@ -1028,7 +1037,8 @@ WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(CaptureInfoConst,user_app,wth->shb_hdr.shb_u
be nil. */
static int CaptureInfoConst_get_hosts(lua_State* L) {
CaptureInfoConst fi = checkCaptureInfoConst(L,1);
wtap_dumper *wdh = fi->wdh;
wftap_dumper *wfdh = fi->wdh;
wtap_dumper *wdh = (wtap_dumper*)wfdh->tap_specific_data;
/* create the main table to return */
lua_newtable(L);
@ -1126,10 +1136,12 @@ WSLUA_ATTRIBUTES CaptureInfoConst_attributes[] = {
WSLUA_ATTRIBUTE_ROREG(CaptureInfoConst,encap),
WSLUA_ATTRIBUTE_ROREG(CaptureInfoConst,type),
WSLUA_ATTRIBUTE_ROREG(CaptureInfoConst,snapshot_length),
#if FILESHARK /* XXX - FIX ME PLEASE!!!!!! */
WSLUA_ATTRIBUTE_ROREG(CaptureInfoConst,comment),
WSLUA_ATTRIBUTE_ROREG(CaptureInfoConst,hardware),
WSLUA_ATTRIBUTE_ROREG(CaptureInfoConst,os),
WSLUA_ATTRIBUTE_ROREG(CaptureInfoConst,user_app),
#endif
WSLUA_ATTRIBUTE_ROREG(CaptureInfoConst,hosts),
WSLUA_ATTRIBUTE_RWREG(CaptureInfoConst,private_table),
{ NULL, NULL, NULL }
@ -1418,7 +1430,7 @@ WSLUA_METHOD FrameInfoConst_write_data(lua_State* L) {
if (len > fi->phdr->caplen)
len = fi->phdr->caplen;
if (!wtap_dump_file_write(fh->wdh, fi->pd, (size_t)(len), &err)) {
if (!wftap_dump_file_write(fh->wdh, fi->pd, (size_t)(len), &err)) {
lua_pushboolean(L, FALSE);
lua_pushfstring(L, "FrameInfoConst write_data() error: %s", g_strerror(err));
lua_pushnumber(L, err);
@ -1618,16 +1630,16 @@ static gboolean in_routine = FALSE;
/* some declarations */
static gboolean
wslua_filehandler_read(wtap *wth, int *err, gchar **err_info,
wslua_filehandler_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean
wslua_filehandler_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf,
wslua_filehandler_seek_read(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf,
int *err, gchar **err_info);
static void
wslua_filehandler_close(wtap *wth);
wslua_filehandler_close(wftap *wfth);
static void
wslua_filehandler_sequential_close(wtap *wth);
wslua_filehandler_sequential_close(wftap *wfth);
/* This is our one-and-only open routine for file handling. When called by
@ -1642,9 +1654,9 @@ wslua_filehandler_sequential_close(wtap *wth);
* field in the "struct wtap" to the type of the file.
*/
static int
wslua_filehandler_open(wtap *wth, int *err _U_, gchar **err_info)
wslua_filehandler_open(wftap *wfth, int *err _U_, gchar **err_info)
{
FileHandler fh = (FileHandler)(wth->wslua_data);
FileHandler fh = (FileHandler)(wfth->wslua_data);
int retval = 0;
lua_State* L = NULL;
File *fp = NULL;
@ -1652,10 +1664,10 @@ wslua_filehandler_open(wtap *wth, int *err _U_, gchar **err_info)
INIT_FILEHANDLER_ROUTINE(read_open,0);
create_wth_priv(L, wth);
create_wth_priv(L, wfth);
fp = push_File(L, wth->fh);
fc = push_CaptureInfo(L, wth, TRUE);
fp = push_File(L, wfth->fh);
fc = push_CaptureInfo(L, wfth, TRUE);
errno = WTAP_ERR_CANT_READ;
switch ( lua_pcall(L,2,1,1) ) {
@ -1674,32 +1686,32 @@ wslua_filehandler_open(wtap *wth, int *err _U_, gchar **err_info)
/* this is our file type - set the routines and settings into wtap */
if (fh->read_ref != LUA_NOREF) {
wth->subtype_read = wslua_filehandler_read;
wfth->subtype_read = wslua_filehandler_read;
}
else return 0;
if (fh->seek_read_ref != LUA_NOREF) {
wth->subtype_seek_read = wslua_filehandler_seek_read;
wfth->subtype_seek_read = wslua_filehandler_seek_read;
}
else return 0;
/* it's ok to not have a close routine */
if (fh->read_close_ref != LUA_NOREF)
wth->subtype_close = wslua_filehandler_close;
wfth->subtype_close = wslua_filehandler_close;
else
wth->subtype_close = NULL;
wfth->subtype_close = NULL;
/* it's ok to not have a sequential close routine */
if (fh->seq_read_close_ref != LUA_NOREF)
wth->subtype_sequential_close = wslua_filehandler_sequential_close;
wfth->subtype_sequential_close = wslua_filehandler_sequential_close;
else
wth->subtype_sequential_close = NULL;
wfth->subtype_sequential_close = NULL;
wth->file_type_subtype = fh->file_type;
wfth->file_type_subtype = fh->file_type;
}
else {
/* not our file type */
remove_wth_priv(L, wth);
remove_wth_priv(L, wfth);
}
lua_settop(L,0);
@ -1713,15 +1725,16 @@ wslua_filehandler_open(wtap *wth, int *err _U_, gchar **err_info)
* This will be the seek_off parameter when this frame is re-read.
*/
static gboolean
wslua_filehandler_read(wtap *wth, int *err, gchar **err_info,
wslua_filehandler_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset)
{
FileHandler fh = (FileHandler)(wth->wslua_data);
FileHandler fh = (FileHandler)(wfth->wslua_data);
int retval = -1;
lua_State* L = NULL;
File *fp = NULL;
CaptureInfo *fc = NULL;
FrameInfo *fi = NULL;
wtap *wth = (wtap*)wfth->tap_specific_data;
INIT_FILEHANDLER_ROUTINE(read,FALSE);
@ -1730,9 +1743,9 @@ wslua_filehandler_read(wtap *wth, int *err, gchar **err_info,
wth->phdr.opt_comment = NULL;
fp = push_File(L, wth->fh);
fc = push_CaptureInfo(L, wth, FALSE);
fi = push_FrameInfo(L, &wth->phdr, wth->frame_buffer);
fp = push_File(L, wfth->fh);
fc = push_CaptureInfo(L, wfth, FALSE);
fi = push_FrameInfo(L, &wth->phdr, wfth->frame_buffer);
errno = WTAP_ERR_CANT_READ;
switch ( lua_pcall(L,3,1,1) ) {
@ -1761,16 +1774,17 @@ wslua_filehandler_read(wtap *wth, int *err, gchar **err_info,
* success, FALSE on error.
*/
static gboolean
wslua_filehandler_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf,
wslua_filehandler_seek_read(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf,
int *err, gchar **err_info)
{
FileHandler fh = (FileHandler)(wth->wslua_data);
FileHandler fh = (FileHandler)(wfth->wslua_data);
int retval = -1;
lua_State* L = NULL;
File *fp = NULL;
CaptureInfo *fc = NULL;
FrameInfo *fi = NULL;
struct wtap_pkthdr *phdr = (struct wtap_pkthdr*)header;
INIT_FILEHANDLER_ROUTINE(seek_read,FALSE);
@ -1778,8 +1792,8 @@ wslua_filehandler_seek_read(wtap *wth, gint64 seek_off,
*err = errno = 0;
phdr->opt_comment = NULL;
fp = push_File(L, wth->random_fh);
fc = push_CaptureInfo(L, wth, FALSE);
fp = push_File(L, wfth->random_fh);
fc = push_CaptureInfo(L, wfth, FALSE);
fi = push_FrameInfo(L, phdr, buf);
lua_pushnumber(L, (lua_Number)seek_off);
@ -1812,17 +1826,17 @@ wslua_filehandler_seek_read(wtap *wth, gint64 seek_off,
/* Classic wtap close function, called by wtap core.
*/
static void
wslua_filehandler_close(wtap *wth)
wslua_filehandler_close(wftap *wfth)
{
FileHandler fh = (FileHandler)(wth->wslua_data);
FileHandler fh = (FileHandler)(wfth->wslua_data);
lua_State* L = NULL;
File *fp = NULL;
CaptureInfo *fc = NULL;
INIT_FILEHANDLER_ROUTINE(read_close,);
fp = push_File(L, wth->fh);
fc = push_CaptureInfo(L, wth, FALSE);
fp = push_File(L, wfth->fh);
fc = push_CaptureInfo(L, wfth, FALSE);
switch ( lua_pcall(L,2,1,1) ) {
case 0:
@ -1832,7 +1846,7 @@ wslua_filehandler_close(wtap *wth)
END_FILEHANDLER_ROUTINE();
remove_wth_priv(L, wth);
remove_wth_priv(L, wfth);
(*fp)->expired = TRUE;
(*fc)->expired = TRUE;
@ -1844,17 +1858,17 @@ wslua_filehandler_close(wtap *wth)
/* Classic wtap sequential close function, called by wtap core.
*/
static void
wslua_filehandler_sequential_close(wtap *wth)
wslua_filehandler_sequential_close(wftap *wfth)
{
FileHandler fh = (FileHandler)(wth->wslua_data);
FileHandler fh = (FileHandler)(wfth->wslua_data);
lua_State* L = NULL;
File *fp = NULL;
CaptureInfo *fc = NULL;
INIT_FILEHANDLER_ROUTINE(seq_read_close,);
fp = push_File(L, wth->fh);
fc = push_CaptureInfo(L, wth, FALSE);
fp = push_File(L, wfth->fh);
fc = push_CaptureInfo(L, wfth, FALSE);
switch ( lua_pcall(L,2,1,1) ) {
case 0:
@ -1918,17 +1932,17 @@ wslua_filehandler_can_write_encap(int encap, void* data)
/* some declarations */
static gboolean
wslua_filehandler_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
wslua_filehandler_dump(wftap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err);
static gboolean
wslua_filehandler_dump_close(wtap_dumper *wdh, int *err);
wslua_filehandler_dump_close(wftap_dumper *wdh, int *err);
/* The classic wtap dump_open function.
* This returns 1 (TRUE) on success.
*/
static int
wslua_filehandler_dump_open(wtap_dumper *wdh, int *err)
wslua_filehandler_dump_open(wftap_dumper *wdh, int *err)
{
FileHandler fh = (FileHandler)(wdh->wslua_data);
int retval = 0;
@ -1987,7 +2001,7 @@ wslua_filehandler_dump_open(wtap_dumper *wdh, int *err)
* else FALSE.
*/
static gboolean
wslua_filehandler_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
wslua_filehandler_dump(wftap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err)
{
FileHandler fh = (FileHandler)(wdh->wslua_data);
@ -2027,7 +2041,7 @@ wslua_filehandler_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
* else FALSE.
*/
static gboolean
wslua_filehandler_dump_close(wtap_dumper *wdh, int *err)
wslua_filehandler_dump_close(wftap_dumper *wdh, int *err)
{
FileHandler fh = (FileHandler)(wdh->wslua_data);
int retval = -1;

158
file.c
View File

@ -237,7 +237,7 @@ cf_timestamp_auto_precision(capture_file *cf)
prec == TS_PREC_AUTO_USEC ||
prec == TS_PREC_AUTO_NSEC)
{
switch(wtap_file_tsprecision(cf->wth)) {
switch(wftap_file_tsprecision(cf->wfth)) {
case(WTAP_FILE_TSPREC_SEC):
timestamp_set_precision(TS_PREC_AUTO_SEC);
break;
@ -336,7 +336,7 @@ ws_epan_new(capture_file *cf)
cf_status_t
cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_tempfile, int *err)
{
wtap *wth;
wftap *wth;
gchar *err_info;
wth = wtap_open_offline(fname, type, err, &err_info, TRUE);
@ -359,7 +359,7 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp
/* We're about to start reading the file. */
cf->state = FILE_READ_IN_PROGRESS;
cf->wth = wth;
cf->wfth = wth;
cf->f_datalen = 0;
/* Set the file name because we need it to set the follow stream filter.
@ -375,7 +375,7 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp
cf->computed_elapsed = 0;
cf->cd_t = wtap_file_type_subtype(cf->wth);
cf->cd_t = wftap_file_type_subtype(cf->wfth);
cf->open_type = type;
cf->linktypes = g_array_sized_new(FALSE, FALSE, (guint) sizeof(int), 1);
cf->count = 0;
@ -386,7 +386,7 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp
cf->ref_time_count = 0;
cf->drops_known = FALSE;
cf->drops = 0;
cf->snap = wtap_snapshot_length(cf->wth);
cf->snap = wftap_snapshot_length(cf->wfth);
if (cf->snap == 0) {
/* Snapshot length not known. */
cf->has_snap = FALSE;
@ -414,8 +414,8 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp
ber_set_filename(cf->filename);
}
wtap_set_cb_new_ipv4(cf->wth, add_ipv4_name);
wtap_set_cb_new_ipv6(cf->wth, (wtap_new_ipv6_callback_t) add_ipv6_name);
wtap_set_cb_new_ipv4(cf->wfth, add_ipv4_name);
wtap_set_cb_new_ipv6(cf->wfth, (wtap_new_ipv6_callback_t) add_ipv6_name);
return CF_OK;
@ -456,9 +456,9 @@ cf_reset_state(capture_file *cf)
/* Die if we're in the middle of reading a file. */
g_assert(cf->state != FILE_READ_IN_PROGRESS);
if (cf->wth) {
wtap_close(cf->wth);
cf->wth = NULL;
if (cf->wfth) {
wtap_close(cf->wfth);
cf->wfth = NULL;
}
/* We have no file open... */
if (cf->filename != NULL) {
@ -549,12 +549,12 @@ calc_progbar_val(capture_file *cf, gint64 size, gint64 file_pos, gchar *status_s
/* The file probably grew while we were reading it.
* Update file size, and try again.
*/
size = wtap_file_size(cf->wth, NULL);
size = wftap_file_size(cf->wfth, NULL);
if (size >= 0)
progbar_val = (gfloat) file_pos / (gfloat) size;
/* If it's still > 1, either "wtap_file_size()" failed (in which
/* If it's still > 1, either "wftap_file_size()" failed (in which
* case there's not much we can do about it), or the file
* *shrank* (in which case there's not much we can do about
* it); just clip the progress value at 1.0.
@ -608,7 +608,7 @@ cf_read(capture_file *cf, gboolean reloading)
/* Record whether the file is compressed.
XXX - do we know this at open time? */
cf->iscompressed = wtap_iscompressed(cf->wth);
cf->iscompressed = wftap_iscompressed(cf->wfth);
/* The packet list window will be empty until the file is completly loaded */
packet_list_freeze();
@ -638,7 +638,7 @@ cf_read(capture_file *cf, gboolean reloading)
cinfo = (tap_flags & TL_REQUIRES_COLUMNS) ? &cf->cinfo : NULL;
/* Find the size of the file. */
size = wtap_file_size(cf->wth, NULL);
size = wftap_file_size(cf->wfth, NULL);
/* Update the progress bar when it gets to this value. */
progbar_nextstep = 0;
@ -651,10 +651,10 @@ cf_read(capture_file *cf, gboolean reloading)
}else
progbar_quantum = 0;
while ((wtap_read(cf->wth, &err, &err_info, &data_offset))) {
while ((wtap_read(cf->wfth, &err, &err_info, &data_offset))) {
if (size >= 0) {
count++;
file_pos = wtap_read_so_far(cf->wth);
file_pos = wftap_read_so_far(cf->wfth);
/* Create the progress bar if necessary.
* Check whether it should be created or not every MIN_NUMBER_OF_PACKET
@ -736,7 +736,7 @@ cf_read(capture_file *cf, gboolean reloading)
cf->state = FILE_READ_DONE;
/* Close the sequential I/O side, to free up memory it requires. */
wtap_sequential_close(cf->wth);
wftap_sequential_close(cf->wfth);
/* Allow the protocol dissectors to free up memory that they
* don't need after the sequential run-through of the packets. */
@ -749,7 +749,7 @@ cf_read(capture_file *cf, gboolean reloading)
we've looked at all the packets, as we don't know until then whether
there's more than one type (and thus whether it's
WTAP_ENCAP_PER_PACKET). */
cf->lnk_t = wtap_file_encap(cf->wth);
cf->lnk_t = wftap_file_encap(cf->wfth);
cf->current_frame = frame_data_sequence_find(cf->frames, cf->first_displayed);
cf->current_row = 0;
@ -874,8 +874,8 @@ cf_continue_tail(capture_file *cf, volatile int to_read, int *err)
cinfo = (tap_flags & TL_REQUIRES_COLUMNS) ? &cf->cinfo : NULL;
while (to_read != 0) {
wtap_cleareof(cf->wth);
if (!wtap_read(cf->wth, err, &err_info, &data_offset)) {
wftap_cleareof(cf->wfth);
if (!wtap_read(cf->wfth, err, &err_info, &data_offset)) {
break;
}
if (cf->state == FILE_READ_ABORTED) {
@ -907,7 +907,7 @@ cf_continue_tail(capture_file *cf, volatile int to_read, int *err)
/* Update the file encapsulation; it might have changed based on the
packets we've read. */
cf->lnk_t = wtap_file_encap(cf->wth);
cf->lnk_t = wftap_file_encap(cf->wfth);
/* Cleanup and release all dfilter resources */
if (dfcode != NULL) {
@ -981,7 +981,7 @@ cf_finish_tail(capture_file *cf, int *err)
create_proto_tree =
(dfcode != NULL || have_filtering_tap_listeners() || (tap_flags & TL_REQUIRES_PROTO_TREE));
if (cf->wth == NULL) {
if (cf->wfth == NULL) {
cf_close(cf);
return CF_READ_ERROR;
}
@ -992,7 +992,7 @@ cf_finish_tail(capture_file *cf, int *err)
epan_dissect_init(&edt, cf->epan, create_proto_tree, FALSE);
while ((wtap_read(cf->wth, err, &err_info, &data_offset))) {
while ((wtap_read(cf->wfth, err, &err_info, &data_offset))) {
if (cf->state == FILE_READ_ABORTED) {
/* Well, the user decided to abort the read. Break out of the
loop, and let the code below (which is called even if there
@ -1030,7 +1030,7 @@ cf_finish_tail(capture_file *cf, int *err)
/* We're done reading sequentially through the file; close the
sequential I/O side, to free up memory it requires. */
wtap_sequential_close(cf->wth);
wftap_sequential_close(cf->wfth);
/* Allow the protocol dissectors to free up memory that they
* don't need after the sequential run-through of the packets. */
@ -1038,7 +1038,7 @@ cf_finish_tail(capture_file *cf, int *err)
/* Update the file encapsulation; it might have changed based on the
packets we've read. */
cf->lnk_t = wtap_file_encap(cf->wth);
cf->lnk_t = wftap_file_encap(cf->wfth);
/* Update the details in the file-set dialog, as the capture file
* has likely grown since we first stat-ed it */
@ -1235,8 +1235,8 @@ static int
read_packet(capture_file *cf, dfilter_t *dfcode, epan_dissect_t *edt,
column_info *cinfo, gint64 offset)
{
struct wtap_pkthdr *phdr = wtap_phdr(cf->wth);
const guint8 *buf = wtap_buf_ptr(cf->wth);
struct wtap_pkthdr *phdr = wtap_phdr(cf->wfth);
const guint8 *buf = wftap_buf_ptr(cf->wfth);
frame_data fdlocal;
guint32 framenum;
frame_data *fdata;
@ -1294,7 +1294,7 @@ cf_merge_files(char **out_filenamep, int in_file_count,
char *out_filename;
char *tmpname;
int out_fd;
wtap_dumper *pdh;
wftap_dumper *pdh;
int open_err, read_err, write_err, close_err;
gchar *err_info;
int err_fileno;
@ -1361,7 +1361,7 @@ cf_merge_files(char **out_filenamep, int in_file_count,
fake_interface_ids = TRUE;
/* Create SHB info */
shb_hdr = wtap_file_get_shb_info(in_files[0].wth);
shb_hdr = wtap_file_get_shb_info(in_files[0].wfth);
comment_gstr = g_string_new("");
g_string_append_printf(comment_gstr, "%s \n",shb_hdr->opt_comment);
g_string_append_printf(comment_gstr, "File created by merging: \n");
@ -1388,7 +1388,7 @@ cf_merge_files(char **out_filenamep, int in_file_count,
idb_inf->interface_data = g_array_new(FALSE, FALSE, sizeof(wtapng_if_descr_t));
for (i = 0; i < in_file_count; i++) {
idb_inf_merge_file = wtap_file_get_idb_info(in_files[i].wth);
idb_inf_merge_file = wtap_file_get_idb_info(in_files[i].wfth);
/* read the interface data from the in file to our combined interfca data */
file_int_data = &g_array_index (idb_inf_merge_file->interface_data, wtapng_if_descr_t, 0);
int_data.wtap_encap = file_int_data->wtap_encap;
@ -1504,7 +1504,7 @@ cf_merge_files(char **out_filenamep, int in_file_count,
/* Get the sum of the seek positions in all of the files. */
file_pos = 0;
for (i = 0; i < in_file_count; i++)
file_pos += wtap_read_so_far(in_files[i].wth);
file_pos += wftap_read_so_far(in_files[i].wfth);
progbar_val = (gfloat) file_pos / (gfloat) f_len;
if (progbar_val > 1.0f) {
/* Some file probably grew while we were reading it.
@ -1534,12 +1534,12 @@ cf_merge_files(char **out_filenamep, int in_file_count,
if (fake_interface_ids) {
struct wtap_pkthdr *phdr;
phdr = wtap_phdr(in_file->wth);
phdr = wtap_phdr(in_file->wfth);
phdr->interface_id = in_file->interface_id;
phdr->presence_flags = phdr->presence_flags | WTAP_HAS_INTERFACE_ID;
}
if (!wtap_dump(pdh, wtap_phdr(in_file->wth),
wtap_buf_ptr(in_file->wth), &write_err)) {
if (!wtap_dump(pdh, wtap_phdr(in_file->wfth),
wftap_buf_ptr(in_file->wfth), &write_err)) {
got_write_error = TRUE;
break;
}
@ -1551,7 +1551,7 @@ cf_merge_files(char **out_filenamep, int in_file_count,
merge_close_in_files(in_file_count, in_files);
if (!got_write_error) {
if (!wtap_dump_close(pdh, &write_err))
if (!wftap_dump_close(pdh, &write_err))
got_write_error = TRUE;
} else {
/*
@ -1560,7 +1560,7 @@ cf_merge_files(char **out_filenamep, int in_file_count,
*
* Don't overwrite the earlier write error.
*/
(void)wtap_dump_close(pdh, &close_err);
(void)wftap_dump_close(pdh, &close_err);
}
if (got_read_error) {
@ -1778,7 +1778,7 @@ cf_read_frame_r(capture_file *cf, const frame_data *fdata,
}
#endif
if (!wtap_seek_read(cf->wth, fdata->file_off, phdr, buf, &err, &err_info)) {
if (!wftap_seek_read(cf->wfth, fdata->file_off, phdr, buf, &err, &err_info)) {
display_basename = g_filename_display_basename(cf->filename);
switch (err) {
@ -1809,7 +1809,7 @@ cf_read_frame_r(capture_file *cf, const frame_data *fdata,
gboolean
cf_read_frame(capture_file *cf, frame_data *fdata)
{
return cf_read_frame_r(cf, fdata, &cf->phdr, &cf->buf);
return cf_read_frame_r(cf, fdata, &cf->hdr.wtap_hdr, &cf->buf);
}
/* Rescan the list of packets, reconstructing the CList.
@ -2017,7 +2017,7 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item, gb
}
add_packet_to_packet_list(fdata, cf, &edt, dfcode,
cinfo, &cf->phdr,
cinfo, &cf->hdr.wtap_hdr,
buffer_start_ptr(&cf->buf),
add_to_packet_list);
@ -3117,7 +3117,7 @@ match_protocol_tree(capture_file *cf, frame_data *fdata, void *criterion)
/* Construct the protocol tree, including the displayed text */
epan_dissect_init(&edt, cf->epan, TRUE, TRUE);
/* We don't need the column information */
epan_dissect_run(&edt, &cf->phdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata, NULL);
epan_dissect_run(&edt, &cf->hdr.wtap_hdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata, NULL);
/* Iterate through all the nodes, seeing if they have text that matches. */
mdata->cf = cf;
@ -3221,7 +3221,7 @@ match_summary_line(capture_file *cf, frame_data *fdata, void *criterion)
/* Don't bother constructing the protocol tree */
epan_dissect_init(&edt, cf->epan, FALSE, FALSE);
/* Get the column information */
epan_dissect_run(&edt, &cf->phdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata,
epan_dissect_run(&edt, &cf->hdr.wtap_hdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata,
&cf->cinfo);
/* Find the Info column */
@ -3529,7 +3529,7 @@ match_dfilter(capture_file *cf, frame_data *fdata, void *criterion)
epan_dissect_init(&edt, cf->epan, TRUE, FALSE);
epan_dissect_prime_dfilter(&edt, sfcode);
epan_dissect_run(&edt, &cf->phdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata, NULL);
epan_dissect_run(&edt, &cf->hdr.wtap_hdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata, NULL);
result = dfilter_apply_edt(sfcode, &edt) ? MR_MATCHED : MR_NOTMATCHED;
epan_dissect_cleanup(&edt);
return result;
@ -3862,7 +3862,7 @@ cf_select_packet(capture_file *cf, int row)
cf->edt = epan_dissect_new(cf->epan, TRUE, TRUE);
tap_build_interesting(cf->edt);
epan_dissect_run(cf->edt, &cf->phdr, frame_tvbuff_new_buffer(cf->current_frame, &cf->buf),
epan_dissect_run(cf->edt, &cf->hdr.wtap_hdr, frame_tvbuff_new_buffer(cf->current_frame, &cf->buf),
cf->current_frame, NULL);
dfilter_macro_build_ftv_cache(cf->edt->tree);
@ -3968,7 +3968,7 @@ cf_read_shb_comment(capture_file *cf)
const gchar *temp_str;
/* Get info from SHB */
shb_inf = wtap_file_get_shb_info(cf->wth);
shb_inf = wtap_file_get_shb_info(cf->wfth);
if (shb_inf == NULL)
return NULL;
temp_str = shb_inf->opt_comment;
@ -3984,7 +3984,7 @@ cf_update_capture_comment(capture_file *cf, gchar *comment)
wtapng_section_t *shb_inf;
/* Get info from SHB */
shb_inf = wtap_file_get_shb_info(cf->wth);
shb_inf = wtap_file_get_shb_info(cf->wfth);
/* See if the comment has changed or not */
if (shb_inf && shb_inf->opt_comment) {
@ -3998,7 +3998,7 @@ cf_update_capture_comment(capture_file *cf, gchar *comment)
g_free(shb_inf);
/* The comment has changed, let's update it */
wtap_write_shb_comment(cf->wth, comment);
wtap_write_shb_comment(cf->wfth, comment);
/* Mark the file as having unsaved changes */
cf->unsaved_changes = TRUE;
}
@ -4097,9 +4097,9 @@ cf_comment_types(capture_file *cf)
}
typedef struct {
wtap_dumper *pdh;
const char *fname;
int file_type;
wftap_dumper *pdh;
const char *fname;
int file_type;
} save_callback_args_t;
/*
@ -4341,7 +4341,7 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err)
#endif
/* Close the old handle. */
wtap_close(cf->wth);
wtap_close(cf->wfth);
/* Open the new file. */
/* XXX: this will go through all open_routines for a matching one. But right
@ -4349,8 +4349,8 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err)
format than the original, and the user is not given a choice of which
reader to use (only which format to save it in), so doing this makes
sense for now. */
cf->wth = wtap_open_offline(fname, WTAP_TYPE_AUTO, err, &err_info, TRUE);
if (cf->wth == NULL) {
cf->wfth = wtap_open_offline(fname, WTAP_TYPE_AUTO, err, &err_info, TRUE);
if (cf->wfth == NULL) {
cf_open_failure_alert_box(fname, *err, err_info, FALSE, 0);
return CF_READ_ERROR;
}
@ -4370,10 +4370,10 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err)
/* No user changes yet. */
cf->unsaved_changes = FALSE;
cf->cd_t = wtap_file_type_subtype(cf->wth);
cf->cd_t = wftap_file_type_subtype(cf->wfth);
cf->linktypes = g_array_sized_new(FALSE, FALSE, (guint) sizeof(int), 1);
cf->snap = wtap_snapshot_length(cf->wth);
cf->snap = wftap_snapshot_length(cf->wfth);
if (cf->snap == 0) {
/* Snapshot length not known. */
cf->has_snap = FALSE;
@ -4387,10 +4387,10 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err)
/* Record whether the file is compressed.
XXX - do we know this at open time? */
cf->iscompressed = wtap_iscompressed(cf->wth);
cf->iscompressed = wftap_iscompressed(cf->wfth);
/* Find the size of the file. */
size = wtap_file_size(cf->wth, NULL);
size = wftap_file_size(cf->wfth, NULL);
/* Update the progress bar when it gets to this value. */
progbar_nextstep = 0;
@ -4407,14 +4407,14 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err)
g_get_current_time(&start_time);
framenum = 0;
phdr = wtap_phdr(cf->wth);
while ((wtap_read(cf->wth, err, &err_info, &data_offset))) {
phdr = wtap_phdr(cf->wfth);
while ((wtap_read(cf->wfth, err, &err_info, &data_offset))) {
framenum++;
fdata = frame_data_sequence_find(cf->frames, framenum);
fdata->file_off = data_offset;
if (size >= 0) {
count++;
file_pos = wtap_read_so_far(cf->wth);
file_pos = wftap_read_so_far(cf->wfth);
/* Create the progress bar if necessary.
* Check whether it should be created or not every MIN_NUMBER_OF_PACKET
@ -4475,7 +4475,7 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err)
cf->state = FILE_READ_DONE;
/* Close the sequential I/O side, to free up memory it requires. */
wtap_sequential_close(cf->wth);
wftap_sequential_close(cf->wfth);
/* compute the time it took to load the file */
compute_elapsed(cf, &start_time);
@ -4484,7 +4484,7 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err)
we've looked at all the packets, as we don't know until then whether
there's more than one type (and thus whether it's
WTAP_ENCAP_PER_PACKET). */
cf->lnk_t = wtap_file_encap(cf->wth);
cf->lnk_t = wftap_file_encap(cf->wfth);
cf_callback_invoke(cf_cb_file_rescan_finished, cf);
@ -4557,7 +4557,7 @@ cf_save_packets(capture_file *cf, const char *fname, guint save_format,
{
gchar *err_info;
gchar *fname_new = NULL;
wtap_dumper *pdh;
wftap_dumper *pdh;
frame_data *fdata;
addrinfo_lists_t *addr_lists;
guint framenum;
@ -4662,8 +4662,8 @@ cf_save_packets(capture_file *cf, const char *fname, guint save_format,
wtapng_iface_descriptions_t *idb_inf = NULL;
int encap;
shb_hdr = wtap_file_get_shb_info(cf->wth);
idb_inf = wtap_file_get_idb_info(cf->wth);
shb_hdr = wtap_file_get_shb_info(cf->wfth);
idb_inf = wtap_file_get_idb_info(cf->wfth);
/* Determine what file encapsulation type we should use. */
encap = wtap_dump_file_encap_type(cf->linktypes);
@ -4710,7 +4710,7 @@ cf_save_packets(capture_file *cf, const char *fname, guint save_format,
If we're writing to a temporary file, remove it.
XXX - should we do so even if we're not writing to a
temporary file? */
wtap_dump_close(pdh, &err);
wftap_dump_close(pdh, &err);
if (fname_new != NULL)
ws_unlink(fname_new);
cf_callback_invoke(cf_cb_file_save_stopped, NULL);
@ -4721,11 +4721,11 @@ cf_save_packets(capture_file *cf, const char *fname, guint save_format,
If we're writing to a temporary file, remove it. */
if (fname_new != NULL)
ws_unlink(fname_new);
wtap_dump_close(pdh, &err);
wftap_dump_close(pdh, &err);
goto fail;
}
if (!wtap_dump_close(pdh, &err)) {
if (!wftap_dump_close(pdh, &err)) {
cf_close_failure_alert_box(fname, err);
goto fail;
}
@ -4739,7 +4739,7 @@ cf_save_packets(capture_file *cf, const char *fname, guint save_format,
on Windows. However, on Windows, we first need to close whatever
file descriptors we have open for fname. */
#ifdef _WIN32
wtap_fdclose(cf->wth);
wftap_fdclose(cf->wfth);
#endif
/* Now do the rename. */
if (ws_rename(fname_new, fname) == -1) {
@ -4749,7 +4749,7 @@ cf_save_packets(capture_file *cf, const char *fname, guint save_format,
/* Attempt to reopen the random file descriptor using the
current file's filename. (At this point, the sequential
file descriptor is closed.) */
if (!wtap_fdreopen(cf->wth, cf->filename, &err)) {
if (!wftap_fdreopen(cf->wfth, cf->filename, &err)) {
/* Oh, well, we're screwed. */
display_basename = g_filename_display_basename(cf->filename);
simple_error_message_box(
@ -4782,13 +4782,13 @@ cf_save_packets(capture_file *cf, const char *fname, guint save_format,
/* We just copied the file, s all the information other than
the wtap structure, the filename, and the "is temporary"
status applies to the new file; just update that. */
wtap_close(cf->wth);
wtap_close(cf->wfth);
/* Although we're just "copying" and then opening the copy, it will
try all open_routine readers to open the copy, so we need to
reset the cfile's open_type. */
cf->open_type = WTAP_TYPE_AUTO;
cf->wth = wtap_open_offline(fname, WTAP_TYPE_AUTO, &err, &err_info, TRUE);
if (cf->wth == NULL) {
cf->wfth = wtap_open_offline(fname, WTAP_TYPE_AUTO, &err, &err_info, TRUE);
if (cf->wfth == NULL) {
cf_open_failure_alert_box(fname, err, err_info, FALSE, 0);
cf_close(cf);
} else {
@ -4834,7 +4834,7 @@ cf_save_packets(capture_file *cf, const char *fname, guint save_format,
/* If we were told to discard the comments, do so. */
if (discard_comments) {
/* Remove SHB comment, if any. */
wtap_write_shb_comment(cf->wth, NULL);
wtap_write_shb_comment(cf->wfth, NULL);
/* remove all user comments */
for (framenum = 1; framenum <= cf->count; framenum++) {
@ -4876,7 +4876,7 @@ cf_export_specified_packets(capture_file *cf, const char *fname,
{
gchar *fname_new = NULL;
int err;
wtap_dumper *pdh;
wftap_dumper *pdh;
save_callback_args_t callback_args;
wtapng_section_t *shb_hdr;
wtapng_iface_descriptions_t *idb_inf;
@ -4891,8 +4891,8 @@ cf_export_specified_packets(capture_file *cf, const char *fname,
written, don't special-case the operation - read each packet
and then write it out if it's one of the specified ones. */
shb_hdr = wtap_file_get_shb_info(cf->wth);
idb_inf = wtap_file_get_idb_info(cf->wth);
shb_hdr = wtap_file_get_shb_info(cf->wfth);
idb_inf = wtap_file_get_idb_info(cf->wfth);
/* Determine what file encapsulation type we should use. */
encap = wtap_dump_file_encap_type(cf->linktypes);
@ -4945,7 +4945,7 @@ cf_export_specified_packets(capture_file *cf, const char *fname,
If we're writing to a temporary file, remove it.
XXX - should we do so even if we're not writing to a
temporary file? */
wtap_dump_close(pdh, &err);
wftap_dump_close(pdh, &err);
if (fname_new != NULL)
ws_unlink(fname_new);
cf_callback_invoke(cf_cb_file_export_specified_packets_stopped, NULL);
@ -4957,11 +4957,11 @@ cf_export_specified_packets(capture_file *cf, const char *fname,
If we're writing to a temporary file, remove it. */
if (fname_new != NULL)
ws_unlink(fname_new);
wtap_dump_close(pdh, &err);
wftap_dump_close(pdh, &err);
goto fail;
}
if (!wtap_dump_close(pdh, &err)) {
if (!wftap_dump_close(pdh, &err)) {
cf_close_failure_alert_box(fname, err);
goto fail;
}

View File

@ -538,7 +538,7 @@ ftap* ftap_open_offline(const char *filename, int *err, char **err_info,
if (use_stdin) {
/*
* We dup FD 0, so that we don't have to worry about
* a file_close of wth->fh closing the standard
* a file_close of wfth->fh closing the standard
* input of the process.
*/
fd = ws_dup(0);

View File

@ -378,7 +378,7 @@ ftap_read(ftap *fth, int *err, gchar **err_info, gint64 *data_offset)
* *is* FTAP_ENCAP_PER_RECORD, the caller needs to set it
* anyway.
*/
wth->phdr.pkt_encap = wth->file_encap;
wth->phdr.pkt_encap = wfth->file_encap;
#endif
if (!fth->subtype_read(fth, err, err_info, data_offset)) {
@ -460,12 +460,6 @@ wtap_phdr(wtap *wth)
{
return &wth->phdr;
}
guint8 *
wtap_buf_ptr(wtap *wth)
{
return buffer_start_ptr(wth->frame_buffer);
}
#endif
gboolean

View File

@ -31,14 +31,14 @@
#include "frame_tvbuff.h"
#include "globals.h"
#include "wtap-int.h" /* for ->random_fh */
#include "wftap-int.h" /* for ->random_fh */
struct tvb_frame {
struct tvbuff tvb;
Buffer *buf; /* Packet data */
wtap *wth; /**< Wiretap session */
wftap *wth; /**< Wiretap session */
gint64 file_off; /**< File offset */
guint offset;
@ -51,13 +51,13 @@ frame_read(struct tvb_frame *frame_tvb, struct wtap_pkthdr *phdr, Buffer *buf)
gchar *err_info;
/* sanity check, capture file was closed? */
if (cfile.wth != frame_tvb->wth)
if (cfile.wfth != frame_tvb->wth)
return FALSE;
/* XXX, what if phdr->caplen isn't equal to
* frame_tvb->tvb.length + frame_tvb->offset?
*/
if (!wtap_seek_read(frame_tvb->wth, frame_tvb->file_off, phdr, buf, &err, &err_info)) {
if (!wftap_seek_read(frame_tvb->wth, frame_tvb->file_off, phdr, buf, &err, &err_info)) {
switch (err) {
case WTAP_ERR_UNSUPPORTED_ENCAP:
case WTAP_ERR_BAD_FILE:
@ -212,12 +212,12 @@ frame_tvbuff_new(const frame_data *fd, const guint8 *buf)
frame_tvb = (struct tvb_frame *) tvb;
/* XXX, wtap_can_seek() */
if (cfile.wth && cfile.wth->random_fh
if (cfile.wfth && cfile.wfth->random_fh
#ifdef WANT_PACKET_EDITOR
&& fd->file_off != -1 /* generic clone for modified packets */
#endif
) {
frame_tvb->wth = cfile.wth;
frame_tvb->wth = cfile.wfth;
frame_tvb->file_off = fd->file_off;
frame_tvb->offset = 0;
} else
@ -317,12 +317,12 @@ file_tvbuff_new(const frame_data *fd, const guint8 *buf)
frame_tvb = (struct tvb_frame *) tvb;
/* XXX, wtap_can_seek() */
if (cfile.wth && cfile.wth->random_fh
if (cfile.wfth && cfile.wfth->random_fh
#ifdef WANT_PACKET_EDITOR
&& fd->file_off != -1 /* generic clone for modified packets */
#endif
) {
frame_tvb->wth = cfile.wth;
frame_tvb->wth = cfile.wfth;
frame_tvb->file_off = fd->file_off;
frame_tvb->offset = 0;
} else

View File

@ -225,7 +225,7 @@ main(int argc, char *argv[])
merge_in_file_t *in_files = NULL, *in_file;
int i;
struct wtap_pkthdr *phdr, snap_phdr;
wtap_dumper *pdh;
wftap_dumper *pdh;
int open_err, read_err = 0, write_err, close_err;
gchar *err_info;
int err_fileno;
@ -333,7 +333,7 @@ main(int argc, char *argv[])
if (verbose) {
for (i = 0; i < in_file_count; i++)
fprintf(stderr, "mergecap: %s is type %s.\n", argv[optind + i],
wtap_file_type_subtype_string(wtap_file_type_subtype(in_files[i].wth)));
wtap_file_type_subtype_string(wftap_file_type_subtype(in_files[i].wfth)));
}
if (snaplen == 0) {
@ -357,9 +357,9 @@ main(int argc, char *argv[])
*/
int first_frame_type, this_frame_type;
first_frame_type = wtap_file_encap(in_files[0].wth);
first_frame_type = wftap_file_encap(in_files[0].wfth);
for (i = 1; i < in_file_count; i++) {
this_frame_type = wtap_file_encap(in_files[i].wth);
this_frame_type = wftap_file_encap(in_files[i].wfth);
if (first_frame_type != this_frame_type) {
fprintf(stderr, "mergecap: multiple frame encapsulation types detected\n");
fprintf(stderr, " defaulting to WTAP_ENCAP_PER_PACKET\n");
@ -452,14 +452,14 @@ main(int argc, char *argv[])
/* We simply write it, perhaps after truncating it; we could do other
* things, like modify it. */
phdr = wtap_phdr(in_file->wth);
phdr = wtap_phdr(in_file->wfth);
if (snaplen != 0 && phdr->caplen > snaplen) {
snap_phdr = *phdr;
snap_phdr.caplen = snaplen;
phdr = &snap_phdr;
}
if (!wtap_dump(pdh, phdr, wtap_buf_ptr(in_file->wth), &write_err)) {
if (!wtap_dump(pdh, phdr, wftap_buf_ptr(in_file->wfth), &write_err)) {
got_write_error = TRUE;
break;
}
@ -467,7 +467,7 @@ main(int argc, char *argv[])
merge_close_in_files(in_file_count, in_files);
if (!got_write_error) {
if (!wtap_dump_close(pdh, &write_err))
if (!wftap_dump_close(pdh, &write_err))
got_write_error = TRUE;
} else {
/*
@ -476,7 +476,7 @@ main(int argc, char *argv[])
*
* Don't overwrite the earlier write error.
*/
(void)wtap_dump_close(pdh, &close_err);
(void)wftap_dump_close(pdh, &close_err);
}
if (got_read_error) {

View File

@ -494,7 +494,7 @@ int
main(int argc, char **argv)
{
wtap_dumper *dump;
wftap_dumper *dump;
struct wtap_pkthdr pkthdr;
union wtap_pseudo_header *ps_header = &pkthdr.pseudo_header;
int i, j, len_this_pkt, len_random, err;
@ -620,7 +620,7 @@ main(int argc, char **argv)
wtap_dump(dump, &pkthdr, &buffer[0], &err);
}
wtap_dump_close(dump, &err);
wftap_dump_close(dump, &err);
return 0;

View File

@ -867,7 +867,7 @@ main(int argc, char *argv[])
/* Set timestamp precision; there should arguably be a command-line
option to let the user set this. */
#if 0
switch(wtap_file_tsprecision(cfile.wth)) {
switch(wftap_file_tsprecision(cfile.wth)) {
case(WTAP_FILE_TSPREC_SEC):
timestamp_set_precision(TS_PREC_AUTO_SEC);
break;
@ -1665,7 +1665,7 @@ raw_cf_open(capture_file *cf, const char *fname)
epan_free(cf->epan);
cf->epan = raw_epan_new(cf);
cf->wth = NULL;
cf->wfth = NULL;
cf->f_datalen = 0; /* not used, but set it anyway */
/* Set the file name because we need it to set the follow stream filter.

View File

@ -89,7 +89,7 @@ typedef struct FrameRecord_t {
static void
frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh, Buffer *buf,
frame_write(FrameRecord_t *frame, wftap *wth, wftap_dumper *pdh, Buffer *buf,
const char *infile)
{
int err;
@ -103,7 +103,7 @@ frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh, Buffer *buf,
/* Re-read the first frame from the stored location */
if (!wtap_seek_read(wth, frame->offset, &phdr, buf, &err, &err_info)) {
if (!wftap_seek_read(wth, frame->offset, &phdr, buf, &err, &err_info)) {
if (err != 0) {
/* Print a message noting that the read failed somewhere along the line. */
fprintf(stderr,
@ -174,8 +174,8 @@ frames_compare(gconstpointer a, gconstpointer b)
/********************************************************************/
int main(int argc, char *argv[])
{
wtap *wth = NULL;
wtap_dumper *pdh = NULL;
wftap *wth = NULL;
wftap_dumper *pdh = NULL;
Buffer buf;
int err;
gchar *err_info;
@ -241,13 +241,13 @@ int main(int argc, char *argv[])
}
exit(1);
}
DEBUG_PRINT("file_type_subtype is %u\n", wtap_file_type_subtype(wth));
DEBUG_PRINT("file_type_subtype is %u\n", wftap_file_type_subtype(wth));
shb_hdr = wtap_file_get_shb_info(wth);
idb_inf = wtap_file_get_idb_info(wth);
/* Open outfile (same filetype/encap as input file) */
pdh = wtap_dump_open_ng(outfile, wtap_file_type_subtype(wth), wtap_file_encap(wth),
pdh = wtap_dump_open_ng(outfile, wftap_file_type_subtype(wth), wftap_file_encap(wth),
65535, FALSE, shb_hdr, idb_inf, &err);
g_free(idb_inf);
if (pdh == NULL) {
@ -322,7 +322,7 @@ int main(int argc, char *argv[])
g_ptr_array_free(frames, TRUE);
/* Close outfile */
if (!wtap_dump_close(pdh, &err)) {
if (!wftap_dump_close(pdh, &err)) {
fprintf(stderr, "reordercap: Error closing %s: %s\n", outfile,
wtap_strerror(err));
g_free(shb_hdr);
@ -331,7 +331,7 @@ int main(int argc, char *argv[])
g_free(shb_hdr);
/* Finally, close infile */
wtap_fdclose(wth);
wftap_fdclose(wth);
return 0;
}

View File

@ -156,7 +156,7 @@ summary_fill_in(capture_file *cf, summary_tally *st)
st->dfilter = cf->dfilter;
/* Get info from SHB */
shb_inf = wtap_file_get_shb_info(cf->wth);
shb_inf = wtap_file_get_shb_info(cf->wfth);
if(shb_inf == NULL){
st->opt_comment = NULL;
st->shb_hardware = NULL;
@ -171,7 +171,7 @@ summary_fill_in(capture_file *cf, summary_tally *st)
}
st->ifaces = g_array_new(FALSE, FALSE, sizeof(iface_options));
idb_info = wtap_file_get_idb_info(cf->wth);
idb_info = wtap_file_get_idb_info(cf->wfth);
for (i = 0; i < idb_info->number_of_interfaces; i++) {
wtapng_if_descr = g_array_index(idb_info->interface_data, wtapng_if_descr_t, i);
iface.cfilter = g_strdup(wtapng_if_descr.if_filter_str);

View File

@ -89,6 +89,7 @@
#include <epan/timestamp.h>
#include <epan/ex-opt.h>
#include <filetap/ftap.h>
#include <wiretap/wftap-int.h>
#include <wiretap/wtap-int.h>
#include <wiretap/file_wrappers.h>
@ -166,28 +167,6 @@ static void write_failure_message(const char *filename, int err);
capture_file cfile;
#if 0
struct string_elem {
const char *sstr; /* The short string */
const char *lstr; /* The long string */
};
static gint
string_compare(gconstpointer a, gconstpointer b)
{
return strcmp(((const struct string_elem *)a)->sstr,
((const struct string_elem *)b)->sstr);
}
static void
string_elem_print(gpointer data, gpointer not_used _U_)
{
fprintf(stderr, " %s - %s\n",
((struct string_elem *)data)->sstr,
((struct string_elem *)data)->lstr);
}
#endif
static void
print_usage(gboolean print_ver)
{
@ -1145,7 +1124,7 @@ main(int argc, char *argv[])
rfilter = optarg;
break;
case 'S': /* Set the line Separator to be printed between packets */
separator = strdup(optarg);
separator = g_strdup(optarg);
break;
case 't': /* Time stamp type */
if (strcmp(optarg, "r") == 0)
@ -1504,7 +1483,7 @@ tfshark_get_frame_ts(void *data, guint32 frame_num)
static const char *
no_interface_name(void *data _U_, guint32 interface_id _U_)
{
return "";
return NULL;
}
static epan_t *
@ -1688,13 +1667,13 @@ gboolean
local_wtap_read(capture_file *cf, struct wtap_pkthdr* file_phdr, int *err, gchar **err_info, gint64 *data_offset _U_, guint8** data_buffer)
{
int bytes_read;
gint64 packet_size = wtap_file_size(cf->wth, err);
gint64 packet_size = wftap_file_size(cf->wfth, err);
*data_buffer = (guint8*)g_malloc((gsize)packet_size);
bytes_read = file_read(*data_buffer, (unsigned int)packet_size, cf->wth->fh);
bytes_read = file_read(*data_buffer, (unsigned int)packet_size, cf->wfth->fh);
if (bytes_read < 0) {
*err = file_error(cf->wth->fh, err_info);
*err = file_error(cf->wfth->fh, err_info);
if (*err == 0)
*err = FTAP_ERR_SHORT_READ;
return FALSE;
@ -1717,9 +1696,9 @@ local_wtap_read(capture_file *cf, struct wtap_pkthdr* file_phdr, int *err, gchar
* *is* WTAP_ENCAP_PER_PACKET, the caller needs to set it
* anyway.
*/
wth->phdr.pkt_encap = wth->file_encap;
wth->phdr.pkt_encap = wfth->file_encap;
if (!wth->subtype_read(wth, err, err_info, data_offset)) {
if (!wfth->subtype_read(wth, err, err_info, data_offset)) {
/*
* If we didn't get an error indication, we read
* the last packet. See if there's any deferred
@ -1730,7 +1709,7 @@ local_wtap_read(capture_file *cf, struct wtap_pkthdr* file_phdr, int *err, gchar
* last packet of the file.
*/
if (*err == 0)
*err = file_error(wth->fh, err_info);
*err = file_error(wfth->fh, err_info);
return FALSE; /* failure */
}
@ -1805,8 +1784,8 @@ load_cap_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
edt = epan_dissect_new(cf->epan, create_proto_tree, FALSE);
}
while (local_wtap_read(cf, &file_phdr, &err, &err_info, &data_offset, &raw_data)) {
if (process_packet_first_pass(cf, edt, data_offset, &file_phdr/*wtap_phdr(cf->wth)*/,
wtap_buf_ptr(cf->wth))) {
if (process_packet_first_pass(cf, edt, data_offset, &file_phdr/*wtap_phdr(cf->wfth)*/,
wftap_buf_ptr(cf->wfth))) {
/* Stop reading if we have the maximum number of packets;
* When the -c option has not been used, max_packet_count
@ -1827,7 +1806,7 @@ load_cap_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
#if 0
/* Close the sequential I/O side, to free up memory it requires. */
wtap_sequential_close(cf->wth);
wtap_sequential_close(cf->wfth);
#endif
/* Allow the protocol dissectors to free up memory that they
@ -1857,12 +1836,12 @@ load_cap_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
for (framenum = 1; err == 0 && framenum <= cf->count; framenum++) {
fdata = frame_data_sequence_find(cf->frames, framenum);
#if 0
if (wtap_seek_read(cf->wth, fdata->file_off,
if (wtap_seek_read(cf->wfth, fdata->file_off,
&buf, fdata->cap_len, &err, &err_info)) {
process_packet_second_pass(cf, edt, fdata, &cf->phdr, &buf, tap_flags);
process_packet_second_pass(cf, edt, fdata, &cf->hdr.wtap_hdr, &buf, tap_flags);
}
#else
process_packet_second_pass(cf, edt, fdata, &cf->phdr, &buf, tap_flags);
process_packet_second_pass(cf, edt, fdata, &cf->hdr.wtap_hdr, &buf, tap_flags);
#endif
}
@ -1896,7 +1875,7 @@ load_cap_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
framenum++;
process_packet(cf, edt, data_offset, &file_phdr/*wtap_phdr(cf->wth)*/,
process_packet(cf, edt, data_offset, &file_phdr/*wtap_phdr(cf->wfth)*/,
raw_data, tap_flags);
/* Stop reading if we have the maximum number of packets;
@ -1991,8 +1970,8 @@ load_cap_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
}
out:
wtap_close(cf->wth);
cf->wth = NULL;
wtap_close(cf->wfth);
cf->wfth = NULL;
return err;
}
@ -2509,7 +2488,7 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp
#if USE_FTAP
ftap *fth;
#else
wtap *wth;
wftap *wth;
#endif
gchar *err_info;
char err_msg[2048+1];
@ -2531,9 +2510,9 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp
cf->epan = tfshark_epan_new(cf);
#if USE_FTAP
cf->wth = (struct wtap*)fth; /**** XXX - DOESN'T WORK RIGHT NOW!!!! */
cf->wfth = (struct wtap*)fth; /**** XXX - DOESN'T WORK RIGHT NOW!!!! */
#else
cf->wth = wth;
cf->wfth = wth;
#endif
cf->f_datalen = 0; /* not used, but set it anyway */
@ -2548,12 +2527,12 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp
/* No user changes yet. */
cf->unsaved_changes = FALSE;
cf->cd_t = ftap_file_type_subtype((struct ftap*)cf->wth); /**** XXX - DOESN'T WORK RIGHT NOW!!!! */
cf->cd_t = ftap_file_type_subtype((struct ftap*)cf->wfth); /**** XXX - DOESN'T WORK RIGHT NOW!!!! */
cf->open_type = type;
cf->count = 0;
cf->drops_known = FALSE;
cf->drops = 0;
cf->snap = ftap_snapshot_length((struct ftap*)cf->wth); /**** XXX - DOESN'T WORK RIGHT NOW!!!! */
cf->snap = ftap_snapshot_length((struct ftap*)cf->wfth); /**** XXX - DOESN'T WORK RIGHT NOW!!!! */
if (cf->snap == 0) {
/* Snapshot length not known. */
cf->has_snap = FALSE;

View File

@ -2043,7 +2043,7 @@ main(int argc, char *argv[])
/* Set timestamp precision; there should arguably be a command-line
option to let the user set this. */
switch(wtap_file_tsprecision(cfile.wth)) {
switch(wftap_file_tsprecision(cfile.wfth)) {
case(WTAP_FILE_TSPREC_SEC):
timestamp_set_precision(TS_PREC_AUTO_SEC);
break;
@ -2611,9 +2611,9 @@ capture_input_new_file(capture_session *cap_session, gchar *new_file)
/* we start a new capture file, close the old one (if we had one before) */
if ( ((capture_file *) cap_session->cf)->state != FILE_CLOSED) {
if ( ((capture_file *) cap_session->cf)->wth != NULL) {
wtap_close(((capture_file *) cap_session->cf)->wth);
((capture_file *) cap_session->cf)->wth = NULL;
if ( ((capture_file *) cap_session->cf)->wfth != NULL) {
wtap_close(((capture_file *) cap_session->cf)->wfth);
((capture_file *) cap_session->cf)->wfth = NULL;
}
((capture_file *) cap_session->cf)->state = FILE_CLOSED;
}
@ -2694,17 +2694,17 @@ capture_input_new_packets(capture_session *cap_session, int to_read)
("packet_details" is true). */
edt = epan_dissect_new(cf->epan, create_proto_tree, print_packet_info && print_details);
while (to_read-- && cf->wth) {
wtap_cleareof(cf->wth);
ret = wtap_read(cf->wth, &err, &err_info, &data_offset);
while (to_read-- && cf->wfth) {
wftap_cleareof(cf->wfth);
ret = wtap_read(cf->wfth, &err, &err_info, &data_offset);
if (ret == FALSE) {
/* read from file failed, tell the capture child to stop */
sync_pipe_stop(cap_session);
wtap_close(cf->wth);
cf->wth = NULL;
wtap_close(cf->wfth);
cf->wfth = NULL;
} else {
ret = process_packet(cf, edt, data_offset, wtap_phdr(cf->wth),
wtap_buf_ptr(cf->wth),
ret = process_packet(cf, edt, data_offset, wtap_phdr(cf->wfth),
wftap_buf_ptr(cf->wfth),
tap_flags);
}
if (ret != FALSE) {
@ -2809,8 +2809,8 @@ capture_input_closed(capture_session *cap_session, gchar *msg)
report_counts();
if (cf != NULL && cf->wth != NULL) {
wtap_close(cf->wth);
if (cf != NULL && cf->wfth != NULL) {
wtap_close(cf->wfth);
if (cf->is_tempfile) {
ws_unlink(cf->filename);
}
@ -3060,7 +3060,7 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
{
gint linktype;
int snapshot_length;
wtap_dumper *pdh;
wftap_dumper *pdh;
guint32 framenum;
int err;
gchar *err_info = NULL;
@ -3077,23 +3077,23 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
memset(&phdr, 0, sizeof(struct wtap_pkthdr));
shb_hdr = wtap_file_get_shb_info(cf->wth);
idb_inf = wtap_file_get_idb_info(cf->wth);
shb_hdr = wtap_file_get_shb_info(cf->wfth);
idb_inf = wtap_file_get_idb_info(cf->wfth);
#ifdef PCAP_NG_DEFAULT
if (idb_inf->number_of_interfaces > 1) {
linktype = WTAP_ENCAP_PER_PACKET;
} else {
linktype = wtap_file_encap(cf->wth);
linktype = wftap_file_encap(cf->wfth);
}
#else
linktype = wtap_file_encap(cf->wth);
linktype = wftap_file_encap(cf->wfth);
#endif
if (save_file != NULL) {
/* Get a string that describes what we're writing to */
save_file_string = output_file_description(save_file);
/* Set up to write to the capture file. */
snapshot_length = wtap_snapshot_length(cf->wth);
snapshot_length = wftap_snapshot_length(cf->wfth);
if (snapshot_length == 0) {
/* Snapshot length of input file not known. */
snapshot_length = WTAP_MAX_PACKET_SIZE;
@ -3191,9 +3191,9 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
edt = epan_dissect_new(cf->epan, create_proto_tree, FALSE);
}
while (wtap_read(cf->wth, &err, &err_info, &data_offset)) {
if (process_packet_first_pass(cf, edt, data_offset, wtap_phdr(cf->wth),
wtap_buf_ptr(cf->wth))) {
while (wtap_read(cf->wfth, &err, &err_info, &data_offset)) {
if (process_packet_first_pass(cf, edt, data_offset, wtap_phdr(cf->wfth),
wftap_buf_ptr(cf->wfth))) {
/* Stop reading if we have the maximum number of packets;
* When the -c option has not been used, max_packet_count
* starts at 0, which practically means, never stop reading.
@ -3212,7 +3212,7 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
}
/* Close the sequential I/O side, to free up memory it requires. */
wtap_sequential_close(cf->wth);
wftap_sequential_close(cf->wfth);
/* Allow the protocol dissectors to free up memory that they
* don't need after the sequential run-through of the packets. */
@ -3240,7 +3240,7 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
for (framenum = 1; err == 0 && framenum <= cf->count; framenum++) {
fdata = frame_data_sequence_find(cf->frames, framenum);
if (wtap_seek_read(cf->wth, fdata->file_off, &phdr, &buf, &err,
if (wftap_seek_read(cf->wfth, fdata->file_off, &phdr, &buf, &err,
&err_info)) {
if (process_packet_second_pass(cf, edt, fdata, &phdr, &buf,
tap_flags)) {
@ -3286,7 +3286,7 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
show_capture_file_io_error(save_file, err, FALSE);
break;
}
wtap_dump_close(pdh, &err);
wftap_dump_close(pdh, &err);
g_free(shb_hdr);
exit(2);
}
@ -3321,17 +3321,17 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
edt = epan_dissect_new(cf->epan, create_proto_tree, print_packet_info && print_details);
}
while (wtap_read(cf->wth, &err, &err_info, &data_offset)) {
while (wtap_read(cf->wfth, &err, &err_info, &data_offset)) {
framenum++;
if (process_packet(cf, edt, data_offset, wtap_phdr(cf->wth),
wtap_buf_ptr(cf->wth),
if (process_packet(cf, edt, data_offset, wtap_phdr(cf->wfth),
wftap_buf_ptr(cf->wfth),
tap_flags)) {
/* Either there's no read filtering or this packet passed the
filter, so, if we're writing to a capture file, write
this packet out. */
if (pdh != NULL) {
if (!wtap_dump(pdh, wtap_phdr(cf->wth), wtap_buf_ptr(cf->wth), &err)) {
if (!wtap_dump(pdh, wtap_phdr(cf->wfth), wftap_buf_ptr(cf->wfth), &err)) {
/* Error writing to a capture file */
switch (err) {
@ -3363,7 +3363,7 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
show_capture_file_io_error(save_file, err, FALSE);
break;
}
wtap_dump_close(pdh, &err);
wftap_dump_close(pdh, &err);
g_free(shb_hdr);
exit(2);
}
@ -3453,13 +3453,13 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
}
if (save_file != NULL) {
/* Now close the capture file. */
if (!wtap_dump_close(pdh, &err))
if (!wftap_dump_close(pdh, &err))
show_capture_file_io_error(save_file, err, TRUE);
}
} else {
if (save_file != NULL) {
/* Now close the capture file. */
if (!wtap_dump_close(pdh, &err))
if (!wftap_dump_close(pdh, &err))
show_capture_file_io_error(save_file, err, TRUE);
} else {
if (print_packet_info) {
@ -3472,8 +3472,8 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
}
out:
wtap_close(cf->wth);
cf->wth = NULL;
wtap_close(cf->wfth);
cf->wfth = NULL;
g_free(save_file_string);
g_free(shb_hdr);
@ -3995,7 +3995,7 @@ write_finale(void)
cf_status_t
cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_tempfile, int *err)
{
wtap *wth;
wftap *wth;
gchar *err_info;
char err_msg[2048+1];
@ -4009,7 +4009,7 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp
epan_free(cf->epan);
cf->epan = tshark_epan_new(cf);
cf->wth = wth;
cf->wfth = wth;
cf->f_datalen = 0; /* not used, but set it anyway */
/* Set the file name because we need it to set the follow stream filter.
@ -4023,12 +4023,12 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp
/* No user changes yet. */
cf->unsaved_changes = FALSE;
cf->cd_t = wtap_file_type_subtype(cf->wth);
cf->cd_t = wftap_file_type_subtype(cf->wfth);
cf->open_type = type;
cf->count = 0;
cf->drops_known = FALSE;
cf->drops = 0;
cf->snap = wtap_snapshot_length(cf->wth);
cf->snap = wftap_snapshot_length(cf->wfth);
if (cf->snap == 0) {
/* Snapshot length not known. */
cf->has_snap = FALSE;
@ -4042,8 +4042,8 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp
cf->state = FILE_READ_IN_PROGRESS;
wtap_set_cb_new_ipv4(cf->wth, add_ipv4_name);
wtap_set_cb_new_ipv6(cf->wth, (wtap_new_ipv6_callback_t) add_ipv6_name);
wtap_set_cb_new_ipv4(cf->wfth, add_ipv4_name);
wtap_set_cb_new_ipv6(cf->wfth, (wtap_new_ipv6_callback_t) add_ipv6_name);
return CF_OK;

View File

@ -105,11 +105,11 @@ static gboolean color_selected;
/* set a new filename for the preview widget */
static wtap *
static wftap *
preview_set_filename(GtkWidget *prev, const gchar *cf_name)
{
GtkWidget *label;
wtap *wth;
wftap *wth;
int err = 0;
gchar *err_info;
gchar string_buff[PREVIEW_STR_MAX];
@ -150,7 +150,7 @@ preview_set_filename(GtkWidget *prev, const gchar *cf_name)
}
/* Find the size of the file. */
filesize = wtap_file_size(wth, &err);
filesize = wftap_file_size(wth, &err);
if (filesize == -1) {
gtk_label_set_text(GTK_LABEL(label), "error getting file size");
wtap_close(wth);
@ -161,7 +161,7 @@ preview_set_filename(GtkWidget *prev, const gchar *cf_name)
gtk_label_set_text(GTK_LABEL(label), string_buff);
/* type */
g_strlcpy(string_buff, wtap_file_type_subtype_string(wtap_file_type_subtype(wth)), PREVIEW_STR_MAX);
g_strlcpy(string_buff, wtap_file_type_subtype_string(wftap_file_type_subtype(wth)), PREVIEW_STR_MAX);
label = (GtkWidget *)g_object_get_data(G_OBJECT(prev), PREVIEW_FORMAT_KEY);
gtk_label_set_text(GTK_LABEL(label), string_buff);
@ -171,7 +171,7 @@ preview_set_filename(GtkWidget *prev, const gchar *cf_name)
/* do a preview run on the currently selected capture file */
static void
preview_do(GtkWidget *prev, wtap *wth)
preview_do(GtkWidget *prev, wftap *wth)
{
GtkWidget *label;
unsigned int elapsed_time;
@ -299,7 +299,7 @@ file_open_entry_changed(GtkWidget *w _U_, gpointer file_sel)
GtkWidget *prev = (GtkWidget *)g_object_get_data(G_OBJECT(file_sel), PREVIEW_TABLE_KEY);
gchar *cf_name;
gboolean have_preview;
wtap *wth;
wftap *wth;
/* get the filename */
cf_name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(file_sel));

View File

@ -535,7 +535,7 @@ file_import_open(text_import_info_t *info)
read_failure_alert_box(info->import_text_filename, errno);
}
if (!wtap_dump_close(info->wdh, &err)) {
if (!wftap_dump_close(info->wdh, &err)) {
write_failure_alert_box(capfile_name, err);
}

View File

@ -3715,7 +3715,7 @@ void iax2_analysis_cb(GtkAction *action _U_, gpointer user_data _U_)
return; /* error reading the frame */
epan_dissect_init(&edt, cf->epan, TRUE, FALSE);
epan_dissect_prime_dfilter(&edt, sfcode);
epan_dissect_run(&edt, &cf->phdr, frame_tvbuff_new_buffer(fdata, &cf->buf),
epan_dissect_run(&edt, &cf->hdr.wtap_hdr, frame_tvbuff_new_buffer(fdata, &cf->buf),
fdata, NULL);
/* if it is not an iax2 frame, show an error dialog */

View File

@ -549,7 +549,7 @@ get_ip_address_list_from_packet_list_row(gpointer data)
epan_dissect_init(&edt, cfile.epan, FALSE, FALSE);
col_custom_prime_edt(&edt, &cfile.cinfo);
epan_dissect_run(&edt, &cfile.phdr, frame_tvbuff_new_buffer(fdata, &cfile.buf),
epan_dissect_run(&edt, &cfile.hdr.wtap_hdr, frame_tvbuff_new_buffer(fdata, &cfile.buf),
fdata, &cfile.cinfo);
epan_dissect_fill_in_columns(&edt, TRUE, TRUE);
@ -590,7 +590,7 @@ get_filter_from_packet_list_row_and_column(gpointer data)
epan_dissect_init(&edt, cfile.epan, have_custom_cols(&cfile.cinfo), FALSE);
col_custom_prime_edt(&edt, &cfile.cinfo);
epan_dissect_run(&edt, &cfile.phdr, frame_tvbuff_new_buffer(fdata, &cfile.buf),
epan_dissect_run(&edt, &cfile.hdr.wtap_hdr, frame_tvbuff_new_buffer(fdata, &cfile.buf),
fdata, &cfile.cinfo);
epan_dissect_fill_in_columns(&edt, TRUE, TRUE);

View File

@ -972,7 +972,7 @@ void new_packet_window(GtkWidget *w _U_, gboolean reference, gboolean editable _
/* XXX, protect cfile.epan from closing (ref counting?) */
DataPtr->epan = cfile.epan;
DataPtr->frame = fd;
DataPtr->phdr = cfile.phdr;
DataPtr->phdr = cfile.hdr.wtap_hdr;
DataPtr->pd = (guint8 *)g_malloc(DataPtr->frame->cap_len);
memcpy(DataPtr->pd, buffer_start_ptr(&cfile.buf), DataPtr->frame->cap_len);

View File

@ -917,7 +917,7 @@ static rlc_lte_tap_info *select_rlc_lte_session(capture_file *cf, struct segment
epan_dissect_init(&edt, cf->epan, TRUE, FALSE);
epan_dissect_prime_dfilter(&edt, sfcode);
epan_dissect_run_with_taps(&edt, &cf->phdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata, NULL);
epan_dissect_run_with_taps(&edt, &cf->hdr.wtap_hdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata, NULL);
rel_ts = edt.pi.rel_ts;
epan_dissect_cleanup(&edt);
remove_tap_listener(&th);

View File

@ -3950,7 +3950,7 @@ rtp_analysis_cb(GtkAction *action _U_, gpointer user_data _U_)
return; /* error reading the frame */
epan_dissect_init(&edt, cf->epan, TRUE, FALSE);
epan_dissect_prime_dfilter(&edt, sfcode);
epan_dissect_run(&edt, &cf->phdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata, NULL);
epan_dissect_run(&edt, &cf->hdr.wtap_hdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata, NULL);
/* if it is not an rtp frame, show the rtpstream dialog */
frame_matched = dfilter_apply_edt(sfcode, &edt);

View File

@ -980,7 +980,7 @@ sctp_analyse_cb(struct sctp_analyse *u_data, gboolean ext)
epan_dissect_init(&edt, cf->epan, TRUE, FALSE);
epan_dissect_prime_dfilter(&edt, sfcode);
epan_dissect_run(&edt, &cf->phdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata, NULL);
epan_dissect_run(&edt, &cf->hdr.wtap_hdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata, NULL);
frame_matched = dfilter_apply_edt(sfcode, &edt);
/* if it is not an sctp frame, show the dialog */

View File

@ -786,10 +786,10 @@ void CaptureFileDialog::preview(const QString & path)
}
// Format
preview_format_.setText(QString::fromUtf8(wtap_file_type_subtype_string(wtap_file_type_subtype(wth))));
preview_format_.setText(QString::fromUtf8(wtap_file_type_subtype_string(wftap_file_type_subtype(wth))));
// Size
preview_size_.setText(QString(tr("%1 bytes")).arg(wtap_file_size(wth, &err)));
preview_size_.setText(QString(tr("%1 bytes")).arg(wftap_file_size(wth, &err)));
time(&time_preview);
while ( (wtap_read(wth, &err, &err_info, &data_offset)) ) {

View File

@ -142,7 +142,7 @@ void ImportTextDialog::convertTextFile() {
read_failure_alert_box(import_info_.import_text_filename, errno);
}
if (!wtap_dump_close(import_info_.wdh, &err))
if (!wftap_dump_close(import_info_.wdh, &err))
{
write_failure_alert_box(capfile_name_.toUtf8().constData(), err);
}

View File

@ -661,7 +661,7 @@ QString &PacketList::getFilterFromRowAndColumn()
epan_dissect_init(&edt, cap_file_->epan, have_custom_cols(&cap_file_->cinfo), FALSE);
col_custom_prime_edt(&edt, &cap_file_->cinfo);
epan_dissect_run(&edt, &cap_file_->phdr, frame_tvbuff_new_buffer(fdata, &cap_file_->buf), fdata, &cap_file_->cinfo);
epan_dissect_run(&edt, &cap_file_->hdr.wtap_hdr, frame_tvbuff_new_buffer(fdata, &cap_file_->buf), fdata, &cap_file_->cinfo);
epan_dissect_fill_in_columns(&edt, TRUE, TRUE);
if ((cap_file_->cinfo.col_custom_occurrence[ctx_column_]) ||

View File

@ -319,7 +319,7 @@ select_tcpip_session(capture_file *cf, struct segment *hdrs)
epan_dissect_init(&edt, cf->epan, TRUE, FALSE);
epan_dissect_prime_dfilter(&edt, sfcode);
epan_dissect_run_with_taps(&edt, &cf->phdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata, NULL);
epan_dissect_run_with_taps(&edt, &cf->hdr.wtap_hdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata, NULL);
rel_ts = edt.pi.rel_ts;
epan_dissect_cleanup(&edt);
remove_tap_listener(&th);

View File

@ -154,7 +154,7 @@ exp_pdu_file_open(exp_pdu_t *exp_pdu_tap_data)
cf_retap_packets(&cfile);
if (!wtap_dump_close(exp_pdu_tap_data->wdh, &err)) {
if (!wftap_dump_close(exp_pdu_tap_data->wdh, &err)) {
write_failure_alert_box(capfile_name, err);
}

View File

@ -29,7 +29,7 @@ extern "C" {
typedef struct _exp_pdu_t {
int pkt_encap;
wtap_dumper* wdh;
wftap_dumper* wdh;
} exp_pdu_t;
void exp_pdu_file_open(exp_pdu_t *exp_pdu_tap_data);

View File

@ -191,7 +191,7 @@ static guint32 ts_usec = 0;
static char *ts_fmt = NULL;
static struct tm timecode_default;
static wtap_dumper* wdh;
static wftap_dumper* wdh;
/* HDR_ETH Offset base to parse */
static guint32 offset_base = 16;

View File

@ -71,7 +71,7 @@ typedef struct
/* Import info */
guint encapsulation;
wtap_dumper* wdh;
wftap_dumper* wdh;
/* Dummy header info (if encapsulation == 1) */
enum dummy_header_type dummy_header_type;

View File

@ -1114,7 +1114,7 @@ preview_set_file_info(HWND of_hwnd, gchar *preview_file) {
HWND cur_ctrl;
int i;
gboolean enable = FALSE;
wtap *wth;
wftap *wth;
const struct wtap_pkthdr *phdr;
int err = 0;
gchar *err_info;
@ -1177,10 +1177,10 @@ preview_set_file_info(HWND of_hwnd, gchar *preview_file) {
/* Format */
cur_ctrl = GetDlgItem(of_hwnd, EWFD_PTX_FORMAT);
SetWindowText(cur_ctrl, utf_8to16(wtap_file_type_subtype_string(wtap_file_type_subtype(wth))));
SetWindowText(cur_ctrl, utf_8to16(wtap_file_type_subtype_string(wftap_file_type_subtype(wth))));
/* Size */
filesize = wtap_file_size(wth, &err);
filesize = wftap_file_size(wth, &err);
utf_8to16_snprintf(string_buff, PREVIEW_STR_MAX, "%" G_GINT64_FORMAT " bytes", filesize);
cur_ctrl = GetDlgItem(of_hwnd, EWFD_PTX_SIZE);
SetWindowText(cur_ctrl, string_buff);

View File

@ -23,6 +23,7 @@
#include <string.h>
#include <time.h>
#include "wftap-int.h"
#include "wtap-int.h"
#include "file_wrappers.h"
#include "buffer.h"
@ -99,27 +100,27 @@ typedef struct
#define CST_5VW_CAPTURES_RECORD (CST_5VW_SECTION_CAPTURES << 28) /* 0x80000000 */
#define CST_5VW_SYSTEM_RECORD 0x00000000U
static gboolean _5views_read(wtap *wth, int *err, gchar **err_info,
static gboolean _5views_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean _5views_seek_read(wtap *wth, gint64 seek_off,
static gboolean _5views_seek_read(wftap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
static int _5views_read_header(wtap *wth, FILE_T fh, t_5VW_TimeStamped_Header *hdr,
static int _5views_read_header(wftap *wth, FILE_T fh, t_5VW_TimeStamped_Header *hdr,
struct wtap_pkthdr *phdr, int *err, gchar **err_info);
static gboolean _5views_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, const guint8 *pd, int *err);
static gboolean _5views_dump_close(wtap_dumper *wdh, int *err);
static gboolean _5views_dump(wftap_dumper *wdh, void* header, const guint8 *pd, int *err);
static gboolean _5views_dump_close(wftap_dumper *wdh, int *err);
int _5views_open(wtap *wth, int *err, gchar **err_info)
int _5views_open(wftap *wfth, int *err, gchar **err_info)
{
int bytes_read;
t_5VW_Capture_Header Capture_Header;
int encap = WTAP_ENCAP_UNKNOWN;
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(&Capture_Header.Info_Header, sizeof(t_5VW_Info_Header), wth->fh);
bytes_read = file_read(&Capture_Header.Info_Header, sizeof(t_5VW_Info_Header), wfth->fh);
if (bytes_read != sizeof(t_5VW_Info_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;
@ -171,30 +172,31 @@ int _5views_open(wtap *wth, int *err, gchar **err_info)
}
/* read the remaining header information */
bytes_read = file_read(&Capture_Header.HeaderDateCreation, sizeof (t_5VW_Capture_Header) - sizeof(t_5VW_Info_Header), wth->fh);
bytes_read = file_read(&Capture_Header.HeaderDateCreation, sizeof (t_5VW_Capture_Header) - sizeof(t_5VW_Info_Header), wfth->fh);
if (bytes_read != sizeof (t_5VW_Capture_Header)- sizeof(t_5VW_Info_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;
}
/* This is a 5views capture file */
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_5VIEWS;
wth->subtype_read = _5views_read;
wth->subtype_seek_read = _5views_seek_read;
wth->file_encap = encap;
wth->snapshot_length = 0; /* not available in header */
wth->tsprecision = WTAP_FILE_TSPREC_NSEC;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_5VIEWS;
wfth->subtype_read = _5views_read;
wfth->subtype_seek_read = _5views_seek_read;
wfth->file_encap = encap;
wfth->snapshot_length = 0; /* not available in header */
wfth->tsprecision = WTAP_FILE_TSPREC_NSEC;
return 1;
}
/* Read the next packet */
static gboolean
_5views_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
_5views_read(wftap *wfth, int *err, gchar **err_info, gint64 *data_offset)
{
t_5VW_TimeStamped_Header TimeStamped_Header;
wtap* wth = (wtap*)wfth->tap_specific_data;
/*
* Keep reading until we see a record with a subtype of
@ -202,10 +204,10 @@ _5views_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
*/
do
{
*data_offset = file_tell(wth->fh);
*data_offset = file_tell(wfth->fh);
/* Read record header. */
if (!_5views_read_header(wth, wth->fh, &TimeStamped_Header,
if (!_5views_read_header(wfth, wfth->fh, &TimeStamped_Header,
&wth->phdr, err, err_info))
return FALSE;
@ -219,7 +221,7 @@ _5views_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
/*
* Not a packet - skip to the next record.
*/
if (file_seek(wth->fh, TimeStamped_Header.RecSize, SEEK_CUR, err) == -1)
if (file_seek(wfth->fh, TimeStamped_Header.RecSize, SEEK_CUR, err) == -1)
return FALSE;
} while (1);
@ -234,23 +236,23 @@ _5views_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
return FALSE;
}
return wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
return wtap_read_packet_bytes(wfth->fh, wfth->frame_buffer,
wth->phdr.caplen, err, err_info);
}
static gboolean
_5views_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
_5views_seek_read(wftap *wfth, gint64 seek_off, struct wtap_pkthdr *phdr,
Buffer *buf, int *err, gchar **err_info)
{
t_5VW_TimeStamped_Header TimeStamped_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 header.
*/
if (!_5views_read_header(wth, wth->random_fh, &TimeStamped_Header,
if (!_5views_read_header(wfth, wfth->random_fh, &TimeStamped_Header,
phdr, err, err_info)) {
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
@ -260,14 +262,14 @@ _5views_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
/*
* Read the packet data.
*/
return wtap_read_packet_bytes(wth->random_fh, buf, phdr->caplen,
return wtap_read_packet_bytes(wfth->random_fh, buf, phdr->caplen,
err, err_info);
}
/* Read the header of the next packet. Return TRUE on success, FALSE
on error. */
static gboolean
_5views_read_header(wtap *wth, FILE_T fh, t_5VW_TimeStamped_Header *hdr,
_5views_read_header(wftap *wfth, FILE_T fh, t_5VW_TimeStamped_Header *hdr,
struct wtap_pkthdr *phdr, int *err, gchar **err_info)
{
int bytes_read, bytes_to_read;
@ -303,7 +305,7 @@ _5views_read_header(wtap *wth, FILE_T fh, t_5VW_TimeStamped_Header *hdr,
phdr->caplen = hdr->RecSize;
phdr->len = hdr->RecSize;
switch (wth->file_encap) {
switch (wfth->file_encap) {
case WTAP_ENCAP_ETHERNET:
/* We assume there's no FCS in this frame. */
@ -340,7 +342,7 @@ int _5views_dump_can_write_encap(int encap)
/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on
failure */
gboolean _5views_dump_open(wtap_dumper *wdh, int *err)
gboolean _5views_dump_open(wftap_dumper *wdh, int *err)
{
_5views_dump_t *_5views;
@ -348,7 +350,7 @@ gboolean _5views_dump_open(wtap_dumper *wdh, int *err)
haven't yet written any packets. As we'll have to rewrite
the header when we've written out all the packets, we just
skip over the header for now. */
if (wtap_dump_file_seek(wdh, sizeof(t_5VW_Capture_Header), SEEK_SET, err) == -1)
if (wftap_dump_file_seek(wdh, sizeof(t_5VW_Capture_Header), SEEK_SET, err) == -1)
return FALSE;
/* This is a 5Views file */
@ -363,12 +365,12 @@ gboolean _5views_dump_open(wtap_dumper *wdh, int *err)
/* Write a record for a packet to a dump file.
Returns TRUE on success, FALSE on failure. */
static gboolean _5views_dump(wtap_dumper *wdh,
const struct wtap_pkthdr *phdr,
static gboolean _5views_dump(wftap_dumper *wdh, void* header,
const guint8 *pd, int *err)
{
_5views_dump_t *_5views = (_5views_dump_t *)wdh->priv;
t_5VW_TimeStamped_Header HeaderFrame;
const struct wtap_pkthdr *phdr = (const struct wtap_pkthdr*)header;
/* Don't write out something bigger than we can read. */
if (phdr->caplen > WTAP_MAX_PACKET_SIZE) {
@ -392,12 +394,12 @@ static gboolean _5views_dump(wtap_dumper *wdh,
HeaderFrame.RecInfo = GUINT32_TO_LE(0);
/* write the record header */
if (!wtap_dump_file_write(wdh, &HeaderFrame,
if (!wftap_dump_file_write(wdh, &HeaderFrame,
sizeof(t_5VW_TimeStamped_Header), err))
return FALSE;
/* write the data */
if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err))
if (!wftap_dump_file_write(wdh, pd, phdr->caplen, err))
return FALSE;
_5views->nframes ++;
@ -405,12 +407,12 @@ static gboolean _5views_dump(wtap_dumper *wdh,
return TRUE;
}
static gboolean _5views_dump_close(wtap_dumper *wdh, int *err)
static gboolean _5views_dump_close(wftap_dumper *wdh, int *err)
{
_5views_dump_t *_5views = (_5views_dump_t *)wdh->priv;
t_5VW_Capture_Header file_hdr;
if (wtap_dump_file_seek(wdh, 0, SEEK_SET, err) == -1)
if (wftap_dump_file_seek(wdh, 0, SEEK_SET, err) == -1)
return FALSE;
/* fill in the Info_Header */
@ -447,7 +449,7 @@ static gboolean _5views_dump_close(wtap_dumper *wdh, int *err)
file_hdr.TramesStockeesInFile = GUINT32_TO_LE(_5views->nframes);
/* Write the file header. */
if (!wtap_dump_file_write(wdh, &file_hdr, sizeof(t_5VW_Capture_Header),
if (!wftap_dump_file_write(wdh, &file_hdr, sizeof(t_5VW_Capture_Header),
err))
return FALSE;

View File

@ -23,8 +23,8 @@
#include <glib.h>
#include <wtap.h>
int _5views_open(wtap *wth, int *err, gchar **err_info);
gboolean _5views_dump_open(wtap_dumper *wdh, int *err);
int _5views_open(wftap *wfth, int *err, gchar **err_info);
gboolean _5views_dump_open(wftap_dumper *wdh, int *err);
int _5views_dump_can_write_encap(int encap);
#endif

View File

@ -51,8 +51,8 @@ set(CLEAN_FILES
libpcap.c
logcat.c
merge.c
mpeg.c
mime_file.c
mpeg.c
mp2t.c
netmon.c
netscaler.c

View File

@ -51,12 +51,12 @@ NONGENERATED_C_FILES = \
ipfix.c \
iptrace.c \
iseries.c \
mime_file.c \
k12.c \
lanalyzer.c \
logcat.c \
libpcap.c \
merge.c \
mime_file.c \
mpeg.c \
mp2t.c \
netmon.c \
@ -69,8 +69,8 @@ NONGENERATED_C_FILES = \
packetlogger.c \
pcap-common.c \
pcapng.c \
peekclassic.c \
peektagged.c \
peekclassic.c \
peektagged.c \
pppdump.c \
radcom.c \
snoop.c \
@ -79,7 +79,7 @@ NONGENERATED_C_FILES = \
toshiba.c \
visual.c \
vms.c \
vwr.c \
vwr.c \
wtap.c
# Header files that are not generated from other files
@ -128,7 +128,7 @@ NONGENERATED_HEADER_FILES = \
pcap-common.h \
pcap-encap.h \
pcapng.h \
peekclassic.h \
peekclassic.h \
peektagged.h \
pppdump.h \
radcom.h \
@ -138,7 +138,8 @@ NONGENERATED_HEADER_FILES = \
toshiba.h \
visual.h \
vms.h \
vwr.h \
vwr.h \
wftap-int.h \
wtap.h \
wtap-int.h

View File

@ -21,6 +21,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"
@ -112,14 +113,14 @@ typedef struct {
time_t start;
} aethra_t;
static gboolean aethra_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean aethra_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
static gboolean aethra_read_rec_header(wtap *wth, FILE_T fh, struct aethrarec_hdr *hdr,
struct wtap_pkthdr *phdr, int *err, gchar **err_info);
static gboolean aethra_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean aethra_seek_read(wftap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
static gboolean aethra_read_rec_header(wftap *wth, FILE_T fh, struct aethrarec_hdr *hdr,
struct wtap_pkthdr *phdr, int *err, gchar **err_info);
int aethra_open(wtap *wth, int *err, gchar **err_info)
int aethra_open(wftap *wfth, int *err, gchar **err_info)
{
int bytes_read;
struct aethra_hdr hdr;
@ -128,9 +129,9 @@ int aethra_open(wtap *wth, int *err, gchar **err_info)
/* Read in the string that should be at the start of a "aethra" file */
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(hdr.magic, sizeof hdr.magic, wth->fh);
bytes_read = file_read(hdr.magic, sizeof hdr.magic, wfth->fh);
if (bytes_read != sizeof hdr.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;
@ -142,18 +143,18 @@ int aethra_open(wtap *wth, int *err, gchar **err_info)
/* Read the rest of the header. */
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read((char *)&hdr + sizeof hdr.magic,
sizeof hdr - sizeof hdr.magic, wth->fh);
sizeof hdr - sizeof hdr.magic, wfth->fh);
if (bytes_read != sizeof hdr - sizeof hdr.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;
}
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_AETHRA;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_AETHRA;
aethra = (aethra_t *)g_malloc(sizeof(aethra_t));
wth->priv = (void *)aethra;
wth->subtype_read = aethra_read;
wth->subtype_seek_read = aethra_seek_read;
wfth->priv = (void *)aethra;
wfth->subtype_read = aethra_read;
wfth->subtype_seek_read = aethra_seek_read;
/*
* Convert the time stamp to a "time_t".
@ -171,9 +172,9 @@ int aethra_open(wtap *wth, int *err, gchar **err_info)
* We've only seen ISDN files, so, for now, we treat all
* files as ISDN.
*/
wth->file_encap = WTAP_ENCAP_ISDN;
wth->snapshot_length = 0; /* not available in header */
wth->tsprecision = WTAP_FILE_TSPREC_MSEC;
wfth->file_encap = WTAP_ENCAP_ISDN;
wfth->snapshot_length = 0; /* not available in header */
wfth->tsprecision = WTAP_FILE_TSPREC_MSEC;
return 1;
}
@ -182,20 +183,21 @@ static guint packet = 0;
#endif
/* Read the next packet */
static gboolean aethra_read(wtap *wth, int *err, gchar **err_info,
static gboolean aethra_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset)
{
struct aethrarec_hdr hdr;
wtap* wth = (wtap*)wfth->tap_specific_data;
/*
* Keep reading until we see an AETHRA_ISDN_LINK with a subtype
* of AETHRA_ISDN_LINK_LAPD record or get an end-of-file.
*/
for (;;) {
*data_offset = file_tell(wth->fh);
*data_offset = file_tell(wfth->fh);
/* Read record header. */
if (!aethra_read_rec_header(wth, wth->fh, &hdr, &wth->phdr, err, err_info))
if (!aethra_read_rec_header(wfth, wfth->fh, &hdr, &wth->phdr, err, err_info))
return FALSE;
/*
@ -203,7 +205,7 @@ static gboolean aethra_read(wtap *wth, int *err, gchar **err_info,
* growing the buffer to handle it.
*/
if (wth->phdr.caplen != 0) {
if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
if (!wtap_read_packet_bytes(wfth->fh, wfth->frame_buffer,
wth->phdr.caplen, err, err_info))
return FALSE; /* Read error */
}
@ -274,15 +276,15 @@ found:
}
static gboolean
aethra_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
aethra_seek_read(wftap *wfth, gint64 seek_off, struct wtap_pkthdr *phdr,
Buffer *buf, int *err, gchar **err_info)
{
struct aethrarec_hdr hdr;
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 (!aethra_read_rec_header(wth, wth->random_fh, &hdr, phdr, err,
if (!aethra_read_rec_header(wfth, wfth->random_fh, &hdr, phdr, err,
err_info)) {
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
@ -292,17 +294,17 @@ aethra_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
/*
* Read the packet data.
*/
if (!wtap_read_packet_bytes(wth->random_fh, buf, phdr->caplen, err, err_info))
if (!wtap_read_packet_bytes(wfth->random_fh, buf, phdr->caplen, err, err_info))
return FALSE; /* failed */
return TRUE;
}
static gboolean
aethra_read_rec_header(wtap *wth, FILE_T fh, struct aethrarec_hdr *hdr,
aethra_read_rec_header(wftap *wfth, FILE_T fh, struct aethrarec_hdr *hdr,
struct wtap_pkthdr *phdr, int *err, gchar **err_info)
{
aethra_t *aethra = (aethra_t *)wth->priv;
aethra_t *aethra = (aethra_t *)wfth->priv;
int bytes_read;
guint32 rec_size;
guint32 packet_size;

View File

@ -24,6 +24,6 @@
#include <glib.h>
#include <wtap.h>
int aethra_open(wtap *wth, int *err, gchar **err_info);
int aethra_open(wftap *wfth, int *err, gchar **err_info);
#endif

View File

@ -19,6 +19,7 @@
*/
#include "config.h"
#include "wftap-int.h"
#include "wtap-int.h"
#include "buffer.h"
#include "ascendtext.h"
@ -74,26 +75,27 @@ static const ascend_magic_string ascend_magic[] = {
{ ASCEND_PFX_ETHER, "ETHER" },
};
static gboolean ascend_read(wtap *wth, int *err, gchar **err_info,
static gboolean ascend_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean ascend_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf,
static gboolean ascend_seek_read(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf,
int *err, gchar **err_info);
/* Seeks to the beginning of the next packet, and returns the
byte offset at which the header for that packet begins.
Returns -1 on failure. */
static gint64 ascend_seek(wtap *wth, int *err, gchar **err_info)
static gint64 ascend_seek(wftap *wfth, int *err, gchar **err_info)
{
int byte;
gint64 date_off = -1, cur_off, packet_off;
size_t string_level[ASCEND_MAGIC_STRINGS];
guint string_i = 0, type = 0;
guint excessive_read_count = 262144;
wtap* wth = (wtap*)wfth->tap_specific_data;
memset(&string_level, 0, sizeof(string_level));
while (((byte = file_getc(wth->fh)) != EOF)) {
while (((byte = file_getc(wfth->fh)) != EOF)) {
excessive_read_count--;
if (!excessive_read_count) {
@ -108,16 +110,16 @@ static gint64 ascend_seek(wtap *wth, int *err, gchar **err_info)
if (byte == *(strptr + string_level[string_i])) {
string_level[string_i]++;
if (string_level[string_i] >= len) {
cur_off = file_tell(wth->fh);
cur_off = file_tell(wfth->fh);
if (cur_off == -1) {
/* Error. */
*err = file_error(wth->fh, err_info);
*err = file_error(wfth->fh, err_info);
return -1;
}
/* Date: header is a special case. Remember the offset,
but keep looking for other headers. */
if (strcmp(strptr, ASCEND_DATE) == 0) {
if (strcmp(strptr, ASCEND_DATE) == 0) {
date_off = cur_off - len;
} else {
if (date_off == -1) {
@ -140,7 +142,7 @@ static gint64 ascend_seek(wtap *wth, int *err, gchar **err_info)
}
}
*err = file_error(wth->fh, err_info);
*err = file_error(wfth->fh, err_info);
return -1;
found:
@ -148,7 +150,7 @@ found:
* Move to where the read for this packet should start, and return
* that seek offset.
*/
if (file_seek(wth->fh, packet_off, SEEK_SET, err) == -1)
if (file_seek(wfth->fh, packet_off, SEEK_SET, err) == -1)
return -1;
wth->phdr.pseudo_header.ascend.type = type;
@ -156,18 +158,19 @@ found:
return packet_off;
}
int ascend_open(wtap *wth, int *err, gchar **err_info)
int ascend_open(wftap *wfth, int *err, gchar **err_info)
{
gint64 offset;
ws_statb64 statbuf;
ascend_t *ascend;
wtap* wth = (wtap*)wfth->tap_specific_data;
/* We haven't yet allocated a data structure for our private stuff;
set the pointer to null, so that "ascend_seek()" knows not to
fill it in. */
wth->priv = NULL;
wfth->priv = NULL;
offset = ascend_seek(wth, err, err_info);
offset = ascend_seek(wfth, err, err_info);
if (offset == -1) {
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
return -1;
@ -176,31 +179,31 @@ int ascend_open(wtap *wth, int *err, gchar **err_info)
/* Do a trial parse of the first packet just found to see if we might really have an Ascend file */
init_parse_ascend();
if (!check_ascend(wth->fh, &wth->phdr)) {
if (!check_ascend(wfth->fh, &wth->phdr)) {
return 0;
}
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_ASCEND;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_ASCEND;
switch(wth->phdr.pseudo_header.ascend.type) {
case ASCEND_PFX_ISDN_X:
case ASCEND_PFX_ISDN_R:
wth->file_encap = WTAP_ENCAP_ISDN;
wfth->file_encap = WTAP_ENCAP_ISDN;
break;
case ASCEND_PFX_ETHER:
wth->file_encap = WTAP_ENCAP_ETHERNET;
wfth->file_encap = WTAP_ENCAP_ETHERNET;
break;
default:
wth->file_encap = WTAP_ENCAP_ASCEND;
wfth->file_encap = WTAP_ENCAP_ASCEND;
}
wth->snapshot_length = ASCEND_MAX_PKT_LEN;
wth->subtype_read = ascend_read;
wth->subtype_seek_read = ascend_seek_read;
wfth->snapshot_length = ASCEND_MAX_PKT_LEN;
wfth->subtype_read = ascend_read;
wfth->subtype_seek_read = ascend_seek_read;
ascend = (ascend_t *)g_malloc(sizeof(ascend_t));
wth->priv = (void *)ascend;
wfth->priv = (void *)ascend;
/* The first packet we want to read is the one that "ascend_seek()"
just found; start searching for it at the offset at which it
@ -212,12 +215,12 @@ 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 (wtap_fstat(wth, &statbuf, err) == -1) {
if (wftap_fstat(wfth, &statbuf, err) == -1) {
return -1;
}
ascend->inittime = statbuf.st_ctime;
ascend->adjusted = FALSE;
wth->tsprecision = WTAP_FILE_TSPREC_USEC;
wfth->tsprecision = WTAP_FILE_TSPREC_USEC;
init_parse_ascend();
@ -225,25 +228,26 @@ int ascend_open(wtap *wth, int *err, gchar **err_info)
}
/* Read the next packet; called from wtap_read(). */
static gboolean ascend_read(wtap *wth, int *err, gchar **err_info,
static gboolean ascend_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset)
{
ascend_t *ascend = (ascend_t *)wth->priv;
ascend_t *ascend = (ascend_t *)wfth->priv;
gint64 offset;
wtap* wth = (wtap*)wfth->tap_specific_data;
/* parse_ascend() will advance the point at which to look for the next
packet's header, to just after the last packet's header (ie. at the
start of the last packet's data). We have to get past the last
packet's header because we might mistake part of it for a new header. */
if (file_seek(wth->fh, ascend->next_packet_seek_start,
if (file_seek(wfth->fh, ascend->next_packet_seek_start,
SEEK_SET, err) == -1)
return FALSE;
offset = ascend_seek(wth, err, err_info);
offset = ascend_seek(wfth, err, err_info);
if (offset == -1)
return FALSE;
if (parse_ascend(ascend, wth->fh, &wth->phdr, wth->frame_buffer,
wth->snapshot_length) != PARSED_RECORD) {
if (parse_ascend(ascend, wfth->fh, &wth->phdr, wfth->frame_buffer,
wfth->snapshot_length) != PARSED_RECORD) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup((ascend_parse_error != NULL) ? ascend_parse_error : "parse error");
return FALSE;
@ -253,16 +257,17 @@ static gboolean ascend_read(wtap *wth, int *err, gchar **err_info,
return TRUE;
}
static gboolean ascend_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf,
static gboolean ascend_seek_read(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf,
int *err, gchar **err_info)
{
ascend_t *ascend = (ascend_t *)wth->priv;
ascend_t *ascend = (ascend_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 (parse_ascend(ascend, wth->random_fh, phdr, buf,
wth->snapshot_length) != PARSED_RECORD) {
if (parse_ascend(ascend, wfth->random_fh, phdr, buf,
wfth->snapshot_length) != PARSED_RECORD) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup((ascend_parse_error != NULL) ? ascend_parse_error : "parse error");
return FALSE;

View File

@ -27,6 +27,6 @@
#define ASCEND_MAX_DATA_COLS 16
#define ASCEND_MAX_PKT_LEN (ASCEND_MAX_DATA_ROWS * ASCEND_MAX_DATA_COLS)
int ascend_open(wtap *wth, int *err, gchar **err_info);
int ascend_open(wftap *wfth, int *err, gchar **err_info);
#endif

View File

@ -25,6 +25,7 @@
#include <sys/stat.h>
#endif
#include "wftap-int.h"
#include "wtap-int.h"
#include "file_wrappers.h"
#include "buffer.h"
@ -38,13 +39,13 @@
#define BER_UNI_TAG_SEQ 16 /* SEQUENCE, SEQUENCE OF */
#define BER_UNI_TAG_SET 17 /* SET, SET OF */
static gboolean ber_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
static gboolean ber_read_file(wftap *wfth, FILE_T fh, struct wtap_pkthdr *phdr,
Buffer *buf, int *err, gchar **err_info)
{
gint64 file_size;
int packet_size;
if ((file_size = wtap_file_size(wth, err)) == -1)
if ((file_size = wftap_file_size(wfth, err)) == -1)
return FALSE;
if (file_size > WTAP_MAX_PACKET_SIZE) {
@ -54,7 +55,7 @@ static gboolean ber_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
*/
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("ber: File has %" G_GINT64_MODIFIER "d-byte packet, bigger than maximum of %u",
file_size, WTAP_MAX_PACKET_SIZE);
file_size, WTAP_MAX_PACKET_SIZE);
return FALSE;
}
packet_size = (int)file_size;
@ -70,13 +71,14 @@ static gboolean ber_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
return wtap_read_packet_bytes(fh, buf, packet_size, err, err_info);
}
static gboolean ber_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
static gboolean ber_read(wftap *wfth, int *err, gchar **err_info, gint64 *data_offset)
{
gint64 offset;
wtap* wth = (wtap*)wfth->tap_specific_data;
*err = 0;
offset = file_tell(wth->fh);
offset = file_tell(wfth->fh);
/* there is only ever one packet */
if (offset != 0)
@ -84,25 +86,27 @@ static gboolean ber_read(wtap *wth, int *err, gchar **err_info, gint64 *data_off
*data_offset = offset;
return ber_read_file(wth, wth->fh, &wth->phdr, wth->frame_buffer, err, err_info);
return ber_read_file(wfth, wfth->fh, &wth->phdr, wfth->frame_buffer, err, err_info);
}
static gboolean ber_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr _U_,
Buffer *buf, int *err, gchar **err_info)
static gboolean ber_seek_read(wftap *wfth, gint64 seek_off, void* header,
Buffer *buf, int *err, gchar **err_info)
{
struct wtap_pkthdr *phdr = (struct wtap_pkthdr*)header;
/* there is only one packet */
if(seek_off > 0) {
*err = 0;
return FALSE;
}
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;
return ber_read_file(wth, wth->random_fh, phdr, buf, err, err_info);
return ber_read_file(wfth, wfth->random_fh, phdr, buf, err, err_info);
}
int ber_open(wtap *wth, int *err, gchar **err_info)
int ber_open(wftap *wfth, int *err, gchar **err_info)
{
#define BER_BYTES_TO_CHECK 8
guint8 bytes[BER_BYTES_TO_CHECK];
@ -116,9 +120,9 @@ int ber_open(wtap *wth, int *err, gchar **err_info)
gint64 file_size;
int offset = 0, i;
bytes_read = file_read(&bytes, BER_BYTES_TO_CHECK, wth->fh);
bytes_read = file_read(&bytes, BER_BYTES_TO_CHECK, wfth->fh);
if (bytes_read != BER_BYTES_TO_CHECK) {
*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;
@ -161,7 +165,7 @@ int ber_open(wtap *wth, int *err, gchar **err_info)
}
len += (2 + nlb); /* add back Tag and Length bytes */
file_size = wtap_file_size(wth, err);
file_size = wftap_file_size(wfth, err);
if(len != file_size) {
return 0; /* not ASN.1 */
@ -171,16 +175,16 @@ int ber_open(wtap *wth, int *err, gchar **err_info)
}
/* seek back to the start of the file */
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
if (file_seek(wfth->fh, 0, SEEK_SET, err) == -1)
return -1;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_BER;
wth->file_encap = WTAP_ENCAP_BER;
wth->snapshot_length = 0;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_BER;
wfth->file_encap = WTAP_ENCAP_BER;
wfth->snapshot_length = 0;
wth->subtype_read = ber_read;
wth->subtype_seek_read = ber_seek_read;
wth->tsprecision = WTAP_FILE_TSPREC_SEC;
wfth->subtype_read = ber_read;
wfth->subtype_seek_read = ber_seek_read;
wfth->tsprecision = WTAP_FILE_TSPREC_SEC;
return 1;
}

View File

@ -23,6 +23,6 @@
#include <glib.h>
#include "ws_symbol_export.h"
int ber_open(wtap *wth, int *err, gchar **err_info);
int ber_open(wftap *wfth, int *err, gchar **err_info);
#endif

View File

@ -21,6 +21,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"
@ -73,14 +74,14 @@ struct btsnooprec_hdr {
static const gint64 KUnixTimeBase = G_GINT64_CONSTANT(0x00dcddb30f2f8000); /* offset from symbian - unix time */
static gboolean btsnoop_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
static gboolean btsnoop_read_record(wtap *wth, FILE_T fh,
static gboolean btsnoop_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean btsnoop_seek_read(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info);
static gboolean btsnoop_read_record(wftap *wfth, FILE_T fh,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
int btsnoop_open(wtap *wth, int *err, gchar **err_info)
int btsnoop_open(wftap *wfth, int *err, gchar **err_info)
{
int bytes_read;
char magic[sizeof btsnoop_magic];
@ -90,9 +91,9 @@ int btsnoop_open(wtap *wth, int *err, gchar **err_info)
/* Read in the string that should be at the start of a "btsnoop" 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;
@ -104,9 +105,9 @@ int btsnoop_open(wtap *wth, int *err, gchar **err_info)
/* Read the rest of the header. */
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(&hdr, sizeof hdr, wth->fh);
bytes_read = file_read(&hdr, sizeof hdr, wfth->fh);
if (bytes_read != sizeof 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;
@ -151,34 +152,36 @@ int btsnoop_open(wtap *wth, int *err, gchar **err_info)
return -1;
}
wth->subtype_read = btsnoop_read;
wth->subtype_seek_read = btsnoop_seek_read;
wth->file_encap = file_encap;
wth->snapshot_length = 0; /* not available in header */
wth->tsprecision = WTAP_FILE_TSPREC_USEC;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_BTSNOOP;
wfth->subtype_read = btsnoop_read;
wfth->subtype_seek_read = btsnoop_seek_read;
wfth->file_encap = file_encap;
wfth->snapshot_length = 0; /* not available in header */
wfth->tsprecision = WTAP_FILE_TSPREC_USEC;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_BTSNOOP;
return 1;
}
static gboolean btsnoop_read(wtap *wth, int *err, gchar **err_info,
static gboolean btsnoop_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset)
{
*data_offset = file_tell(wth->fh);
wtap* wth = (wtap*)wfth->tap_specific_data;
*data_offset = file_tell(wfth->fh);
return btsnoop_read_record(wth, wth->fh, &wth->phdr, wth->frame_buffer,
return btsnoop_read_record(wfth, wfth->fh, &wth->phdr, wfth->frame_buffer,
err, err_info);
}
static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
static gboolean btsnoop_seek_read(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
struct wtap_pkthdr *phdr = (struct wtap_pkthdr *)header;
if (file_seek(wfth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
return btsnoop_read_record(wth, wth->random_fh, phdr, buf, err, err_info);
return btsnoop_read_record(wfth, wfth->random_fh, phdr, buf, err, err_info);
}
static gboolean btsnoop_read_record(wtap *wth, FILE_T fh,
static gboolean btsnoop_read_record(wftap *wfth, FILE_T fh,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
{
int bytes_read;
@ -221,10 +224,12 @@ static gboolean btsnoop_read_record(wtap *wth, FILE_T fh,
phdr->ts.nsecs = (guint)((ts % 1000000) * 1000);
phdr->caplen = packet_size;
phdr->len = orig_size;
if(wth->file_encap == WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR)
switch(wfth->file_encap)
{
case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
phdr->pseudo_header.p2p.sent = (flags & KHciLoggerControllerToHost) ? FALSE : TRUE;
} else if(wth->file_encap == WTAP_ENCAP_BLUETOOTH_HCI) {
break;
case WTAP_ENCAP_BLUETOOTH_HCI:
phdr->pseudo_header.bthci.sent = (flags & KHciLoggerControllerToHost) ? FALSE : TRUE;
if(flags & KHciLoggerCommandOrEvent)
{
@ -241,12 +246,13 @@ static gboolean btsnoop_read_record(wtap *wth, FILE_T fh,
{
phdr->pseudo_header.bthci.channel = BTHCI_CHANNEL_ACL;
}
} else if (wth->file_encap == WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR) {
break;
case WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR:
phdr->pseudo_header.btmon.opcode = flags & 0xFFFF;
phdr->pseudo_header.btmon.adapter_id = flags >> 16;
break;
}
/* Read packet data. */
return wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info);
}
@ -297,7 +303,7 @@ static guint8 btsnoop_lookup_flags(guint8 hci_type, gboolean sent, guint8 *flags
return FALSE;
}
static gboolean btsnoop_dump_partial_rec_hdr(wtap_dumper *wdh _U_,
static gboolean btsnoop_dump_partial_rec_hdr(wftap_dumper *wdh _U_,
const struct wtap_pkthdr *phdr,
const union wtap_pseudo_header *pseudo_header,
const guint8 *pd, int *err,
@ -324,10 +330,10 @@ static gboolean btsnoop_dump_partial_rec_hdr(wtap_dumper *wdh _U_,
}
/* FIXME: How do we support multiple backends?*/
static gboolean btsnoop_dump_h1(wtap_dumper *wdh,
const struct wtap_pkthdr *phdr,
static gboolean btsnoop_dump_h1(wftap_dumper *wdh, void* header,
const guint8 *pd, int *err)
{
const struct wtap_pkthdr *phdr = (const struct wtap_pkthdr *)header;
const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header;
struct btsnooprec_hdr rec_hdr;
@ -346,7 +352,7 @@ static gboolean btsnoop_dump_h1(wtap_dumper *wdh,
rec_hdr.incl_len = GUINT32_TO_BE(phdr->caplen-1);
rec_hdr.orig_len = GUINT32_TO_BE(phdr->len-1);
if (!wtap_dump_file_write(wdh, &rec_hdr, sizeof rec_hdr, err))
if (!wftap_dump_file_write(wdh, &rec_hdr, sizeof rec_hdr, err))
return FALSE;
wdh->bytes_dumped += sizeof rec_hdr;
@ -354,7 +360,7 @@ static gboolean btsnoop_dump_h1(wtap_dumper *wdh,
/* Skip HCI packet type */
++pd;
if (!wtap_dump_file_write(wdh, pd, phdr->caplen-1, err))
if (!wftap_dump_file_write(wdh, pd, phdr->caplen-1, err))
return FALSE;
wdh->bytes_dumped += phdr->caplen-1;
@ -362,7 +368,7 @@ static gboolean btsnoop_dump_h1(wtap_dumper *wdh,
return TRUE;
}
static gboolean btsnoop_dump_h4(wtap_dumper *wdh,
static gboolean btsnoop_dump_h4(wftap_dumper *wdh,
const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err)
{
@ -381,12 +387,12 @@ static gboolean btsnoop_dump_h4(wtap_dumper *wdh,
rec_hdr.incl_len = GUINT32_TO_BE(phdr->caplen);
rec_hdr.orig_len = GUINT32_TO_BE(phdr->len);
if (!wtap_dump_file_write(wdh, &rec_hdr, sizeof rec_hdr, err))
if (!wftap_dump_file_write(wdh, &rec_hdr, sizeof rec_hdr, err))
return FALSE;
wdh->bytes_dumped += sizeof rec_hdr;
if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err))
if (!wftap_dump_file_write(wdh, pd, phdr->caplen, err))
return FALSE;
wdh->bytes_dumped += phdr->caplen;
@ -395,7 +401,7 @@ static gboolean btsnoop_dump_h4(wtap_dumper *wdh,
}
/* FIXME: How do we support multiple backends?*/
gboolean btsnoop_dump_open_h1(wtap_dumper *wdh, int *err)
gboolean btsnoop_dump_open_h1(wftap_dumper *wdh, int *err)
{
struct btsnoop_hdr file_hdr;
@ -417,7 +423,7 @@ gboolean btsnoop_dump_open_h1(wtap_dumper *wdh, int *err)
return FALSE;
}
if (!wtap_dump_file_write(wdh, btsnoop_magic, sizeof btsnoop_magic, err))
if (!wftap_dump_file_write(wdh, btsnoop_magic, sizeof btsnoop_magic, err))
return FALSE;
wdh->bytes_dumped += sizeof btsnoop_magic;
@ -427,7 +433,7 @@ gboolean btsnoop_dump_open_h1(wtap_dumper *wdh, int *err)
/* HCI type encoded in first byte */
file_hdr.datalink = GUINT32_TO_BE(KHciLoggerDatalinkTypeH1);
if (!wtap_dump_file_write(wdh, &file_hdr, sizeof file_hdr, err))
if (!wftap_dump_file_write(wdh, &file_hdr, sizeof file_hdr, err))
return FALSE;
wdh->bytes_dumped += sizeof file_hdr;
@ -437,7 +443,7 @@ gboolean btsnoop_dump_open_h1(wtap_dumper *wdh, int *err)
/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on
failure */
gboolean btsnoop_dump_open_h4(wtap_dumper *wdh, int *err)
gboolean btsnoop_dump_open_h4(wftap_dumper *wdh, int *err)
{
struct btsnoop_hdr file_hdr;
@ -459,7 +465,7 @@ gboolean btsnoop_dump_open_h4(wtap_dumper *wdh, int *err)
return FALSE;
}
if (!wtap_dump_file_write(wdh, btsnoop_magic, sizeof btsnoop_magic, err))
if (!wftap_dump_file_write(wdh, btsnoop_magic, sizeof btsnoop_magic, err))
return FALSE;
wdh->bytes_dumped += sizeof btsnoop_magic;
@ -469,7 +475,7 @@ gboolean btsnoop_dump_open_h4(wtap_dumper *wdh, int *err)
/* HCI type encoded in first byte */
file_hdr.datalink = GUINT32_TO_BE(KHciLoggerDatalinkTypeH4);
if (!wtap_dump_file_write(wdh, &file_hdr, sizeof file_hdr, err))
if (!wftap_dump_file_write(wdh, &file_hdr, sizeof file_hdr, err))
return FALSE;
wdh->bytes_dumped += sizeof file_hdr;

View File

@ -23,9 +23,9 @@
#include <glib.h>
#include "ws_symbol_export.h"
int btsnoop_open(wtap *wth, int *err, gchar **err_info);
gboolean btsnoop_dump_open_h1(wtap_dumper *wdh, int *err);
gboolean btsnoop_dump_open_h4(wtap_dumper *wdh, int *err);
int btsnoop_open(wftap *wfth, int *err, gchar **err_info);
gboolean btsnoop_dump_open_h1(wftap_dumper *wfdh, int *err);
gboolean btsnoop_dump_open_h4(wftap_dumper *wfdh, int *err);
int btsnoop_dump_can_write_encap(int encap);
#endif

View File

@ -62,6 +62,7 @@
#include <string.h>
#include <glib.h>
#include <wtap.h>
#include <wftap-int.h>
#include <wtap-int.h>
#include <file_wrappers.h>
#include <buffer.h>
@ -297,28 +298,29 @@ camins_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
static gboolean
camins_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
camins_read(wftap *wfth, int *err, gchar **err_info, gint64 *data_offset)
{
*data_offset = file_tell(wth->fh);
wtap* wth = (wtap*)wfth->tap_specific_data;
*data_offset = file_tell(wfth->fh);
return camins_read_packet(wth->fh, &wth->phdr, wth->frame_buffer, err,
err_info);
return camins_read_packet(wfth->fh, &wth->phdr, wfth->frame_buffer, err,
err_info);
}
static gboolean
camins_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *pkthdr, Buffer *buf, int *err, gchar **err_info)
camins_seek_read(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info)
{
if (-1 == file_seek(wth->random_fh, seek_off, SEEK_SET, err))
struct wtap_pkthdr *pkthdr = (struct wtap_pkthdr *)header;
if (-1 == file_seek(wfth->random_fh, seek_off, SEEK_SET, err))
return FALSE;
return camins_read_packet(wth->random_fh, pkthdr, buf, err, err_info);
return camins_read_packet(wfth->random_fh, pkthdr, buf, err, err_info);
}
int camins_open(wtap *wth, int *err, gchar **err_info _U_)
int camins_open(wftap *wfth, int *err, gchar **err_info _U_)
{
guint8 found_start_blocks = 0;
guint8 count = 0;
@ -328,7 +330,7 @@ int camins_open(wtap *wth, int *err, gchar **err_info _U_)
/* all CAM Inspector files I've looked at have at least two blocks of
0x00 0xE1 within the first 20 bytes */
do {
bytes_read = file_read(block, sizeof(block), wth->fh);
bytes_read = file_read(block, sizeof(block), wfth->fh);
if (bytes_read != sizeof(block))
break;
@ -342,18 +344,18 @@ int camins_open(wtap *wth, int *err, gchar **err_info _U_)
return 0; /* no CAM Inspector file */
/* rewind the fh so we re-read from the beginning */
if (-1 == file_seek(wth->fh, 0, SEEK_SET, err))
if (-1 == file_seek(wfth->fh, 0, SEEK_SET, err))
return -1;
wth->file_encap = WTAP_ENCAP_DVBCI;
wth->snapshot_length = 0;
wth->tsprecision = WTAP_FILE_TSPREC_MSEC;
wfth->file_encap = WTAP_ENCAP_DVBCI;
wfth->snapshot_length = 0;
wfth->tsprecision = WTAP_FILE_TSPREC_MSEC;
wth->priv = NULL;
wfth->priv = NULL;
wth->subtype_read = camins_read;
wth->subtype_seek_read = camins_seek_read;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_CAMINS;
wfth->subtype_read = camins_read;
wfth->subtype_seek_read = camins_seek_read;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_CAMINS;
*err = 0;
return 1;

View File

@ -28,6 +28,6 @@
#include <glib.h>
#include <wiretap/wtap.h>
int camins_open(wtap *wth, int *err, gchar **err_info);
int camins_open(wftap *wfth, int *err, gchar **err_info);
#endif /* _CAMINS_H */

View File

@ -24,6 +24,7 @@
#include <stdlib.h>
#include <ctype.h>
#include "wftap-int.h"
#include "wtap-int.h"
#include "file_wrappers.h"
#include "buffer.h"
@ -103,15 +104,15 @@ static const gchar catapult_dct2000_magic[] = "Session Transcript";
/************************************************************/
/* Functions called from wiretap core */
static gboolean catapult_dct2000_read(wtap *wth, int *err, gchar **err_info,
static gboolean catapult_dct2000_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean catapult_dct2000_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr,
static gboolean catapult_dct2000_seek_read(wftap *wfth, gint64 seek_off,
void* header,
Buffer *buf, int *err,
gchar **err_info);
static void catapult_dct2000_close(wtap *wth);
static void catapult_dct2000_close(wftap *wfth);
static gboolean catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
static gboolean catapult_dct2000_dump(wftap_dumper *wdh, void* header,
const guint8 *pd, int *err);
@ -131,7 +132,7 @@ static gboolean parse_line(char *linebuff, gint line_length,
gchar *context_name, guint8 *context_portp,
gchar *protocol_name, gchar *variant_name,
gchar *outhdr_name);
static void process_parsed_line(wtap *wth,
static void process_parsed_line(wftap *wfth,
dct2000_file_externals_t *file_externals,
struct wtap_pkthdr *phdr,
Buffer *buf, gint64 file_offset,
@ -167,7 +168,7 @@ static gboolean free_line_prefix_info(gpointer key, gpointer value, gpointer use
/* Open file (for reading) */
/********************************************/
int
catapult_dct2000_open(wtap *wth, int *err, gchar **err_info)
catapult_dct2000_open(wftap *wfth, int *err, gchar **err_info)
{
gint64 offset = 0;
time_t timestamp;
@ -184,7 +185,7 @@ catapult_dct2000_open(wtap *wth, int *err, gchar **err_info)
/********************************************************************/
/* First line needs to contain at least as many characters as magic */
if (!read_new_line(wth->fh, &offset, &firstline_length, linebuff,
if (!read_new_line(wfth->fh, &offset, &firstline_length, linebuff,
sizeof linebuff, err, err_info)) {
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
return -1;
@ -223,7 +224,7 @@ catapult_dct2000_open(wtap *wth, int *err, gchar **err_info)
/* Second line contains file timestamp */
/* Store this offset in in file_externals */
if (!read_new_line(wth->fh, &offset, &(file_externals->secondline_length),
if (!read_new_line(wfth->fh, &offset, &(file_externals->secondline_length),
linebuff, sizeof linebuff, err, err_info)) {
g_free(file_externals);
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
@ -250,18 +251,18 @@ catapult_dct2000_open(wtap *wth, int *err, gchar **err_info)
/* File is for us. Fill in details so packets can be read */
/* Set our file type */
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_CATAPULT_DCT2000;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_CATAPULT_DCT2000;
/* Use our own encapsulation to send all packets to our stub dissector */
wth->file_encap = WTAP_ENCAP_CATAPULT_DCT2000;
wfth->file_encap = WTAP_ENCAP_CATAPULT_DCT2000;
/* Callbacks for reading operations */
wth->subtype_read = catapult_dct2000_read;
wth->subtype_seek_read = catapult_dct2000_seek_read;
wth->subtype_close = catapult_dct2000_close;
wfth->subtype_read = catapult_dct2000_read;
wfth->subtype_seek_read = catapult_dct2000_seek_read;
wfth->subtype_close = catapult_dct2000_close;
/* Choose microseconds (have 4 decimal places...) */
wth->tsprecision = WTAP_FILE_TSPREC_USEC;
wfth->tsprecision = WTAP_FILE_TSPREC_USEC;
/***************************************************************/
@ -270,7 +271,7 @@ catapult_dct2000_open(wtap *wth, int *err, gchar **err_info)
g_hash_table_new(packet_offset_hash_func, packet_offset_equal);
/* Set this wtap to point to the file_externals */
wth->priv = (void*)file_externals;
wfth->priv = (void*)file_externals;
*err = errno;
return 1;
@ -334,17 +335,18 @@ static void write_timestamp_string(char *timestamp_string, int secs, int tenthou
/* - return TRUE and details if found */
/**************************************************/
static gboolean
catapult_dct2000_read(wtap *wth, int *err, gchar **err_info,
catapult_dct2000_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset)
{
gint64 offset = file_tell(wth->fh);
gint64 offset = file_tell(wfth->fh);
long dollar_offset, before_time_offset, after_time_offset;
packet_direction_t direction;
int encap;
wtap* wth = (wtap*)wfth->tap_specific_data;
/* Get wtap external structure for this wtap */
dct2000_file_externals_t *file_externals =
(dct2000_file_externals_t*)wth->priv;
(dct2000_file_externals_t*)wfth->priv;
/* Search for a line containing a usable packet */
while (1) {
@ -361,13 +363,13 @@ catapult_dct2000_read(wtap *wth, int *err, gchar **err_info,
gchar outhdr_name[MAX_OUTHDR_NAME+1];
/* Are looking for first packet after 2nd line */
if (file_tell(wth->fh) == 0) {
if (file_tell(wfth->fh) == 0) {
this_offset += (file_externals->firstline_length+1+
file_externals->secondline_length+1);
}
/* Read a new line from file into linebuff */
if (!read_new_line(wth->fh, &offset, &line_length, linebuff,
if (!read_new_line(wfth->fh, &offset, &line_length, linebuff,
sizeof linebuff, err, err_info)) {
if (*err != 0)
return FALSE; /* error */
@ -394,9 +396,9 @@ catapult_dct2000_read(wtap *wth, int *err, gchar **err_info,
*/
*data_offset = this_offset;
process_parsed_line(wth, file_externals,
process_parsed_line(wfth, file_externals,
&wth->phdr,
wth->frame_buffer, this_offset,
wfth->frame_buffer, this_offset,
linebuff, dollar_offset,
seconds, useconds, timestamp_string,
direction, encap,
@ -447,8 +449,8 @@ catapult_dct2000_read(wtap *wth, int *err, gchar **err_info,
/* Read & seek function. */
/**************************************************/
static gboolean
catapult_dct2000_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf,
catapult_dct2000_seek_read(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf,
int *err, gchar **err_info)
{
gint64 offset = 0;
@ -466,21 +468,22 @@ catapult_dct2000_seek_read(wtap *wth, gint64 seek_off,
packet_direction_t direction;
int encap;
int seconds, useconds, data_chars;
struct wtap_pkthdr *phdr = (struct wtap_pkthdr *)header;
/* Get wtap external structure for this wtap */
dct2000_file_externals_t *file_externals =
(dct2000_file_externals_t*)wth->priv;
(dct2000_file_externals_t*)wfth->priv;
/* Reset errno */
*err = errno = 0;
/* Seek to beginning of packet */
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;
}
/* Re-read whole line (this really should succeed) */
if (!read_new_line(wth->random_fh, &offset, &length, linebuff,
if (!read_new_line(wfth->random_fh, &offset, &length, linebuff,
sizeof linebuff, err, err_info)) {
return FALSE;
}
@ -497,7 +500,7 @@ catapult_dct2000_seek_read(wtap *wth, gint64 seek_off,
write_timestamp_string(timestamp_string, seconds, useconds/100);
process_parsed_line(wth, file_externals,
process_parsed_line(wfth, file_externals,
phdr, buf, seek_off,
linebuff, dollar_offset,
seconds, useconds, timestamp_string,
@ -524,11 +527,11 @@ catapult_dct2000_seek_read(wtap *wth, gint64 seek_off,
/* Free dct2000-specific capture info from file that was open for reading */
/***************************************************************************/
static void
catapult_dct2000_close(wtap *wth)
catapult_dct2000_close(wftap *wfth)
{
/* Get externals for this file */
dct2000_file_externals_t *file_externals =
(dct2000_file_externals_t*)wth->priv;
(dct2000_file_externals_t*)wfth->priv;
/* Free up its line prefix values */
g_hash_table_foreach_remove(file_externals->packet_prefix_table,
@ -554,7 +557,7 @@ typedef struct {
/* Set other dump callbacks. */
/*****************************************************/
gboolean
catapult_dct2000_dump_open(wtap_dumper *wdh, int *err _U_)
catapult_dct2000_dump_open(wftap_dumper *wdh, int *err _U_)
{
/* Fill in other dump callbacks */
wdh->subtype_write = catapult_dct2000_dump;
@ -586,7 +589,7 @@ catapult_dct2000_dump_can_write_encap(int encap)
/*****************************************/
static gboolean
catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
catapult_dct2000_dump(wftap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err)
{
const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header;
@ -603,28 +606,28 @@ catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
/* Get the file_externals structure for this file */
/* Find wtap external structure for this wtap */
dct2000_file_externals_t *file_externals =
(dct2000_file_externals_t*)pseudo_header->dct2000.wth->priv;
(dct2000_file_externals_t*)pseudo_header->dct2000.wfth->priv;
dct2000 = (dct2000_dump_t *)wdh->priv;
if (dct2000 == NULL) {
/* Write out saved first line */
if (!wtap_dump_file_write(wdh, file_externals->firstline,
if (!wftap_dump_file_write(wdh, file_externals->firstline,
file_externals->firstline_length, err)) {
return FALSE;
}
if (!wtap_dump_file_write(wdh, "\n", 1, err)) {
if (!wftap_dump_file_write(wdh, "\n", 1, err)) {
return FALSE;
}
/* Also write out saved second line with timestamp corresponding to the
opening time of the log.
*/
if (!wtap_dump_file_write(wdh, file_externals->secondline,
if (!wftap_dump_file_write(wdh, file_externals->secondline,
file_externals->secondline_length, err)) {
return FALSE;
}
if (!wtap_dump_file_write(wdh, "\n", 1, err)) {
if (!wftap_dump_file_write(wdh, "\n", 1, err)) {
return FALSE;
}
@ -650,7 +653,7 @@ catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
(const void*)&(pseudo_header->dct2000.seek_off));
/* Write out text before timestamp */
if (!wtap_dump_file_write(wdh, prefix->before_time,
if (!wftap_dump_file_write(wdh, prefix->before_time,
strlen(prefix->before_time), err)) {
return FALSE;
}
@ -680,18 +683,18 @@ catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
}
/* Write out the calculated timestamp */
if (!wtap_dump_file_write(wdh, time_string, strlen(time_string), err)) {
if (!wftap_dump_file_write(wdh, time_string, strlen(time_string), err)) {
return FALSE;
}
/* Write out text between timestamp and start of hex data */
if (prefix->after_time == NULL) {
if (!wtap_dump_file_write(wdh, " l ", strlen(" l "), err)) {
if (!wftap_dump_file_write(wdh, " l ", strlen(" l "), err)) {
return FALSE;
}
}
else {
if (!wtap_dump_file_write(wdh, prefix->after_time,
if (!wftap_dump_file_write(wdh, prefix->after_time,
strlen(prefix->after_time), err)) {
return FALSE;
}
@ -733,7 +736,7 @@ catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
/**************************************/
/* Remainder is encapsulated protocol */
if (!wtap_dump_file_write(wdh, is_sprint ? " " : "$", 1, err)) {
if (!wftap_dump_file_write(wdh, is_sprint ? " " : "$", 1, err)) {
return FALSE;
}
@ -745,7 +748,7 @@ catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
c[1] = char_from_hex((guint8)(pd[n] & 0x0f));
/* Write both hex chars of byte together */
if (!wtap_dump_file_write(wdh, c, 2, err)) {
if (!wftap_dump_file_write(wdh, c, 2, err)) {
return FALSE;
}
}
@ -756,14 +759,14 @@ catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
c[0] = pd[n];
/* Write both hex chars of byte together */
if (!wtap_dump_file_write(wdh, c, 1, err)) {
if (!wftap_dump_file_write(wdh, c, 1, err)) {
return FALSE;
}
}
}
/* End the line */
if (!wtap_dump_file_write(wdh, "\n", 1, err)) {
if (!wftap_dump_file_write(wdh, "\n", 1, err)) {
return FALSE;
}
@ -1260,7 +1263,7 @@ parse_line(gchar *linebuff, gint line_length,
/* Process results of parse_line() */
/***********************************/
static void
process_parsed_line(wtap *wth, dct2000_file_externals_t *file_externals,
process_parsed_line(wftap *wfth, dct2000_file_externals_t *file_externals,
struct wtap_pkthdr *phdr,
Buffer *buf, gint64 file_offset,
char *linebuff, long dollar_offset,
@ -1361,7 +1364,7 @@ process_parsed_line(wtap *wth, dct2000_file_externals_t *file_externals,
/*****************************************/
/* Set packet pseudo-header if necessary */
phdr->pseudo_header.dct2000.seek_off = file_offset;
phdr->pseudo_header.dct2000.wth = wth;
phdr->pseudo_header.dct2000.wfth = wfth;
switch (encap) {
case WTAP_ENCAP_ATM_PDUS_UNTRUNCATED:

View File

@ -24,8 +24,8 @@
#include <glib.h>
#include "ws_symbol_export.h"
int catapult_dct2000_open(wtap *wth, int *err, gchar **err_info);
gboolean catapult_dct2000_dump_open(wtap_dumper *wdh, int *err);
int catapult_dct2000_open(wftap *wfth, int *err, gchar **err_info);
gboolean catapult_dct2000_dump_open(wftap_dumper *wdh, int *err);
int catapult_dct2000_dump_can_write_encap(int encap);
#define DCT2000_ENCAP_UNHANDLED 0

View File

@ -37,6 +37,7 @@
#include <string.h>
#include "wtap.h"
#include "wftap-int.h"
#include "wtap-int.h"
#include "buffer.h"
#include "file_wrappers.h"
@ -78,21 +79,20 @@ typedef struct commview_header {
#define MEDIUM_WIFI 1
#define MEDIUM_TOKEN_RING 2
static gboolean commview_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean commview_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr,
Buffer *buf, int *err, gchar **err_info);
static gboolean commview_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean commview_seek_read(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info);
static gboolean commview_read_header(commview_header_t *cv_hdr, FILE_T fh,
int *err, gchar **err_info);
static gboolean commview_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err);
int *err, gchar **err_info);
static gboolean commview_dump(wftap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err);
int commview_open(wtap *wth, int *err, gchar **err_info)
int commview_open(wftap *wfth, int *err, gchar **err_info)
{
commview_header_t cv_hdr;
if(!commview_read_header(&cv_hdr, wth->fh, err, err_info)) {
if(!commview_read_header(&cv_hdr, wfth->fh, err, err_info)) {
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
return -1;
return 0;
@ -114,16 +114,16 @@ int commview_open(wtap *wth, int *err, gchar **err_info)
return 0; /* Not our kind of file */
/* No file header. 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;
/* Set up the pointers to the handlers for this file type */
wth->subtype_read = commview_read;
wth->subtype_seek_read = commview_seek_read;
wfth->subtype_read = commview_read;
wfth->subtype_seek_read = commview_seek_read;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_COMMVIEW;
wth->file_encap = WTAP_ENCAP_PER_PACKET;
wth->tsprecision = WTAP_FILE_TSPREC_USEC;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_COMMVIEW;
wfth->file_encap = WTAP_ENCAP_PER_PACKET;
wfth->tsprecision = WTAP_FILE_TSPREC_USEC;
return 1; /* Our kind of file */
}
@ -185,22 +185,24 @@ commview_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
}
static gboolean
commview_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
commview_read(wftap *wfth, int *err, gchar **err_info, gint64 *data_offset)
{
*data_offset = file_tell(wth->fh);
wtap* wth = (wtap*)wfth->tap_specific_data;
*data_offset = file_tell(wfth->fh);
return commview_read_packet(wth->fh, &wth->phdr, wth->frame_buffer, err,
return commview_read_packet(wfth->fh, &wth->phdr, wfth->frame_buffer, err,
err_info);
}
static gboolean
commview_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
commview_seek_read(wftap *wfth, gint64 seek_off, void* header,
Buffer *buf, int *err, gchar **err_info)
{
if(file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
struct wtap_pkthdr *phdr = (struct wtap_pkthdr *)header;
if(file_seek(wfth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
return commview_read_packet(wth->random_fh, phdr, buf, err, err_info);
return commview_read_packet(wfth->random_fh, phdr, buf, err, err_info);
}
static gboolean
@ -255,7 +257,7 @@ int commview_dump_can_write_encap(int encap)
/* Returns TRUE on success, FALSE on failure;
sets "*err" to an error code on failure */
gboolean commview_dump_open(wtap_dumper *wdh, int *err _U_)
gboolean commview_dump_open(wftap_dumper *wdh, int *err _U_)
{
wdh->subtype_write = commview_dump;
wdh->subtype_close = NULL;
@ -268,7 +270,7 @@ gboolean commview_dump_open(wtap_dumper *wdh, int *err _U_)
/* Write a record for a packet to a dump file.
* Returns TRUE on success, FALSE on failure. */
static gboolean commview_dump(wtap_dumper *wdh,
static gboolean commview_dump(wftap_dumper *wdh,
const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err)
{
@ -326,45 +328,45 @@ static gboolean commview_dump(wtap_dumper *wdh,
return FALSE;
}
if (!wtap_dump_file_write(wdh, &cv_hdr.data_len, 2, err))
if (!wftap_dump_file_write(wdh, &cv_hdr.data_len, 2, err))
return FALSE;
if (!wtap_dump_file_write(wdh, &cv_hdr.source_data_len, 2, err))
if (!wftap_dump_file_write(wdh, &cv_hdr.source_data_len, 2, err))
return FALSE;
if (!wtap_dump_file_write(wdh, &cv_hdr.version, 1, err))
if (!wftap_dump_file_write(wdh, &cv_hdr.version, 1, err))
return FALSE;
if (!wtap_dump_file_write(wdh, &cv_hdr.year, 2, err))
if (!wftap_dump_file_write(wdh, &cv_hdr.year, 2, err))
return FALSE;
if (!wtap_dump_file_write(wdh, &cv_hdr.month, 1, err))
if (!wftap_dump_file_write(wdh, &cv_hdr.month, 1, err))
return FALSE;
if (!wtap_dump_file_write(wdh, &cv_hdr.day, 1, err))
if (!wftap_dump_file_write(wdh, &cv_hdr.day, 1, err))
return FALSE;
if (!wtap_dump_file_write(wdh, &cv_hdr.hours, 1, err))
if (!wftap_dump_file_write(wdh, &cv_hdr.hours, 1, err))
return FALSE;
if (!wtap_dump_file_write(wdh, &cv_hdr.minutes, 1, err))
if (!wftap_dump_file_write(wdh, &cv_hdr.minutes, 1, err))
return FALSE;
if (!wtap_dump_file_write(wdh, &cv_hdr.seconds, 1, err))
if (!wftap_dump_file_write(wdh, &cv_hdr.seconds, 1, err))
return FALSE;
if (!wtap_dump_file_write(wdh, &cv_hdr.usecs, 4, err))
if (!wftap_dump_file_write(wdh, &cv_hdr.usecs, 4, err))
return FALSE;
if (!wtap_dump_file_write(wdh, &cv_hdr.flags, 1, err))
if (!wftap_dump_file_write(wdh, &cv_hdr.flags, 1, err))
return FALSE;
if (!wtap_dump_file_write(wdh, &cv_hdr.signal_level_percent, 1, err))
if (!wftap_dump_file_write(wdh, &cv_hdr.signal_level_percent, 1, err))
return FALSE;
if (!wtap_dump_file_write(wdh, &cv_hdr.rate, 1, err))
if (!wftap_dump_file_write(wdh, &cv_hdr.rate, 1, err))
return FALSE;
if (!wtap_dump_file_write(wdh, &cv_hdr.band, 1, err))
if (!wftap_dump_file_write(wdh, &cv_hdr.band, 1, err))
return FALSE;
if (!wtap_dump_file_write(wdh, &cv_hdr.channel, 1, err))
if (!wftap_dump_file_write(wdh, &cv_hdr.channel, 1, err))
return FALSE;
if (!wtap_dump_file_write(wdh, &cv_hdr.direction, 1, err))
if (!wftap_dump_file_write(wdh, &cv_hdr.direction, 1, err))
return FALSE;
if (!wtap_dump_file_write(wdh, &cv_hdr.signal_level_dbm, 2, err))
if (!wftap_dump_file_write(wdh, &cv_hdr.signal_level_dbm, 2, err))
return FALSE;
if (!wtap_dump_file_write(wdh, &cv_hdr.noise_level, 2, err))
if (!wftap_dump_file_write(wdh, &cv_hdr.noise_level, 2, err))
return FALSE;
wdh->bytes_dumped += COMMVIEW_HEADER_SIZE;
if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err))
if (!wftap_dump_file_write(wdh, pd, phdr->caplen, err))
return FALSE;
wdh->bytes_dumped += phdr->caplen;

View File

@ -25,9 +25,9 @@
#include <glib.h>
#include "ws_symbol_export.h"
int commview_open(wtap *wth, int *err, gchar **err_info _U_);
int commview_open(wftap *wfth, int *err, gchar **err_info _U_);
int commview_dump_can_write_encap(int encap);
gboolean commview_dump_open(wtap_dumper *wdh, int *err);
gboolean commview_dump_open(wftap_dumper *wdh, int *err);
#endif /* __COMMVIEW_H__ */

View File

@ -22,6 +22,7 @@
*/
#include "config.h"
#include "wftap-int.h"
#include "wtap-int.h"
#include "buffer.h"
#include "cosine.h"
@ -163,13 +164,13 @@
#define COSINE_MAX_PACKET_LEN 65536
static gboolean empty_line(const gchar *line);
static gint64 cosine_seek_next_packet(wtap *wth, int *err, gchar **err_info,
static gint64 cosine_seek_next_packet(wftap *wfth, int *err, gchar **err_info,
char *hdr);
static gboolean cosine_check_file_type(wtap *wth, int *err, gchar **err_info);
static gboolean cosine_read(wtap *wth, int *err, gchar **err_info,
static gboolean cosine_check_file_type(wftap *wfth, int *err, gchar **err_info);
static gboolean cosine_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean cosine_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
static gboolean cosine_seek_read(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info);
static int parse_cosine_rec_hdr(struct wtap_pkthdr *phdr, const char *line,
int *err, gchar **err_info);
static gboolean parse_cosine_hex_dump(FILE_T fh, struct wtap_pkthdr *phdr,
@ -199,21 +200,21 @@ static gboolean empty_line(const gchar *line)
byte offset. Copy the header line to hdr. Returns -1 on failure,
and sets "*err" to the error and sets "*err_info" to null or an
additional error string. */
static gint64 cosine_seek_next_packet(wtap *wth, int *err, gchar **err_info,
static gint64 cosine_seek_next_packet(wftap *wfth, int *err, gchar **err_info,
char *hdr)
{
gint64 cur_off;
char buf[COSINE_LINE_LENGTH];
while (1) {
cur_off = file_tell(wth->fh);
cur_off = file_tell(wfth->fh);
if (cur_off == -1) {
/* Error */
*err = file_error(wth->fh, err_info);
*err = file_error(wfth->fh, err_info);
return -1;
}
if (file_gets(buf, sizeof(buf), wth->fh) == NULL) {
*err = file_error(wth->fh, err_info);
if (file_gets(buf, sizeof(buf), wfth->fh) == NULL) {
*err = file_error(wfth->fh, err_info);
return -1;
}
if (strstr(buf, COSINE_REC_MAGIC_STR1) ||
@ -232,7 +233,7 @@ static gint64 cosine_seek_next_packet(wtap *wth, int *err, gchar **err_info,
* if we get an I/O error, "*err" will be set to a non-zero value and
* "*err_info" will be set to null or an additional error string.
*/
static gboolean cosine_check_file_type(wtap *wth, int *err, gchar **err_info)
static gboolean cosine_check_file_type(wftap *wfth, int *err, gchar **err_info)
{
char buf[COSINE_LINE_LENGTH];
gsize reclen;
@ -241,9 +242,9 @@ static gboolean cosine_check_file_type(wtap *wth, int *err, gchar **err_info)
buf[COSINE_LINE_LENGTH-1] = '\0';
for (line = 0; line < COSINE_HEADER_LINES_TO_CHECK; line++) {
if (file_gets(buf, COSINE_LINE_LENGTH, wth->fh) == NULL) {
if (file_gets(buf, COSINE_LINE_LENGTH, wfth->fh) == NULL) {
/* EOF or error. */
*err = file_error(wth->fh, err_info);
*err = file_error(wfth->fh, err_info);
return FALSE;
}
@ -263,38 +264,39 @@ static gboolean cosine_check_file_type(wtap *wth, int *err, gchar **err_info)
}
int cosine_open(wtap *wth, int *err, gchar **err_info)
int cosine_open(wftap *wfth, int *err, gchar **err_info)
{
/* Look for CoSine header */
if (!cosine_check_file_type(wth, err, err_info)) {
if (!cosine_check_file_type(wfth, err, err_info)) {
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
return -1;
return 0;
}
if (file_seek(wth->fh, 0L, SEEK_SET, err) == -1) /* rewind */
if (file_seek(wfth->fh, 0L, SEEK_SET, err) == -1) /* rewind */
return -1;
wth->file_encap = WTAP_ENCAP_COSINE;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_COSINE;
wth->snapshot_length = 0; /* not known */
wth->subtype_read = cosine_read;
wth->subtype_seek_read = cosine_seek_read;
wth->tsprecision = WTAP_FILE_TSPREC_CSEC;
wfth->file_encap = WTAP_ENCAP_COSINE;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_COSINE;
wfth->snapshot_length = 0; /* not known */
wfth->subtype_read = cosine_read;
wfth->subtype_seek_read = cosine_seek_read;
wfth->tsprecision = WTAP_FILE_TSPREC_CSEC;
return 1;
}
/* Find the next packet and parse it; called from wtap_read(). */
static gboolean cosine_read(wtap *wth, int *err, gchar **err_info,
static gboolean cosine_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset)
{
gint64 offset;
int pkt_len;
char line[COSINE_LINE_LENGTH];
wtap* wth = (wtap*)wfth->tap_specific_data;
/* Find the next packet */
offset = cosine_seek_next_packet(wth, err, err_info, line);
offset = cosine_seek_next_packet(wfth, err, err_info, line);
if (offset < 0)
return FALSE;
*data_offset = offset;
@ -305,23 +307,24 @@ static gboolean cosine_read(wtap *wth, int *err, gchar **err_info,
return FALSE;
/* Convert the ASCII hex dump to binary data */
return parse_cosine_hex_dump(wth->fh, &wth->phdr, pkt_len,
wth->frame_buffer, err, err_info);
return parse_cosine_hex_dump(wfth->fh, &wth->phdr, pkt_len,
wfth->frame_buffer, err, err_info);
}
/* Used to read packets in random-access fashion */
static gboolean
cosine_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
cosine_seek_read(wftap *wfth, gint64 seek_off, void* header,
Buffer *buf, int *err, gchar **err_info)
{
int pkt_len;
char line[COSINE_LINE_LENGTH];
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 (file_gets(line, COSINE_LINE_LENGTH, wth->random_fh) == NULL) {
*err = file_error(wth->random_fh, err_info);
if (file_gets(line, COSINE_LINE_LENGTH, wfth->random_fh) == NULL) {
*err = file_error(wfth->random_fh, err_info);
if (*err == 0) {
*err = WTAP_ERR_SHORT_READ;
}
@ -334,7 +337,7 @@ cosine_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
return FALSE;
/* Convert the ASCII hex dump to binary data */
return parse_cosine_hex_dump(wth->random_fh, phdr, pkt_len, buf, err,
return parse_cosine_hex_dump(wfth->random_fh, phdr, pkt_len, buf, err,
err_info);
}

View File

@ -28,6 +28,6 @@
#include <wtap.h>
#include "ws_symbol_export.h"
int cosine_open(wtap *wth, int *err, gchar **err_info);
int cosine_open(wftap *wfth, int *err, gchar **err_info);
#endif

View File

@ -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;

View File

@ -25,6 +25,6 @@
#include <wtap.h>
#include "ws_symbol_export.h"
int csids_open(wtap *wth, int *err, gchar **err_info);
int csids_open(wftap *wfth, int *err, gchar **err_info);
#endif

View File

@ -1,4 +1,4 @@
/* daintree_sna.c
/* daintree-sna.c
* Routines for opening .dcf capture files created by Daintree's
* Sensor Network Analyzer for 802.15.4 radios
* Copyright 2009, Exegin Technologies Limited <fff@exegin.com>
@ -54,6 +54,7 @@
#include <ctype.h>
#include "wtap.h"
#include "wftap-int.h"
#include "wtap-int.h"
#include "buffer.h"
#include "file_wrappers.h"
@ -77,11 +78,11 @@ static const char daintree_magic_text[] =
#define COMMENT_LINE daintree_magic_text[0]
static gboolean daintree_sna_read(wtap *wth, int *err, gchar **err_info,
static gboolean daintree_sna_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean daintree_sna_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
static gboolean daintree_sna_seek_read(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info);
static gboolean daintree_sna_scan_header(struct wtap_pkthdr *phdr,
char *readLine, char *readData, int *err, gchar **err_info);
@ -90,14 +91,14 @@ static gboolean daintree_sna_process_hex_data(struct wtap_pkthdr *phdr,
Buffer *buf, char *readData, int *err, gchar **err_info);
/* Open a file and determine if it's a Daintree file */
int daintree_sna_open(wtap *wth, int *err, gchar **err_info)
int daintree_sna_open(wftap *wfth, int *err, gchar **err_info)
{
char readLine[DAINTREE_MAX_LINE_SIZE];
guint i;
/* get first line of file header */
if (file_gets(readLine, DAINTREE_MAX_LINE_SIZE, wth->fh)==NULL) {
*err = file_error(wth->fh, err_info);
if (file_gets(readLine, DAINTREE_MAX_LINE_SIZE, wfth->fh)==NULL) {
*err = file_error(wfth->fh, err_info);
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
return -1;
return 0;
@ -111,8 +112,8 @@ int daintree_sna_open(wtap *wth, int *err, gchar **err_info)
}
/* read second header line */
if (file_gets(readLine, DAINTREE_MAX_LINE_SIZE, wth->fh)==NULL) {
*err = file_error(wth->fh, err_info);
if (file_gets(readLine, DAINTREE_MAX_LINE_SIZE, wfth->fh)==NULL) {
*err = file_error(wfth->fh, err_info);
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
return -1;
return 0;
@ -120,14 +121,14 @@ int daintree_sna_open(wtap *wth, int *err, gchar **err_info)
if (readLine[0] != COMMENT_LINE) return 0; /* daintree files have a two line header */
/* set up the pointers to the handlers for this file type */
wth->subtype_read = daintree_sna_read;
wth->subtype_seek_read = daintree_sna_seek_read;
wfth->subtype_read = daintree_sna_read;
wfth->subtype_seek_read = daintree_sna_seek_read;
/* set up for file type */
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_DAINTREE_SNA;
wth->file_encap = WTAP_ENCAP_IEEE802_15_4_NOFCS;
wth->tsprecision = WTAP_FILE_TSPREC_USEC;
wth->snapshot_length = 0; /* not available in header */
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_DAINTREE_SNA;
wfth->file_encap = WTAP_ENCAP_IEEE802_15_4_NOFCS;
wfth->tsprecision = WTAP_FILE_TSPREC_USEC;
wfth->snapshot_length = 0; /* not available in header */
return 1; /* it's a Daintree file */
}
@ -135,18 +136,19 @@ int daintree_sna_open(wtap *wth, int *err, gchar **err_info)
/* Read the capture file sequentially
* Wireshark scans the file with sequential reads during preview and initial display. */
static gboolean
daintree_sna_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
daintree_sna_read(wftap *wfth, int *err, gchar **err_info, gint64 *data_offset)
{
char readLine[DAINTREE_MAX_LINE_SIZE];
char readData[READDATA_BUF_SIZE];
wtap* wth = (wtap*)wfth->tap_specific_data;
*data_offset = file_tell(wth->fh);
*data_offset = file_tell(wfth->fh);
/* we've only seen file header lines starting with '#', but
* if others appear in the file, they are tossed */
do {
if (file_gets(readLine, DAINTREE_MAX_LINE_SIZE, wth->fh) == NULL) {
*err = file_error(wth->fh, err_info);
if (file_gets(readLine, DAINTREE_MAX_LINE_SIZE, wfth->fh) == NULL) {
*err = file_error(wfth->fh, err_info);
return FALSE; /* all done */
}
} while (readLine[0] == COMMENT_LINE);
@ -157,27 +159,28 @@ daintree_sna_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
return FALSE;
/* process packet data */
return daintree_sna_process_hex_data(&wth->phdr, wth->frame_buffer,
return daintree_sna_process_hex_data(&wth->phdr, wfth->frame_buffer,
readData, err, err_info);
}
/* Read the capture file randomly
* Wireshark opens the capture file for random access when displaying user-selected packets */
static gboolean
daintree_sna_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
daintree_sna_seek_read(wftap *wfth, gint64 seek_off, void* header,
Buffer *buf, int *err, gchar **err_info)
{
char readLine[DAINTREE_MAX_LINE_SIZE];
char readData[READDATA_BUF_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;
/* It appears only file header lines start with '#', but
* if we find any others, we toss them */
do {
if (file_gets(readLine, DAINTREE_MAX_LINE_SIZE, wth->random_fh) == NULL) {
*err = file_error(wth->random_fh, err_info);
if (file_gets(readLine, DAINTREE_MAX_LINE_SIZE, wfth->random_fh) == NULL) {
*err = file_error(wfth->random_fh, err_info);
return FALSE; /* all done */
}
} while (readLine[0] == COMMENT_LINE);

View File

@ -27,7 +27,7 @@
#include <wtap.h>
#include "ws_symbol_export.h"
int daintree_sna_open(wtap *wth, int *err, gchar **err_info _U_);
int daintree_sna_open(wftap *wfth, int *err, gchar **err_info _U_);
#endif /* __DAINTREE_SNA_H__ */

View File

@ -19,6 +19,7 @@
*/
#include "config.h"
#include "wftap-int.h"
#include "wtap-int.h"
#include "buffer.h"
#include "dbs-etherwatch.h"
@ -84,10 +85,10 @@ static const char dbs_etherwatch_rec_magic[] =
*/
#define DBS_ETHERWATCH_MAX_PACKET_LEN 16384
static gboolean dbs_etherwatch_read(wtap *wth, int *err, gchar **err_info,
static gboolean dbs_etherwatch_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean dbs_etherwatch_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
static gboolean dbs_etherwatch_seek_read(wftap *wth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info);
static gboolean parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh,
Buffer* buf, int *err, gchar **err_info);
static guint parse_single_hex_dump_line(char* rec, guint8 *buf,
@ -97,22 +98,22 @@ static guint parse_hex_dump(char* dump, guint8 *buf, char seperator, char end);
/* Seeks to the beginning of the next packet, and returns the
byte offset. Returns -1 on failure, and sets "*err" to the error
and "*err_info" to null or an additional error string. */
static gint64 dbs_etherwatch_seek_next_packet(wtap *wth, int *err,
static gint64 dbs_etherwatch_seek_next_packet(wftap *wfth, int *err,
gchar **err_info)
{
int byte;
unsigned int level = 0;
gint64 cur_off;
while ((byte = file_getc(wth->fh)) != EOF) {
while ((byte = file_getc(wfth->fh)) != EOF) {
if (byte == dbs_etherwatch_rec_magic[level]) {
level++;
if (level >= DBS_ETHERWATCH_REC_MAGIC_SIZE) {
/* note: we're leaving file pointer right after the magic characters */
cur_off = file_tell(wth->fh);
cur_off = file_tell(wfth->fh);
if (cur_off == -1) {
/* Error. */
*err = file_error(wth->fh, err_info);
*err = file_error(wfth->fh, err_info);
return -1;
}
return cur_off + 1;
@ -122,7 +123,7 @@ static gint64 dbs_etherwatch_seek_next_packet(wtap *wth, int *err,
}
}
/* EOF or error. */
*err = file_error(wth->fh, err_info);
*err = file_error(wfth->fh, err_info);
return -1;
}
@ -136,7 +137,7 @@ static gint64 dbs_etherwatch_seek_next_packet(wtap *wth, int *err,
* if we get an I/O error, "*err" will be set to a non-zero value and
* "*err_info" will be set to null or an error string.
*/
static gboolean dbs_etherwatch_check_file_type(wtap *wth, int *err,
static gboolean dbs_etherwatch_check_file_type(wftap *wfth, int *err,
gchar **err_info)
{
char buf[DBS_ETHERWATCH_LINE_LENGTH];
@ -147,9 +148,9 @@ static gboolean dbs_etherwatch_check_file_type(wtap *wth, int *err,
buf[DBS_ETHERWATCH_LINE_LENGTH-1] = 0;
for (line = 0; line < DBS_ETHERWATCH_HEADER_LINES_TO_CHECK; line++) {
if (file_gets(buf, DBS_ETHERWATCH_LINE_LENGTH, wth->fh) == NULL) {
if (file_gets(buf, DBS_ETHERWATCH_LINE_LENGTH, wfth->fh) == NULL) {
/* EOF or error. */
*err = file_error(wth->fh, err_info);
*err = file_error(wfth->fh, err_info);
return FALSE;
}
@ -176,51 +177,53 @@ static gboolean dbs_etherwatch_check_file_type(wtap *wth, int *err,
}
int dbs_etherwatch_open(wtap *wth, int *err, gchar **err_info)
int dbs_etherwatch_open(wftap *wfth, int *err, gchar **err_info)
{
/* Look for DBS ETHERWATCH header */
if (!dbs_etherwatch_check_file_type(wth, err, err_info)) {
if (!dbs_etherwatch_check_file_type(wfth, err, err_info)) {
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
return -1;
return 0;
}
wth->file_encap = WTAP_ENCAP_ETHERNET;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_DBS_ETHERWATCH;
wth->snapshot_length = 0; /* not known */
wth->subtype_read = dbs_etherwatch_read;
wth->subtype_seek_read = dbs_etherwatch_seek_read;
wth->tsprecision = WTAP_FILE_TSPREC_CSEC;
wfth->file_encap = WTAP_ENCAP_ETHERNET;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_DBS_ETHERWATCH;
wfth->snapshot_length = 0; /* not known */
wfth->subtype_read = dbs_etherwatch_read;
wfth->subtype_seek_read = dbs_etherwatch_seek_read;
wfth->tsprecision = WTAP_FILE_TSPREC_CSEC;
return 1;
}
/* Find the next packet and parse it; called from wtap_read(). */
static gboolean dbs_etherwatch_read(wtap *wth, int *err, gchar **err_info,
static gboolean dbs_etherwatch_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset)
{
gint64 offset;
wtap* wth = (wtap*)wfth->tap_specific_data;
/* Find the next packet */
offset = dbs_etherwatch_seek_next_packet(wth, err, err_info);
offset = dbs_etherwatch_seek_next_packet(wfth, err, err_info);
if (offset < 1)
return FALSE;
*data_offset = offset;
/* Parse the packet */
return parse_dbs_etherwatch_packet(&wth->phdr, wth->fh,
wth->frame_buffer, err, err_info);
return parse_dbs_etherwatch_packet(&wth->phdr, wfth->fh,
wfth->frame_buffer, err, err_info);
}
/* Used to read packets in random-access fashion */
static gboolean
dbs_etherwatch_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
dbs_etherwatch_seek_read(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off - 1, SEEK_SET, err) == -1)
struct wtap_pkthdr *phdr = (struct wtap_pkthdr*)header;
if (file_seek(wfth->random_fh, seek_off - 1, SEEK_SET, err) == -1)
return FALSE;
return parse_dbs_etherwatch_packet(phdr, wth->random_fh, buf, err,
return parse_dbs_etherwatch_packet(phdr, wfth->random_fh, buf, err,
err_info);
}

View File

@ -25,6 +25,6 @@
#include <wtap.h>
#include "ws_symbol_export.h"
int dbs_etherwatch_open(wtap *wth, int *err, gchar **err_info);
int dbs_etherwatch_open(wftap *wfth, int *err, gchar **err_info);
#endif

View File

@ -25,6 +25,7 @@
*/
#include "config.h"
#include "wftap-int.h"
#include "wtap-int.h"
#include "buffer.h"
#include "dct3trace.h"
@ -73,10 +74,10 @@ static const char dct3trace_magic_end[] = "</dump>";
#define MAX_PACKET_LEN 23
static gboolean dct3trace_read(wtap *wth, int *err, gchar **err_info,
static gboolean dct3trace_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean dct3trace_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
static gboolean dct3trace_seek_read(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info);
/*
* Following 3 functions taken from gsmdecode-0.7bis, with permission - http://wiki.thc.org/gsm
@ -155,15 +156,15 @@ xml_get_int(int *val, const char *str, const char *pattern)
}
int dct3trace_open(wtap *wth, int *err, gchar **err_info)
int dct3trace_open(wftap *wfth, int *err, gchar **err_info)
{
char line1[64], line2[64];
/* Look for Gammu DCT3 trace header */
if (file_gets(line1, sizeof(line1), wth->fh) == NULL ||
file_gets(line2, sizeof(line2), wth->fh) == NULL)
if (file_gets(line1, sizeof(line1), wfth->fh) == NULL ||
file_gets(line2, sizeof(line2), wfth->fh) == NULL)
{
*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;
@ -176,12 +177,12 @@ int dct3trace_open(wtap *wth, int *err, gchar **err_info)
return 0;
}
wth->file_encap = WTAP_ENCAP_GSM_UM;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_DCT3TRACE;
wth->snapshot_length = 0; /* not known */
wth->subtype_read = dct3trace_read;
wth->subtype_seek_read = dct3trace_seek_read;
wth->tsprecision = WTAP_FILE_TSPREC_SEC;
wfth->file_encap = WTAP_ENCAP_GSM_UM;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_DCT3TRACE;
wfth->snapshot_length = 0; /* not known */
wfth->subtype_read = dct3trace_read;
wfth->subtype_seek_read = dct3trace_seek_read;
wfth->tsprecision = WTAP_FILE_TSPREC_SEC;
return 1;
}
@ -346,24 +347,26 @@ baddata:
/* Find the next packet and parse it; called from wtap_read(). */
static gboolean dct3trace_read(wtap *wth, int *err, gchar **err_info,
static gboolean dct3trace_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset)
{
*data_offset = file_tell(wth->fh);
wtap* wth = (wtap*)wfth->tap_specific_data;
*data_offset = file_tell(wfth->fh);
return dct3trace_get_packet(wth->fh, &wth->phdr, wth->frame_buffer,
return dct3trace_get_packet(wfth->fh, &wth->phdr, wfth->frame_buffer,
err, err_info);
}
/* Used to read packets in random-access fashion */
static gboolean dct3trace_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
static gboolean dct3trace_seek_read(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
struct wtap_pkthdr *phdr = (struct wtap_pkthdr*)header;
if (file_seek(wfth->random_fh, seek_off, SEEK_SET, err) == -1)
{
return FALSE;
}
return dct3trace_get_packet(wth->random_fh, phdr, buf, err, err_info);
return dct3trace_get_packet(wfth->random_fh, phdr, buf, err, err_info);
}

View File

@ -24,6 +24,6 @@
#include <wtap.h>
#include "ws_symbol_export.h"
int dct3trace_open(wtap *wth, int *err, gchar **err_info);
int dct3trace_open(wftap *wfth, int *err, gchar **err_info);
#endif

View File

@ -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;

View File

@ -103,9 +103,9 @@ union erf_subhdr {
#define RECORDS_FOR_ERF_CHECK 20
#define FCS_BITS 32
int erf_open(wtap *wth, int *err, gchar **err_info);
int erf_open(wftap *wfth, int *err, gchar **err_info);
int erf_dump_can_write_encap(int encap);
int erf_dump_open(wtap_dumper *wdh, int *err);
int erf_dump_open(wftap_dumper *wdh, int *err);
int erf_populate_interfaces(wtap *wth);

View File

@ -19,6 +19,7 @@
*/
#include "config.h"
#include "wftap-int.h"
#include "wtap-int.h"
#include "buffer.h"
#include "eyesdn.h"
@ -90,47 +91,47 @@ static const unsigned char eyesdn_hdr_magic[] =
*/
#define EYESDN_MAX_PACKET_LEN 16384
static gboolean eyesdn_read(wtap *wth, int *err, gchar **err_info,
static gboolean eyesdn_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean eyesdn_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
static gboolean eyesdn_seek_read(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info);
static int read_eyesdn_rec(FILE_T fh, struct wtap_pkthdr *phdr, Buffer* buf,
int *err, gchar **err_info);
/* Seeks to the beginning of the next packet, and returns the
byte offset. Returns -1 on failure, and sets "*err" to the error
and "*err_info" to null or an additional error string. */
static gint64 eyesdn_seek_next_packet(wtap *wth, int *err, gchar **err_info)
static gint64 eyesdn_seek_next_packet(wftap *wfth, int *err, gchar **err_info)
{
int byte;
gint64 cur_off;
while ((byte = file_getc(wth->fh)) != EOF) {
while ((byte = file_getc(wfth->fh)) != EOF) {
if (byte == 0xff) {
cur_off = file_tell(wth->fh);
cur_off = file_tell(wfth->fh);
if (cur_off == -1) {
/* Error. */
*err = file_error(wth->fh, err_info);
*err = file_error(wfth->fh, err_info);
return -1;
}
return cur_off;
}
}
/* EOF or error. */
*err = file_error(wth->fh, err_info);
*err = file_error(wfth->fh, err_info);
return -1;
}
int eyesdn_open(wtap *wth, int *err, gchar **err_info)
int eyesdn_open(wftap *wfth, int *err, gchar **err_info)
{
int bytes_read;
char magic[EYESDN_HDR_MAGIC_SIZE];
/* Look for eyesdn header */
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;
@ -138,42 +139,44 @@ int eyesdn_open(wtap *wth, int *err, gchar **err_info)
if (memcmp(magic, eyesdn_hdr_magic, EYESDN_HDR_MAGIC_SIZE) != 0)
return 0;
wth->file_encap = WTAP_ENCAP_PER_PACKET;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_EYESDN;
wth->snapshot_length = 0; /* not known */
wth->subtype_read = eyesdn_read;
wth->subtype_seek_read = eyesdn_seek_read;
wth->tsprecision = WTAP_FILE_TSPREC_USEC;
wfth->file_encap = WTAP_ENCAP_PER_PACKET;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_EYESDN;
wfth->snapshot_length = 0; /* not known */
wfth->subtype_read = eyesdn_read;
wfth->subtype_seek_read = eyesdn_seek_read;
wfth->tsprecision = WTAP_FILE_TSPREC_USEC;
return 1;
}
/* Find the next packet and parse it; called from wtap_read(). */
static gboolean eyesdn_read(wtap *wth, int *err, gchar **err_info,
static gboolean eyesdn_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset)
{
gint64 offset;
wtap* wth = (wtap*)wfth->tap_specific_data;
/* Find the next record */
offset = eyesdn_seek_next_packet(wth, err, err_info);
offset = eyesdn_seek_next_packet(wfth, err, err_info);
if (offset < 1)
return FALSE;
*data_offset = offset;
/* Parse the record */
return read_eyesdn_rec(wth->fh, &wth->phdr, wth->frame_buffer,
return read_eyesdn_rec(wfth->fh, &wth->phdr, wfth->frame_buffer,
err, err_info);
}
/* Used to read packets in random-access fashion */
static gboolean
eyesdn_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
eyesdn_seek_read(wftap *wfth, gint64 seek_off, void* header,
Buffer *buf, int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
struct wtap_pkthdr *phdr = (struct wtap_pkthdr *)header;
if (file_seek(wfth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
return read_eyesdn_rec(wth->random_fh, phdr, buf, err, err_info);
return read_eyesdn_rec(wfth->random_fh, phdr, buf, err, err_info);
}
/* Parses a record. */
@ -187,8 +190,8 @@ read_eyesdn_rec(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err,
int usecs;
int pkt_len;
guint8 channel, direction;
int bytes_read;
guint8 *pd;
int bytes_read;
guint8 *pd;
/* Our file pointer should be at the summary information header
* for a packet. Read in that header and extract the useful
@ -342,7 +345,7 @@ read_eyesdn_rec(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err,
static gboolean
esc_write(wtap_dumper *wdh, const guint8 *buf, int len, int *err)
esc_write(wftap_dumper *wdh, const guint8 *buf, int len, int *err)
{
int i;
guint8 byte;
@ -354,26 +357,26 @@ esc_write(wtap_dumper *wdh, const guint8 *buf, int len, int *err)
/*
* Escape the frame delimiter and escape byte.
*/
if (!wtap_dump_file_write(wdh, &esc, sizeof esc, err))
if (!wftap_dump_file_write(wdh, &esc, sizeof esc, err))
return FALSE;
byte-=2;
}
if (!wtap_dump_file_write(wdh, &byte, sizeof byte, err))
if (!wftap_dump_file_write(wdh, &byte, sizeof byte, err))
return FALSE;
}
return TRUE;
}
static gboolean eyesdn_dump(wtap_dumper *wdh,
static gboolean eyesdn_dump(wftap_dumper *wdh,
const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err);
gboolean eyesdn_dump_open(wtap_dumper *wdh, int *err)
gboolean eyesdn_dump_open(wftap_dumper *wdh, int *err)
{
wdh->subtype_write=eyesdn_dump;
wdh->subtype_close=NULL;
if (!wtap_dump_file_write(wdh, eyesdn_hdr_magic,
if (!wftap_dump_file_write(wdh, eyesdn_hdr_magic,
EYESDN_HDR_MAGIC_SIZE, err))
return FALSE;
wdh->bytes_dumped += EYESDN_HDR_MAGIC_SIZE;
@ -401,7 +404,7 @@ int eyesdn_dump_can_write_encap(int encap)
/* Write a record for a packet to a dump file.
* Returns TRUE on success, FALSE on failure. */
static gboolean eyesdn_dump(wtap_dumper *wdh,
static gboolean eyesdn_dump(wftap_dumper *wdh,
const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err)
{
@ -488,7 +491,7 @@ static gboolean eyesdn_dump(wtap_dumper *wdh,
phtons(&buf[10], size);
/* start flag */
if (!wtap_dump_file_write(wdh, &start_flag, sizeof start_flag, err))
if (!wftap_dump_file_write(wdh, &start_flag, sizeof start_flag, err))
return FALSE;
if (!esc_write(wdh, buf, 12, err))
return FALSE;

View File

@ -26,7 +26,7 @@
#include <wtap.h>
#include "ws_symbol_export.h"
int eyesdn_open(wtap *wth, int *err, gchar **err_info);
int eyesdn_open(wftap *wfth, int *err, gchar **err_info);
enum EyeSDN_TYPES {
EYESDN_ENCAP_ISDN=0,
@ -40,7 +40,7 @@ enum EyeSDN_TYPES {
EYESDN_ENCAP_V5_EF
};
gboolean eyesdn_dump_open(wtap_dumper *wdh, int *err);
gboolean eyesdn_dump_open(wftap_dumper *wdh, int *err);
int eyesdn_dump_can_write_encap(int encap);
#endif

View File

@ -36,6 +36,7 @@
#include <wsutil/file_util.h>
#include "wftap-int.h"
#include "wtap-int.h"
#include "file_wrappers.h"
#include "buffer.h"
@ -673,12 +674,13 @@ static gboolean heuristic_uses_extension(unsigned int i, const char *extension)
so that it can do sequential I/O to a capture file that's being
written to as new packets arrive independently of random I/O done
to display protocol trees for packets when they're selected. */
wtap* wtap_open_offline(const char *filename, unsigned int type, int *err, char **err_info,
wftap* wtap_open_offline(const char *filename, unsigned int type, int *err, char **err_info,
gboolean do_random)
{
int fd;
ws_statb64 statb;
wtap *wth;
wftap *wfth;
unsigned int i;
gboolean use_stdin = FALSE;
gchar *extension;
@ -742,76 +744,79 @@ wtap* wtap_open_offline(const char *filename, unsigned int type, int *err, char
}
errno = ENOMEM;
wth = (wtap *)g_malloc0(sizeof(wtap));
wfth = (wftap *)g_malloc0(sizeof(wtap));
/* Open the file */
errno = WTAP_ERR_CANT_OPEN;
if (use_stdin) {
/*
* We dup FD 0, so that we don't have to worry about
* a file_close of wth->fh closing the standard
* a file_close of wfth->fh closing the standard
* input of the process.
*/
fd = ws_dup(0);
if (fd < 0) {
*err = errno;
g_free(wth);
g_free(wfth);
return NULL;
}
#ifdef _WIN32
if (_setmode(fd, O_BINARY) == -1) {
/* "Shouldn't happen" */
*err = errno;
g_free(wth);
g_free(wfth);
return NULL;
}
#endif
if (!(wth->fh = file_fdopen(fd))) {
if (!(wfth->fh = file_fdopen(fd))) {
*err = errno;
ws_close(fd);
g_free(wth);
g_free(wfth);
return NULL;
}
} else {
if (!(wth->fh = file_open(filename))) {
if (!(wfth->fh = file_open(filename))) {
*err = errno;
g_free(wth);
g_free(wfth);
return NULL;
}
}
if (do_random) {
if (!(wth->random_fh = file_open(filename))) {
if (!(wfth->random_fh = file_open(filename))) {
*err = errno;
file_close(wth->fh);
g_free(wth);
file_close(wfth->fh);
g_free(wfth);
return NULL;
}
} else
wth->random_fh = NULL;
wfth->random_fh = NULL;
wth = (wtap *)g_malloc0(sizeof(wtap));
wfth->tap_specific_data = wth;
/* initialization */
wth->file_encap = WTAP_ENCAP_UNKNOWN;
wth->subtype_sequential_close = NULL;
wth->subtype_close = NULL;
wth->tsprecision = WTAP_FILE_TSPREC_USEC;
wth->priv = NULL;
wth->wslua_data = NULL;
wfth->file_encap = WTAP_ENCAP_UNKNOWN;
wfth->subtype_sequential_close = NULL;
wfth->subtype_close = NULL;
wfth->tsprecision = WTAP_FILE_TSPREC_USEC;
wfth->priv = NULL;
wfth->wslua_data = NULL;
if (wth->random_fh) {
wth->fast_seek = g_ptr_array_new();
if (wfth->random_fh) {
wfth->fast_seek = g_ptr_array_new();
file_set_random_access(wth->fh, FALSE, wth->fast_seek);
file_set_random_access(wth->random_fh, TRUE, wth->fast_seek);
file_set_random_access(wfth->fh, FALSE, wfth->fast_seek);
file_set_random_access(wfth->random_fh, TRUE, wfth->fast_seek);
}
/* 'type' is 1 greater than the array index */
if (type != WTAP_TYPE_AUTO && type <= open_info_arr->len) {
int result;
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) {
if (file_seek(wfth->fh, 0, SEEK_SET, err) == -1) {
/* I/O error - give up */
wtap_close(wth);
wtap_close(wfth);
return NULL;
}
@ -819,14 +824,14 @@ wtap* wtap_open_offline(const char *filename, unsigned int type, int *err, char
* to the file reader, kinda like the priv member but not free'd later.
* It's ok for this to copy a NULL.
*/
wth->wslua_data = open_routines[type - 1].wslua_data;
wfth->wslua_data = open_routines[type - 1].wslua_data;
result = (*open_routines[type - 1].open_routine)(wth, err, err_info);
result = (*open_routines[type - 1].open_routine)(wfth, err, err_info);
switch (result) {
case -1:
/* I/O error - give up */
wtap_close(wth);
wtap_close(wfth);
return NULL;
case 0:
@ -848,9 +853,9 @@ wtap* wtap_open_offline(const char *filename, unsigned int type, int *err, char
to start reading at the beginning.
Initialize the data offset while we're at it. */
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) {
if (file_seek(wfth->fh, 0, SEEK_SET, err) == -1) {
/* I/O error - give up */
wtap_close(wth);
wtap_close(wfth);
return NULL;
}
@ -858,13 +863,13 @@ wtap* wtap_open_offline(const char *filename, unsigned int type, int *err, char
* to the file reader, kinda like the priv member but not free'd later.
* It's ok for this to copy a NULL.
*/
wth->wslua_data = open_routines[i].wslua_data;
wfth->wslua_data = open_routines[i].wslua_data;
switch ((*open_routines[i].open_routine)(wth, err, err_info)) {
switch ((*open_routines[i].open_routine)(wfth, err, err_info)) {
case -1:
/* I/O error - give up */
wtap_close(wth);
wtap_close(wfth);
return NULL;
case 0:
@ -886,25 +891,25 @@ wtap* wtap_open_offline(const char *filename, unsigned int type, int *err, char
/* Does this type use that extension? */
if (heuristic_uses_extension(i, extension)) {
/* Yes. */
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) {
if (file_seek(wfth->fh, 0, SEEK_SET, err) == -1) {
/* I/O error - give up */
g_free(extension);
wtap_close(wth);
wtap_close(wfth);
return NULL;
}
/* Set wth with wslua data if any - this is how we pass the data
* to the file reader, kind of like priv but not free'd later.
*/
wth->wslua_data = open_routines[i].wslua_data;
wfth->wslua_data = open_routines[i].wslua_data;
switch ((*open_routines[i].open_routine)(wth,
switch ((*open_routines[i].open_routine)(wfth,
err, err_info)) {
case -1:
/* I/O error - give up */
g_free(extension);
wtap_close(wth);
wtap_close(wfth);
return NULL;
case 0:
@ -924,25 +929,25 @@ wtap* wtap_open_offline(const char *filename, unsigned int type, int *err, char
/* Does this type use that extension? */
if (!heuristic_uses_extension(i, extension)) {
/* No. */
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) {
if (file_seek(wfth->fh, 0, SEEK_SET, err) == -1) {
/* I/O error - give up */
g_free(extension);
wtap_close(wth);
wtap_close(wfth);
return NULL;
}
/* Set wth with wslua data if any - this is how we pass the data
* to the file reader, kind of like priv but not free'd later.
*/
wth->wslua_data = open_routines[i].wslua_data;
wfth->wslua_data = open_routines[i].wslua_data;
switch ((*open_routines[i].open_routine)(wth,
switch ((*open_routines[i].open_routine)(wfth,
err, err_info)) {
case -1:
/* I/O error - give up */
g_free(extension);
wtap_close(wth);
wtap_close(wfth);
return NULL;
case 0:
@ -961,22 +966,22 @@ wtap* wtap_open_offline(const char *filename, unsigned int type, int *err, char
/* No - try all the heuristics types in order. */
for (i = heuristic_open_routine_idx; i < open_info_arr->len; i++) {
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) {
if (file_seek(wfth->fh, 0, SEEK_SET, err) == -1) {
/* I/O error - give up */
wtap_close(wth);
wtap_close(wfth);
return NULL;
}
/* Set wth with wslua data if any - this is how we pass the data
* to the file reader, kind of like priv but not free'd later.
*/
wth->wslua_data = open_routines[i].wslua_data;
wfth->wslua_data = open_routines[i].wslua_data;
switch ((*open_routines[i].open_routine)(wth, err, err_info)) {
switch ((*open_routines[i].open_routine)(wfth, err, err_info)) {
case -1:
/* I/O error - give up */
wtap_close(wth);
wtap_close(wfth);
return NULL;
case 0:
@ -993,22 +998,22 @@ wtap* wtap_open_offline(const char *filename, unsigned int type, int *err, char
fail:
/* Well, it's not one of the types of file we know about. */
wtap_close(wth);
wtap_close(wfth);
*err = WTAP_ERR_FILE_UNKNOWN_FORMAT;
return NULL;
success:
wth->frame_buffer = (struct Buffer *)g_malloc(sizeof(struct Buffer));
buffer_init(wth->frame_buffer, 1500);
wfth->frame_buffer = (struct Buffer *)g_malloc(sizeof(struct Buffer));
buffer_init(wfth->frame_buffer, 1500);
if(wth->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_PCAP){
if(wfth->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_PCAP){
wtapng_if_descr_t descr;
descr.wtap_encap = wth->file_encap;
descr.wtap_encap = wfth->file_encap;
descr.time_units_per_second = 1000000; /* default microsecond resolution */
descr.link_type = wtap_wtap_encap_to_pcap_encap(wth->file_encap);
descr.snap_len = wth->snapshot_length;
descr.link_type = wtap_wtap_encap_to_pcap_encap(wfth->file_encap);
descr.snap_len = wfth->snapshot_length;
descr.opt_comment = NULL;
descr.if_name = NULL;
descr.if_description = NULL;
@ -1026,7 +1031,7 @@ success:
g_array_append_val(wth->interface_data, descr);
}
return wth;
return wfth;
}
/*
@ -1042,7 +1047,7 @@ success:
* reopens the random stream.
*/
gboolean
wtap_fdreopen(wtap *wth, const char *filename, int *err)
wftap_fdreopen(wftap *wfth, const char *filename, int *err)
{
ws_statb64 statb;
@ -1084,7 +1089,7 @@ wtap_fdreopen(wtap *wth, const char *filename, int *err)
/* Open the file */
errno = WTAP_ERR_CANT_OPEN;
if (!file_fdreopen(wth->random_fh, filename)) {
if (!file_fdreopen(wfth->random_fh, filename)) {
*err = errno;
return FALSE;
}
@ -1956,31 +1961,40 @@ gboolean wtap_dump_supports_comment_types(int file_type_subtype, guint32 comment
}
static gboolean wtap_dump_open_check(int file_type_subtype, int encap, gboolean comressed, int *err);
static wtap_dumper* wtap_dump_alloc_wdh(int file_type_subtype, int encap, int snaplen,
static wftap_dumper* wtap_dump_alloc_wfdh(int file_type_subtype, int encap, int snaplen,
gboolean compressed, int *err);
static gboolean wtap_dump_open_finish(wtap_dumper *wdh, int file_type_subtype, gboolean compressed, int *err);
static gboolean wtap_dump_open_finish(wftap_dumper *wdh, int file_type_subtype, gboolean compressed, int *err);
static WFILE_T wtap_dump_file_open(wtap_dumper *wdh, const char *filename);
static WFILE_T wtap_dump_file_fdopen(wtap_dumper *wdh, int fd);
static int wtap_dump_file_close(wtap_dumper *wdh);
static WFILE_T wftap_dump_file_open(wftap_dumper *wdh, const char *filename);
static WFILE_T wftap_dump_file_fdopen(wftap_dumper *wdh, int fd);
static int wtap_dump_file_close(wftap_dumper *wdh);
wtap_dumper* wtap_dump_open(const char *filename, int file_type_subtype, int encap,
wftap_dumper* wtap_dump_open(const char *filename, int file_type_subtype, int encap,
int snaplen, gboolean compressed, int *err)
{
return wtap_dump_open_ng(filename, file_type_subtype, encap,snaplen, compressed, NULL, NULL, err);
}
static wtap_dumper *
static wftap_dumper *
wtap_dump_init_dumper(int file_type_subtype, int encap, int snaplen, gboolean compressed,
wtapng_section_t *shb_hdr, wtapng_iface_descriptions_t *idb_inf, int *err)
{
wtap_dumper *wdh;
wftap_dumper *wfdh;
wtap_dumper* wdh;
/* Allocate a data structure for the output stream. */
wdh = wtap_dump_alloc_wdh(file_type_subtype, encap, snaplen, compressed, err);
if (wdh == NULL)
wfdh = wtap_dump_alloc_wfdh(file_type_subtype, encap, snaplen, compressed, err);
if (wfdh == NULL)
return NULL; /* couldn't allocate it */
wdh = (wtap_dumper *)g_malloc0(sizeof (wtap_dumper));
if (wdh == NULL) {
*err = errno;
g_free(wfdh);
return NULL;
}
wfdh->tap_specific_data = wdh;
/* Set Section Header Block data */
wdh->shb_hdr = shb_hdr;
/* Set Interface Description Block data */
@ -2010,13 +2024,14 @@ wtap_dump_init_dumper(int file_type_subtype, int encap, int snaplen, gboolean co
wdh->interface_data= g_array_new(FALSE, FALSE, sizeof(wtapng_if_descr_t));
g_array_append_val(wdh->interface_data, descr);
}
return wdh;
return wfdh;
}
wtap_dumper* wtap_dump_open_ng(const char *filename, int file_type_subtype, int encap,
wftap_dumper* wtap_dump_open_ng(const char *filename, int file_type_subtype, int encap,
int snaplen, gboolean compressed, wtapng_section_t *shb_hdr, wtapng_iface_descriptions_t *idb_inf, int *err)
{
wtap_dumper *wdh;
wftap_dumper *wfdh;
wtap_dumper* wdh;
WFILE_T fh;
/* Check whether we can open a capture file with that file type
@ -2025,16 +2040,19 @@ wtap_dumper* wtap_dump_open_ng(const char *filename, int file_type_subtype, int
return NULL;
/* Allocate and initialize a data structure for the output stream. */
wdh = wtap_dump_init_dumper(file_type_subtype, encap, snaplen, compressed,
wfdh = wtap_dump_init_dumper(file_type_subtype, encap, snaplen, compressed,
shb_hdr, idb_inf, err);
if (wdh == NULL)
if (wfdh == NULL)
return NULL;
wdh = wfdh->tap_specific_data;
/* "-" means stdout */
if (strcmp(filename, "-") == 0) {
if (compressed) {
*err = EINVAL; /* XXX - return a Wiretap error code for this */
g_free(wdh);
g_free(wfdh);
return NULL; /* compress won't work on stdout */
}
#ifdef _WIN32
@ -2042,46 +2060,49 @@ wtap_dumper* wtap_dump_open_ng(const char *filename, int file_type_subtype, int
/* "Should not happen" */
*err = errno;
g_free(wdh);
g_free(wfdh);
return NULL; /* couldn't put standard output in binary mode */
}
#endif
wdh->fh = stdout;
wfdh->fh = stdout;
} else {
/* In case "fopen()" fails but doesn't set "errno", set "errno"
to a generic "the open failed" error. */
errno = WTAP_ERR_CANT_OPEN;
fh = wtap_dump_file_open(wdh, filename);
fh = wftap_dump_file_open(wfdh, filename);
if (fh == NULL) {
*err = errno;
g_free(wdh);
g_free(wfdh);
return NULL; /* can't create file */
}
wdh->fh = fh;
wfdh->fh = fh;
}
if (!wtap_dump_open_finish(wdh, file_type_subtype, compressed, err)) {
if (!wtap_dump_open_finish(wfdh, file_type_subtype, compressed, err)) {
/* Get rid of the file we created; we couldn't finish
opening it. */
if (wdh->fh != stdout) {
wtap_dump_file_close(wdh);
if (wfdh->fh != stdout) {
wtap_dump_file_close(wfdh);
ws_unlink(filename);
}
g_free(wdh);
g_free(wfdh);
return NULL;
}
return wdh;
return wfdh;
}
wtap_dumper* wtap_dump_fdopen(int fd, int file_type_subtype, int encap, int snaplen,
wftap_dumper* wtap_dump_fdopen(int fd, int file_type_subtype, int encap, int snaplen,
gboolean compressed, int *err)
{
return wtap_dump_fdopen_ng(fd, file_type_subtype, encap, snaplen, compressed, NULL, NULL, err);
}
wtap_dumper* wtap_dump_fdopen_ng(int fd, int file_type_subtype, int encap, int snaplen,
wftap_dumper* wtap_dump_fdopen_ng(int fd, int file_type_subtype, int encap, int snaplen,
gboolean compressed, wtapng_section_t *shb_hdr, wtapng_iface_descriptions_t *idb_inf, int *err)
{
wtap_dumper *wdh;
wftap_dumper *wfdh;
WFILE_T fh;
/* Check whether we can open a capture file with that file type
@ -2090,9 +2111,9 @@ wtap_dumper* wtap_dump_fdopen_ng(int fd, int file_type_subtype, int encap, int s
return NULL;
/* Allocate and initialize a data structure for the output stream. */
wdh = wtap_dump_init_dumper(file_type_subtype, encap, snaplen, compressed,
wfdh = wtap_dump_init_dumper(file_type_subtype, encap, snaplen, compressed,
shb_hdr, idb_inf, err);
if (wdh == NULL)
if (wfdh == NULL)
return NULL;
#ifdef _WIN32
@ -2100,7 +2121,7 @@ wtap_dumper* wtap_dump_fdopen_ng(int fd, int file_type_subtype, int encap, int s
if (_setmode(fileno(stdout), O_BINARY) == -1) {
/* "Should not happen" */
*err = errno;
g_free(wdh);
g_free(wfdh);
return NULL; /* couldn't put standard output in binary mode */
}
}
@ -2109,20 +2130,20 @@ wtap_dumper* wtap_dump_fdopen_ng(int fd, int file_type_subtype, int encap, int s
/* In case "fopen()" fails but doesn't set "errno", set "errno"
to a generic "the open failed" error. */
errno = WTAP_ERR_CANT_OPEN;
fh = wtap_dump_file_fdopen(wdh, fd);
fh = wftap_dump_file_fdopen(wfdh, fd);
if (fh == NULL) {
*err = errno;
g_free(wdh);
g_free(wfdh);
return NULL; /* can't create standard I/O stream */
}
wdh->fh = fh;
wfdh->fh = fh;
if (!wtap_dump_open_finish(wdh, file_type_subtype, compressed, err)) {
wtap_dump_file_close(wdh);
g_free(wdh);
if (!wtap_dump_open_finish(wfdh, file_type_subtype, compressed, err)) {
wtap_dump_file_close(wfdh);
g_free(wfdh);
return NULL;
}
return wdh;
return wfdh;
}
static gboolean wtap_dump_open_check(int file_type_subtype, int encap, gboolean compressed, int *err)
@ -2158,12 +2179,12 @@ static gboolean wtap_dump_open_check(int file_type_subtype, int encap, gboolean
return TRUE;
}
static wtap_dumper* wtap_dump_alloc_wdh(int file_type_subtype, int encap, int snaplen,
static wftap_dumper* wtap_dump_alloc_wfdh(int file_type_subtype, int encap, int snaplen,
gboolean compressed, int *err)
{
wtap_dumper *wdh;
wftap_dumper *wdh;
wdh = (wtap_dumper *)g_malloc0(sizeof (wtap_dumper));
wdh = (wftap_dumper *)g_malloc0(sizeof (wftap_dumper));
if (wdh == NULL) {
*err = errno;
return NULL;
@ -2177,7 +2198,7 @@ static wtap_dumper* wtap_dump_alloc_wdh(int file_type_subtype, int encap, int sn
return wdh;
}
static gboolean wtap_dump_open_finish(wtap_dumper *wdh, int file_type_subtype, gboolean compressed, int *err)
static gboolean wtap_dump_open_finish(wftap_dumper *wdh, int file_type_subtype, gboolean compressed, int *err)
{
int fd;
gboolean cant_seek;
@ -2217,13 +2238,13 @@ static gboolean wtap_dump_open_finish(wtap_dumper *wdh, int file_type_subtype, g
return TRUE; /* success! */
}
gboolean wtap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
gboolean wtap_dump(wftap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err)
{
return (wdh->subtype_write)(wdh, phdr, pd, err);
return (wdh->subtype_write)(wdh, (void*)phdr, pd, err);
}
void wtap_dump_flush(wtap_dumper *wdh)
void wftap_dump_flush(wftap_dumper *wdh)
{
#ifdef HAVE_LIBZ
if(wdh->compressed) {
@ -2235,7 +2256,7 @@ void wtap_dump_flush(wtap_dumper *wdh)
}
}
gboolean wtap_dump_close(wtap_dumper *wdh, int *err)
gboolean wftap_dump_close(wftap_dumper *wdh, int *err)
{
gboolean ret = TRUE;
@ -2259,36 +2280,44 @@ gboolean wtap_dump_close(wtap_dumper *wdh, int *err)
}
} else {
/* as we don't close stdout, at least try to flush it */
wtap_dump_flush(wdh);
wftap_dump_flush(wdh);
}
if (wdh->priv != NULL)
g_free(wdh->priv);
if (wdh->tap_specific_data != NULL)
g_free(wdh->tap_specific_data);
g_free(wdh);
return ret;
}
gint64 wtap_get_bytes_dumped(wtap_dumper *wdh)
gint64 wftap_get_bytes_dumped(wftap_dumper *wdh)
{
return wdh->bytes_dumped;
}
void wtap_set_bytes_dumped(wtap_dumper *wdh, gint64 bytes_dumped)
void wftap_set_bytes_dumped(wftap_dumper *wdh, gint64 bytes_dumped)
{
wdh->bytes_dumped = bytes_dumped;
}
gboolean wtap_dump_set_addrinfo_list(wtap_dumper *wdh, addrinfo_lists_t *addrinfo_lists)
gboolean wtap_dump_set_addrinfo_list(wftap_dumper *wfdh, addrinfo_lists_t *addrinfo_lists)
{
if (!wdh || wdh->file_type_subtype < 0 || wdh->file_type_subtype >= wtap_num_file_types_subtypes
|| dump_open_table[wdh->file_type_subtype].has_name_resolution == FALSE)
wtap_dumper *wdh;
if (!wfdh || wfdh->file_type_subtype < 0 || wfdh->file_type_subtype >= wtap_num_file_types_subtypes
|| dump_open_table[wfdh->file_type_subtype].has_name_resolution == FALSE)
return FALSE;
wdh = (wtap_dumper*)wfdh->tap_specific_data;
wdh->addrinfo_lists = addrinfo_lists;
return TRUE;
}
/* internally open a file for writing (compressed or not) */
#ifdef HAVE_LIBZ
static WFILE_T wtap_dump_file_open(wtap_dumper *wdh, const char *filename)
static WFILE_T wftap_dump_file_open(wftap_dumper *wdh, const char *filename)
{
if(wdh->compressed) {
return gzwfile_open(filename);
@ -2297,7 +2326,7 @@ static WFILE_T wtap_dump_file_open(wtap_dumper *wdh, const char *filename)
}
}
#else
static WFILE_T wtap_dump_file_open(wtap_dumper *wdh _U_, const char *filename)
static WFILE_T wftap_dump_file_open(wftap_dumper *wdh _U_, const char *filename)
{
return ws_fopen(filename, "wb");
}
@ -2305,7 +2334,7 @@ static WFILE_T wtap_dump_file_open(wtap_dumper *wdh _U_, const char *filename)
/* internally open a file for writing (compressed or not) */
#ifdef HAVE_LIBZ
static WFILE_T wtap_dump_file_fdopen(wtap_dumper *wdh, int fd)
static WFILE_T wftap_dump_file_fdopen(wftap_dumper *wdh, int fd)
{
if(wdh->compressed) {
return gzwfile_fdopen(fd);
@ -2314,14 +2343,14 @@ static WFILE_T wtap_dump_file_fdopen(wtap_dumper *wdh, int fd)
}
}
#else
static WFILE_T wtap_dump_file_fdopen(wtap_dumper *wdh _U_, int fd)
static WFILE_T wftap_dump_file_fdopen(wftap_dumper *wdh, int fd)
{
return fdopen(fd, "wb");
}
#endif
/* internally writing raw bytes (compressed or not) */
gboolean wtap_dump_file_write(wtap_dumper *wdh, const void *buf, size_t bufsize,
gboolean wftap_dump_file_write(wftap_dumper *wdh, const void *buf, size_t bufsize,
int *err)
{
size_t nwritten;
@ -2356,7 +2385,7 @@ gboolean wtap_dump_file_write(wtap_dumper *wdh, const void *buf, size_t bufsize,
}
/* internally close a file for writing (compressed or not) */
static int wtap_dump_file_close(wtap_dumper *wdh)
static int wtap_dump_file_close(wftap_dumper *wdh)
{
#ifdef HAVE_LIBZ
if(wdh->compressed) {
@ -2368,7 +2397,7 @@ static int wtap_dump_file_close(wtap_dumper *wdh)
}
}
gint64 wtap_dump_file_seek(wtap_dumper *wdh, gint64 offset, int whence, int *err)
gint64 wftap_dump_file_seek(wftap_dumper *wdh, gint64 offset, int whence, int *err)
{
#ifdef HAVE_LIBZ
if(wdh->compressed) {
@ -2386,7 +2415,7 @@ gint64 wtap_dump_file_seek(wtap_dumper *wdh, gint64 offset, int whence, int *err
}
}
}
gint64 wtap_dump_file_tell(wtap_dumper *wdh, int *err)
gint64 wftap_dump_file_tell(wftap_dumper *wdh, int *err)
{
gint64 rval;
#ifdef HAVE_LIBZ

View File

@ -19,6 +19,7 @@
#include "config.h"
#include "wftap-int.h"
#include "wtap-int.h"
#include "file_wrappers.h"
#include "buffer.h"
@ -71,33 +72,35 @@ static gboolean hcidump_process_packet(FILE_T fh, struct wtap_pkthdr *phdr,
return wtap_read_packet_bytes(fh, buf, packet_size, err, err_info);
}
static gboolean hcidump_read(wtap *wth, int *err, gchar **err_info,
static gboolean hcidump_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset)
{
*data_offset = file_tell(wth->fh);
wtap* wth = (wtap*)wfth->tap_specific_data;
*data_offset = file_tell(wfth->fh);
return hcidump_process_packet(wth->fh, &wth->phdr, wth->frame_buffer,
return hcidump_process_packet(wfth->fh, &wth->phdr, wfth->frame_buffer,
err, err_info);
}
static gboolean hcidump_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
static gboolean hcidump_seek_read(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
struct wtap_pkthdr *phdr = (struct wtap_pkthdr *)header;
if (file_seek(wfth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
return hcidump_process_packet(wth->random_fh, phdr, buf, err, err_info);
return hcidump_process_packet(wfth->random_fh, phdr, buf, err, err_info);
}
int hcidump_open(wtap *wth, int *err, gchar **err_info)
int hcidump_open(wftap *wfth, int *err, gchar **err_info)
{
struct dump_hdr dh;
guint8 type;
int bytes_read;
bytes_read = file_read(&dh, DUMP_HDR_SIZE, wth->fh);
bytes_read = file_read(&dh, DUMP_HDR_SIZE, wfth->fh);
if (bytes_read != DUMP_HDR_SIZE) {
*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;
@ -107,9 +110,9 @@ int hcidump_open(wtap *wth, int *err, gchar **err_info)
|| GUINT16_FROM_LE(dh.len) < 1)
return 0;
bytes_read = file_read(&type, 1, wth->fh);
bytes_read = file_read(&type, 1, wfth->fh);
if (bytes_read != 1) {
*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;
@ -118,16 +121,16 @@ int hcidump_open(wtap *wth, int *err, gchar **err_info)
if (type < 1 || type > 4)
return 0;
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
if (file_seek(wfth->fh, 0, SEEK_SET, err) == -1)
return -1;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_HCIDUMP;
wth->file_encap = WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR;
wth->snapshot_length = 0;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_HCIDUMP;
wfth->file_encap = WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR;
wfth->snapshot_length = 0;
wth->subtype_read = hcidump_read;
wth->subtype_seek_read = hcidump_seek_read;
wth->tsprecision = WTAP_FILE_TSPREC_USEC;
wfth->subtype_read = hcidump_read;
wfth->subtype_seek_read = hcidump_seek_read;
wfth->tsprecision = WTAP_FILE_TSPREC_USEC;
return 1;
}

View File

@ -25,6 +25,6 @@
#include <wtap.h>
#include "ws_symbol_export.h"
int hcidump_open(wtap *wth, int *err, gchar **err_info);
int hcidump_open(wftap *wfth, int *err, gchar **err_info);
#endif

View File

@ -23,6 +23,7 @@
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include "wftap-int.h"
#include "wtap-int.h"
#include "file_wrappers.h"
#include "buffer.h"
@ -33,11 +34,11 @@ typedef struct {
gboolean byte_swapped;
} i4btrace_t;
static gboolean i4btrace_read(wtap *wth, int *err, gchar **err_info,
static gboolean i4btrace_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean i4btrace_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
static int i4b_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
static gboolean i4btrace_seek_read(wftap *wth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info);
static int i4b_read_rec(wftap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
Buffer *buf, int *err, gchar **err_info);
/*
@ -48,7 +49,7 @@ static int i4b_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
(unsigned)hdr.unit > 4 || (unsigned)hdr.type > 4 || \
(unsigned)hdr.dir > 2 || (unsigned)hdr.trunc > 2048))
int i4btrace_open(wtap *wth, int *err, gchar **err_info)
int i4btrace_open(wftap *wfth, int *err, gchar **err_info)
{
int bytes_read;
i4b_trace_hdr_t hdr;
@ -57,9 +58,9 @@ int i4btrace_open(wtap *wth, int *err, gchar **err_info)
/* I4B trace files have no magic in the header... Sigh */
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(&hdr, sizeof(hdr), wth->fh);
bytes_read = file_read(&hdr, sizeof(hdr), wfth->fh);
if (bytes_read != sizeof(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;
return 0;
@ -89,44 +90,46 @@ int i4btrace_open(wtap *wth, int *err, gchar **err_info)
byte_swapped = TRUE;
}
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
if (file_seek(wfth->fh, 0, SEEK_SET, err) == -1)
return -1;
/* Get capture start time */
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_I4BTRACE;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_I4BTRACE;
i4btrace = (i4btrace_t *)g_malloc(sizeof(i4btrace_t));
wth->priv = (void *)i4btrace;
wth->subtype_read = i4btrace_read;
wth->subtype_seek_read = i4btrace_seek_read;
wth->snapshot_length = 0; /* not known */
wfth->priv = (void *)i4btrace;
wfth->subtype_read = i4btrace_read;
wfth->subtype_seek_read = i4btrace_seek_read;
wfth->snapshot_length = 0; /* not known */
i4btrace->byte_swapped = byte_swapped;
wth->file_encap = WTAP_ENCAP_ISDN;
wth->tsprecision = WTAP_FILE_TSPREC_USEC;
wfth->file_encap = WTAP_ENCAP_ISDN;
wfth->tsprecision = WTAP_FILE_TSPREC_USEC;
return 1;
}
/* Read the next packet */
static gboolean i4btrace_read(wtap *wth, int *err, gchar **err_info,
static gboolean i4btrace_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset)
{
*data_offset = file_tell(wth->fh);
wtap* wth = (wtap*)wfth->tap_specific_data;
*data_offset = file_tell(wfth->fh);
return i4b_read_rec(wth, wth->fh, &wth->phdr, wth->frame_buffer,
return i4b_read_rec(wfth, wfth->fh, &wth->phdr, wfth->frame_buffer,
err, err_info);
}
static gboolean
i4btrace_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
i4btrace_seek_read(wftap *wfth, gint64 seek_off, void* header,
Buffer *buf, int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
struct wtap_pkthdr *phdr = (struct wtap_pkthdr *)header;
if (file_seek(wfth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
if (!i4b_read_rec(wth, wth->random_fh, phdr, buf, err, err_info)) {
if (!i4b_read_rec(wfth, wfth->random_fh, phdr, buf, err, err_info)) {
/* Read error or EOF */
if (*err == 0) {
/* EOF means "short read" in random-access mode */
@ -138,10 +141,10 @@ i4btrace_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
}
static int
i4b_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
i4b_read_rec(wftap *wfth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
int *err, gchar **err_info)
{
i4btrace_t *i4btrace = (i4btrace_t *)wth->priv;
i4btrace_t *i4btrace = (i4btrace_t *)wfth->priv;
i4b_trace_hdr_t hdr;
int bytes_read;
guint32 length;

View File

@ -26,6 +26,6 @@
#include <wtap.h>
#include "ws_symbol_export.h"
int i4btrace_open(wtap *wth, int *err, gchar **err_info);
int i4btrace_open(wftap *wfth, int *err, gchar **err_info);
#endif

View File

@ -63,6 +63,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "wftap-int.h"
#include "wtap-int.h"
#include "file_wrappers.h"
#include "buffer.h"
@ -86,13 +87,12 @@
#define RECORDS_FOR_IPFIX_CHECK 20
static gboolean
ipfix_read(wtap *wth, int *err, gchar **err_info,
ipfix_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean
ipfix_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
static void
ipfix_close(wtap *wth);
ipfix_seek_read(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info);
static void ipfix_close(wftap *wth);
#define IPFIX_VERSION 10
@ -184,7 +184,7 @@ ipfix_read_message(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, g
* like malformed format, -1 on bad error like file system
*/
int
ipfix_open(wtap *wth, int *err, gchar **err_info)
ipfix_open(wftap *wfth, int *err, gchar **err_info)
{
gint i, n, records_for_ipfix_check = RECORDS_FOR_IPFIX_CHECK;
gchar *s;
@ -208,7 +208,7 @@ ipfix_open(wtap *wth, int *err, gchar **err_info)
*/
for (i = 0; i < records_for_ipfix_check; i++) {
/* read first message header to check version */
if (!ipfix_read_message_header(&msg_hdr, wth->fh, err, err_info)) {
if (!ipfix_read_message_header(&msg_hdr, wfth->fh, err, err_info)) {
ipfix_debug3("ipfix_open: couldn't read message header #%d with err code #%d (%s)",
i, *err, *err_info);
if (*err == WTAP_ERR_BAD_FILE) {
@ -232,7 +232,7 @@ ipfix_open(wtap *wth, int *err, gchar **err_info)
*/
break;
}
if (file_seek(wth->fh, IPFIX_MSG_HDR_SIZE, SEEK_CUR, err) == -1) {
if (file_seek(wfth->fh, IPFIX_MSG_HDR_SIZE, SEEK_CUR, err) == -1) {
ipfix_debug1("ipfix_open: failed seek to next message in file, %d bytes away",
msg_hdr.message_length);
return 0;
@ -241,7 +241,7 @@ ipfix_open(wtap *wth, int *err, gchar **err_info)
/* check each Set in IPFIX Message for sanity */
while (checked_len < msg_hdr.message_length) {
wtap_file_read_expected_bytes(&set_hdr, IPFIX_SET_HDR_SIZE, wth->fh, err, err_info);
wtap_file_read_expected_bytes(&set_hdr, IPFIX_SET_HDR_SIZE, wfth->fh, err, err_info);
set_hdr.set_length = g_ntohs(set_hdr.set_length);
if ((set_hdr.set_length < IPFIX_SET_HDR_SIZE) ||
((set_hdr.set_length + checked_len) > msg_hdr.message_length)) {
@ -250,7 +250,7 @@ ipfix_open(wtap *wth, int *err, gchar **err_info)
return 0;
}
if (file_seek(wth->fh, set_hdr.set_length - IPFIX_SET_HDR_SIZE,
if (file_seek(wfth->fh, set_hdr.set_length - IPFIX_SET_HDR_SIZE,
SEEK_CUR, err) == -1)
{
ipfix_debug1("ipfix_open: failed seek to next set in file, %d bytes away",
@ -262,16 +262,16 @@ ipfix_open(wtap *wth, int *err, gchar **err_info)
}
/* all's good, this is a IPFIX file */
wth->file_encap = WTAP_ENCAP_RAW_IPFIX;
wth->snapshot_length = 0;
wth->tsprecision = WTAP_FILE_TSPREC_SEC;
wth->subtype_read = ipfix_read;
wth->subtype_seek_read = ipfix_seek_read;
wth->subtype_close = ipfix_close;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_IPFIX;
wfth->file_encap = WTAP_ENCAP_RAW_IPFIX;
wfth->snapshot_length = 0;
wfth->tsprecision = WTAP_FILE_TSPREC_SEC;
wfth->subtype_read = ipfix_read;
wfth->subtype_seek_read = ipfix_seek_read;
wfth->subtype_close = ipfix_close;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_IPFIX;
/* go back to beginning of file */
if (file_seek (wth->fh, 0, SEEK_SET, err) != 0)
if (file_seek (wfth->fh, 0, SEEK_SET, err) != 0)
{
return -1;
}
@ -281,12 +281,13 @@ ipfix_open(wtap *wth, int *err, gchar **err_info)
/* classic wtap: read packet */
static gboolean
ipfix_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
ipfix_read(wftap *wfth, int *err, gchar **err_info, gint64 *data_offset)
{
*data_offset = file_tell(wth->fh);
wtap* wth = (wtap*)wfth->tap_specific_data;
*data_offset = file_tell(wfth->fh);
ipfix_debug1("ipfix_read: data_offset is initially %" G_GINT64_MODIFIER "d", *data_offset);
if (!ipfix_read_message(wth->fh, &wth->phdr, wth->frame_buffer, err, err_info)) {
if (!ipfix_read_message(wfth->fh, &wth->phdr, wfth->frame_buffer, err, err_info)) {
ipfix_debug2("ipfix_read: couldn't read message header with code: %d\n, and error '%s'",
*err, *err_info);
return FALSE;
@ -298,11 +299,13 @@ ipfix_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
/* classic wtap: seek to file position and read packet */
static gboolean
ipfix_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
ipfix_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 right file position */
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) {
if (file_seek(wfth->random_fh, seek_off, SEEK_SET, err) == -1) {
ipfix_debug2("ipfix_seek_read: couldn't read message header with code: %d\n, and error '%s'",
*err, *err_info);
return FALSE; /* Seek error */
@ -310,7 +313,7 @@ ipfix_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
ipfix_debug1("ipfix_seek_read: reading at offset %" G_GINT64_MODIFIER "u", seek_off);
if (!ipfix_read_message(wth->random_fh, phdr, buf, err, err_info)) {
if (!ipfix_read_message(wfth->random_fh, phdr, buf, err, err_info)) {
ipfix_debug0("ipfix_seek_read: couldn't read message header");
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
@ -322,7 +325,7 @@ ipfix_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
/* classic wtap: close capture file */
static void
ipfix_close(wtap *wth _U_)
ipfix_close(wftap *wth _U_)
{
ipfix_debug0("ipfix_close: closing file");
}

View File

@ -25,6 +25,6 @@
#include <wtap.h>
#include "ws_symbol_export.h"
int ipfix_open(wtap *wth, int *err, gchar **err_info);
int ipfix_open(wftap *wfth, int *err, gchar **err_info);
#endif

View File

@ -22,6 +22,7 @@
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include "wftap-int.h"
#include "wtap-int.h"
#include "file_wrappers.h"
#include "buffer.h"
@ -31,15 +32,15 @@
#define IPTRACE_IFT_HF 0x3d /* Support for PERCS IP-HFI*/
#define IPTRACE_IFT_IB 0xc7 /* IP over Infiniband. Number by IANA */
static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info,
static gboolean iptrace_read_1_0(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean iptrace_seek_read_1_0(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
static gboolean iptrace_seek_read_1_0(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info);
static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info,
static gboolean iptrace_read_2_0(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean iptrace_seek_read_2_0(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
static gboolean iptrace_seek_read_2_0(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info);
static int iptrace_read_rec_header(FILE_T fh, guint8 *header, int header_len,
int *err, gchar **err_info);
@ -49,15 +50,15 @@ static void fill_in_pseudo_header(int encap,
union wtap_pseudo_header *pseudo_header, guint8 *header);
static int wtap_encap_ift(unsigned int ift);
int iptrace_open(wtap *wth, int *err, gchar **err_info)
int iptrace_open(wftap *wfth, int *err, gchar **err_info)
{
int bytes_read;
char name[12];
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(name, 11, wth->fh);
bytes_read = file_read(name, 11, wfth->fh);
if (bytes_read != 11) {
*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;
@ -65,16 +66,16 @@ int iptrace_open(wtap *wth, int *err, gchar **err_info)
name[11] = '\0';
if (strcmp(name, "iptrace 1.0") == 0) {
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_IPTRACE_1_0;
wth->subtype_read = iptrace_read_1_0;
wth->subtype_seek_read = iptrace_seek_read_1_0;
wth->tsprecision = WTAP_FILE_TSPREC_SEC;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_IPTRACE_1_0;
wfth->subtype_read = iptrace_read_1_0;
wfth->subtype_seek_read = iptrace_seek_read_1_0;
wfth->tsprecision = WTAP_FILE_TSPREC_SEC;
}
else if (strcmp(name, "iptrace 2.0") == 0) {
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_IPTRACE_2_0;
wth->subtype_read = iptrace_read_2_0;
wth->subtype_seek_read = iptrace_seek_read_2_0;
wth->tsprecision = WTAP_FILE_TSPREC_NSEC;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_IPTRACE_2_0;
wfth->subtype_read = iptrace_read_2_0;
wfth->subtype_seek_read = iptrace_seek_read_2_0;
wfth->tsprecision = WTAP_FILE_TSPREC_NSEC;
}
else {
return 0;
@ -214,13 +215,14 @@ iptrace_read_rec_1_0(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
}
/* Read the next packet */
static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info,
static gboolean iptrace_read_1_0(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset)
{
*data_offset = file_tell(wth->fh);
wtap* wth = (wtap*)wfth->tap_specific_data;
*data_offset = file_tell(wfth->fh);
/* Read the packet */
if (!iptrace_read_rec_1_0(wth->fh, &wth->phdr, wth->frame_buffer,
if (!iptrace_read_rec_1_0(wfth->fh, &wth->phdr, wfth->frame_buffer,
err, err_info)) {
/* Read error or EOF */
return FALSE;
@ -232,24 +234,25 @@ static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info,
If it *is* known, and it isn't this packet's encapsulation,
set it to WTAP_ENCAP_PER_PACKET, as this file doesn't
have a single encapsulation for all packets in the file. */
if (wth->file_encap == WTAP_ENCAP_UNKNOWN)
wth->file_encap = wth->phdr.pkt_encap;
if (wfth->file_encap == WTAP_ENCAP_UNKNOWN)
wfth->file_encap = wth->phdr.pkt_encap;
else {
if (wth->file_encap != wth->phdr.pkt_encap)
wth->file_encap = WTAP_ENCAP_PER_PACKET;
if (wfth->file_encap != wth->phdr.pkt_encap)
wfth->file_encap = WTAP_ENCAP_PER_PACKET;
}
return TRUE;
}
static gboolean iptrace_seek_read_1_0(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
static gboolean iptrace_seek_read_1_0(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
struct wtap_pkthdr *phdr = (struct wtap_pkthdr *)header;
if (file_seek(wfth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
/* Read the packet */
if (!iptrace_read_rec_1_0(wth->random_fh, phdr, buf, err, err_info)) {
if (!iptrace_read_rec_1_0(wfth->random_fh, phdr, buf, err, err_info)) {
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
return FALSE;
@ -409,13 +412,14 @@ iptrace_read_rec_2_0(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
}
/* Read the next packet */
static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info,
static gboolean iptrace_read_2_0(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset)
{
*data_offset = file_tell(wth->fh);
wtap* wth = (wtap*)wfth->tap_specific_data;
*data_offset = file_tell(wfth->fh);
/* Read the packet */
if (!iptrace_read_rec_2_0(wth->fh, &wth->phdr, wth->frame_buffer,
if (!iptrace_read_rec_2_0(wfth->fh, &wth->phdr, wfth->frame_buffer,
err, err_info)) {
/* Read error or EOF */
return FALSE;
@ -427,24 +431,25 @@ static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info,
If it *is* known, and it isn't this packet's encapsulation,
set it to WTAP_ENCAP_PER_PACKET, as this file doesn't
have a single encapsulation for all packets in the file. */
if (wth->file_encap == WTAP_ENCAP_UNKNOWN)
wth->file_encap = wth->phdr.pkt_encap;
if (wfth->file_encap == WTAP_ENCAP_UNKNOWN)
wfth->file_encap = wth->phdr.pkt_encap;
else {
if (wth->file_encap != wth->phdr.pkt_encap)
wth->file_encap = WTAP_ENCAP_PER_PACKET;
if (wfth->file_encap != wth->phdr.pkt_encap)
wfth->file_encap = WTAP_ENCAP_PER_PACKET;
}
return TRUE;
}
static gboolean iptrace_seek_read_2_0(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
static gboolean iptrace_seek_read_2_0(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
struct wtap_pkthdr *phdr = (struct wtap_pkthdr *)header;
if (file_seek(wfth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
/* Read the packet */
if (!iptrace_read_rec_2_0(wth->random_fh, phdr, buf, err, err_info)) {
if (!iptrace_read_rec_2_0(wfth->random_fh, phdr, buf, err, err_info)) {
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
return FALSE;

View File

@ -25,6 +25,6 @@
#include <glib.h>
#include <wtap.h>
int iptrace_open(wtap *wth, int *err, gchar **err_info);
int iptrace_open(wftap *wfth, int *err, gchar **err_info);
#endif

View File

@ -149,6 +149,7 @@ Number S/R Length Timer MAC Address MAC Address
*/
#include "config.h"
#include "wftap-int.h"
#include "wtap-int.h"
#include "buffer.h"
#include "iseries.h"
@ -179,15 +180,14 @@ typedef struct {
int format; /* Trace format type */
} iseries_t;
static gboolean iseries_read (wtap * wth, int *err, gchar ** err_info,
static gboolean iseries_read (wftap* wfth, int *err, gchar ** err_info,
gint64 *data_offset);
static gboolean iseries_seek_read (wtap * wth, gint64 seek_off,
struct wtap_pkthdr *phdr,
static gboolean iseries_seek_read (wftap * wfth, gint64 seek_off, void* header,
Buffer * buf, int *err, gchar ** err_info);
static gboolean iseries_check_file_type (wtap * wth, int *err, gchar **err_info,
static gboolean iseries_check_file_type (wftap * wth, int *err, gchar **err_info,
int format);
static gint64 iseries_seek_next_packet (wtap * wth, int *err, gchar **err_info);
static gboolean iseries_parse_packet (wtap * wth, FILE_T fh,
static gint64 iseries_seek_next_packet (wftap * wfth, int *err, gchar **err_info);
static gboolean iseries_parse_packet (wftap * wfth, FILE_T fh,
struct wtap_pkthdr *phdr,
Buffer * buf, int *err, gchar ** err_info);
static int iseries_UNICODE_to_ASCII (guint8 * buf, guint bytes);
@ -195,7 +195,7 @@ static gboolean iseries_parse_hex_string (const char * ascii, guint8 * buf,
size_t len);
int
iseries_open (wtap * wth, int *err, gchar ** err_info)
iseries_open (wftap* wfth, int *err, gchar ** err_info)
{
int bytes_read;
gint offset;
@ -211,10 +211,10 @@ iseries_open (wtap * wth, int *err, gchar ** err_info)
* by scanning for it in the first line
*/
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;
@ -227,7 +227,7 @@ iseries_open (wtap * wth, int *err, gchar ** err_info)
while ((unsigned)offset < (ISERIES_LINE_LENGTH - (sizeof unicodemagic)))
{
if (memcmp (magic + offset, unicodemagic, sizeof unicodemagic) == 0) {
if (file_seek (wth->fh, 0, SEEK_SET, err) == -1)
if (file_seek (wfth->fh, 0, SEEK_SET, err) == -1)
{
return 0;
}
@ -235,7 +235,7 @@ iseries_open (wtap * wth, int *err, gchar ** err_info)
* Do some basic sanity checking to ensure we can handle the
* contents of this trace
*/
if (!iseries_check_file_type (wth, err, err_info, ISERIES_FORMAT_UNICODE))
if (!iseries_check_file_type (wfth, err, err_info, ISERIES_FORMAT_UNICODE))
{
if (*err == 0)
return 0;
@ -243,14 +243,14 @@ iseries_open (wtap * wth, int *err, gchar ** err_info)
return -1;
}
wth->file_encap = WTAP_ENCAP_ETHERNET;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_ISERIES;
wth->snapshot_length = 0;
wth->subtype_read = iseries_read;
wth->subtype_seek_read = iseries_seek_read;
wth->tsprecision = WTAP_FILE_TSPREC_USEC;
wfth->file_encap = WTAP_ENCAP_ETHERNET;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_ISERIES;
wfth->snapshot_length = 0;
wfth->subtype_read = iseries_read;
wfth->subtype_seek_read = iseries_seek_read;
wfth->tsprecision = WTAP_FILE_TSPREC_USEC;
if (file_seek (wth->fh, 0, SEEK_SET, err) == -1)
if (file_seek (wfth->fh, 0, SEEK_SET, err) == -1)
{
return 0;
}
@ -267,7 +267,7 @@ iseries_open (wtap * wth, int *err, gchar ** err_info)
{
if (memcmp (magic + offset, ISERIES_HDR_MAGIC_STR, ISERIES_HDR_MAGIC_LEN) == 0)
{
if (file_seek (wth->fh, 0, SEEK_SET, err) == -1)
if (file_seek (wfth->fh, 0, SEEK_SET, err) == -1)
{
return 0;
}
@ -275,7 +275,7 @@ iseries_open (wtap * wth, int *err, gchar ** err_info)
* Do some basic sanity checking to ensure we can handle the
* contents of this trace
*/
if (!iseries_check_file_type (wth, err, err_info, ISERIES_FORMAT_ASCII))
if (!iseries_check_file_type (wfth, err, err_info, ISERIES_FORMAT_ASCII))
{
if (*err == 0)
return 0;
@ -283,14 +283,14 @@ iseries_open (wtap * wth, int *err, gchar ** err_info)
return -1;
}
wth->file_encap = WTAP_ENCAP_ETHERNET;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_ISERIES;
wth->snapshot_length = 0;
wth->subtype_read = iseries_read;
wth->subtype_seek_read = iseries_seek_read;
wth->tsprecision = WTAP_FILE_TSPREC_USEC;
wfth->file_encap = WTAP_ENCAP_ETHERNET;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_ISERIES;
wfth->snapshot_length = 0;
wfth->subtype_read = iseries_read;
wfth->subtype_seek_read = iseries_seek_read;
wfth->tsprecision = WTAP_FILE_TSPREC_USEC;
if (file_seek (wth->fh, 0, SEEK_SET, err) == -1)
if (file_seek (wfth->fh, 0, SEEK_SET, err) == -1)
{
return 0;
}
@ -309,7 +309,7 @@ iseries_open (wtap * wth, int *err, gchar ** err_info)
* requisit requirements and additional information.
*/
static gboolean
iseries_check_file_type (wtap * wth, int *err, gchar **err_info, int format)
iseries_check_file_type (wftap * wfth, int *err, gchar **err_info, int format)
{
guint line;
int num_items_scanned;
@ -318,16 +318,16 @@ iseries_check_file_type (wtap * wth, int *err, gchar **err_info, int format)
/* Save trace format for passing between packets */
iseries = (iseries_t *) g_malloc (sizeof (iseries_t));
wth->priv = (void *) iseries;
wfth->priv = (void *) iseries;
iseries->have_date = FALSE;
iseries->format = format;
for (line = 0; line < ISERIES_HDR_LINES_TO_CHECK; line++)
{
if (file_gets (buf, ISERIES_LINE_LENGTH, wth->fh) == NULL)
if (file_gets (buf, ISERIES_LINE_LENGTH, wfth->fh) == NULL)
{
/* EOF or error. */
*err = file_error (wth->fh, err_info);
*err = file_error (wfth->fh, err_info);
if (*err == WTAP_ERR_SHORT_READ)
*err = 0;
return FALSE;
@ -371,14 +371,15 @@ iseries_check_file_type (wtap * wth, int *err, gchar **err_info, int format)
* Find the next packet and parse it; called from wtap_read().
*/
static gboolean
iseries_read (wtap * wth, int *err, gchar ** err_info, gint64 *data_offset)
iseries_read (wftap* wfth, int *err, gchar ** err_info, gint64 *data_offset)
{
gint64 offset;
wtap* wth = (wtap*)wfth->tap_specific_data;
/*
* Locate the next packet
*/
offset = iseries_seek_next_packet (wth, err, err_info);
offset = iseries_seek_next_packet (wfth, err, err_info);
if (offset < 0)
return FALSE;
*data_offset = offset;
@ -386,7 +387,7 @@ iseries_read (wtap * wth, int *err, gchar ** err_info, gint64 *data_offset)
/*
* Parse the packet and extract the various fields
*/
return iseries_parse_packet (wth, wth->fh, &wth->phdr, wth->frame_buffer,
return iseries_parse_packet (wfth, wfth->fh, &wth->phdr, wfth->frame_buffer,
err, err_info);
}
@ -397,9 +398,9 @@ iseries_read (wtap * wth, int *err, gchar ** err_info, gint64 *data_offset)
* to null or an additional error string.
*/
static gint64
iseries_seek_next_packet (wtap * wth, int *err, gchar **err_info)
iseries_seek_next_packet (wftap* wfth, int *err, gchar **err_info)
{
iseries_t *iseries = (iseries_t *)wth->priv;
iseries_t *iseries = (iseries_t *)wfth->priv;
char buf[ISERIES_LINE_LENGTH],type[5];
int line, num_items_scanned;
gint64 cur_off;
@ -407,10 +408,10 @@ iseries_seek_next_packet (wtap * wth, int *err, gchar **err_info)
for (line = 0; line < ISERIES_MAX_TRACE_LEN; line++)
{
if (file_gets (buf, ISERIES_LINE_LENGTH, wth->fh) == NULL)
if (file_gets (buf, ISERIES_LINE_LENGTH, wfth->fh) == NULL)
{
/* EOF or error. */
*err = file_error (wth->fh, err_info);
*err = file_error (wfth->fh, err_info);
return -1;
}
/* Convert UNICODE to ASCII if required and determine */
@ -433,13 +434,13 @@ iseries_seek_next_packet (wtap * wth, int *err, gchar **err_info)
if (num_items_scanned == 1)
{
/* Rewind to beginning of line */
cur_off = file_tell (wth->fh);
cur_off = file_tell (wfth->fh);
if (cur_off == -1)
{
*err = file_error (wth->fh, err_info);
*err = file_error (wfth->fh, err_info);
return -1;
}
if (file_seek (wth->fh, cur_off - buflen, SEEK_SET, err) == -1)
if (file_seek (wfth->fh, cur_off - buflen, SEEK_SET, err) == -1)
{
return -1;
}
@ -458,18 +459,19 @@ iseries_seek_next_packet (wtap * wth, int *err, gchar **err_info)
* Read packets in random-access fashion
*/
static gboolean
iseries_seek_read (wtap * wth, gint64 seek_off, struct wtap_pkthdr *phdr,
iseries_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 packet location */
if (file_seek (wth->random_fh, seek_off - 1, SEEK_SET, err) == -1)
if (file_seek (wfth->random_fh, seek_off - 1, SEEK_SET, err) == -1)
return FALSE;
/*
* Parse the packet and extract the various fields
*/
return iseries_parse_packet (wth, wth->random_fh, phdr, buf,
return iseries_parse_packet (wfth, wfth->random_fh, phdr, buf,
err, err_info);
}
@ -555,10 +557,10 @@ done:
/* Parses a packet. */
static gboolean
iseries_parse_packet (wtap * wth, FILE_T fh, struct wtap_pkthdr *phdr,
iseries_parse_packet (wftap* wfth, FILE_T fh, struct wtap_pkthdr *phdr,
Buffer *buf, int *err, gchar **err_info)
{
iseries_t *iseries = (iseries_t *)wth->priv;
iseries_t *iseries = (iseries_t *)wfth->priv;
gint64 cur_off;
gboolean isValid, isCurrentPacket;
int num_items_scanned, line, pktline, buflen;

View File

@ -24,6 +24,6 @@
#include <glib.h>
#include <wtap.h>
int iseries_open(wtap *wth, int *err, gchar **err_info);
int iseries_open(wftap *wfth, int *err, gchar **err_info);
#endif

View File

@ -28,6 +28,7 @@
#include <string.h>
#include <errno.h>
#include "wftap-int.h"
#include "wtap-int.h"
#include "wtap.h"
#include "file_wrappers.h"
@ -623,8 +624,9 @@ process_packet_data(struct wtap_pkthdr *phdr, Buffer *target, guint8 *buffer,
phdr->pseudo_header.k12.stuff = k12;
}
static gboolean k12_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) {
k12_t *k12 = (k12_t *)wth->priv;
static gboolean k12_read(wftap *wfth, int *err, gchar **err_info, gint64 *data_offset) {
k12_t *k12 = (k12_t *)wfth->priv;
wtap* wth = (wtap*)wfth->tap_specific_data;
k12_src_desc_t* src_desc;
guint8* buffer;
gint64 offset;
@ -632,7 +634,7 @@ static gboolean k12_read(wtap *wth, int *err, gchar **err_info, gint64 *data_off
guint32 type;
guint32 src_id;
offset = file_tell(wth->fh);
offset = file_tell(wfth->fh);
/* ignore the record if it isn't a packet */
do {
@ -640,7 +642,7 @@ static gboolean k12_read(wtap *wth, int *err, gchar **err_info, gint64 *data_off
*data_offset = offset;
len = get_record(k12, wth->fh, offset, FALSE, err, err_info);
len = get_record(k12, wfth->fh, offset, FALSE, err, err_info);
if (len < 0) {
/* read error */
@ -679,25 +681,26 @@ static gboolean k12_read(wtap *wth, int *err, gchar **err_info, gint64 *data_off
} while ( ((type & K12_MASK_PACKET) != K12_REC_PACKET && (type & K12_MASK_PACKET) != K12_REC_D0020) || !src_id || !src_desc );
process_packet_data(&wth->phdr, wth->frame_buffer, buffer, len, k12);
process_packet_data(&wth->phdr, wfth->frame_buffer, buffer, len, k12);
return TRUE;
}
static gboolean k12_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) {
k12_t *k12 = (k12_t *)wth->priv;
static gboolean k12_seek_read(wftap *wfth, gint64 seek_off, void* header, Buffer *buf, int *err, gchar **err_info) {
struct wtap_pkthdr *phdr = (struct wtap_pkthdr *)header;
k12_t *k12 = (k12_t *)wfth->priv;
guint8* buffer;
gint len;
K12_DBG(5,("k12_seek_read: ENTER"));
if ( file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) {
if ( file_seek(wfth->random_fh, seek_off, SEEK_SET, err) == -1) {
K12_DBG(5,("k12_seek_read: SEEK ERROR"));
return FALSE;
}
len = get_record(k12, wth->random_fh, seek_off, TRUE, err, err_info);
len = get_record(k12, wfth->random_fh, seek_off, TRUE, err, err_info);
if (len < 0) {
K12_DBG(5,("k12_seek_read: READ ERROR"));
return FALSE;
@ -755,11 +758,11 @@ static void destroy_k12_file_data(k12_t* fd) {
g_free(fd);
}
static void k12_close(wtap *wth) {
k12_t *k12 = (k12_t *)wth->priv;
static void k12_close(wftap *wfth) {
k12_t *k12 = (k12_t *)wfth->priv;
destroy_k12_file_data(k12);
wth->priv = NULL; /* destroy_k12_file_data freed it */
wfth->priv = NULL; /* destroy_k12_file_data freed it */
#ifdef DEBUG_K12
K12_DBG(5,("k12_close: CLOSED"));
if (env_file) fclose(dbg_out);
@ -767,7 +770,7 @@ static void k12_close(wtap *wth) {
}
int k12_open(wtap *wth, int *err, gchar **err_info) {
int k12_open(wftap *wfth, int *err, gchar **err_info) {
k12_src_desc_t* rec;
guint8 header_buffer[0x200];
guint8* read_buffer;
@ -797,9 +800,9 @@ int k12_open(wtap *wth, int *err, gchar **err_info) {
K12_DBG(1,("k12_open: ENTER debug_level=%u",debug_level));
#endif
if ( file_read(header_buffer,0x200,wth->fh) != 0x200 ) {
if ( file_read(header_buffer,0x200,wfth->fh) != 0x200 ) {
K12_DBG(1,("k12_open: FILE HEADER TOO SHORT OR READ ERROR"));
*err = file_error(wth->fh, err_info);
*err = file_error(wfth->fh, err_info);
if (*err != 0 && *err != WTAP_ERR_SHORT_READ) {
return -1;
}
@ -825,7 +828,7 @@ int k12_open(wtap *wth, int *err, gchar **err_info) {
do {
len = get_record(file_data, wth->fh, offset, FALSE, err, err_info);
len = get_record(file_data, wfth->fh, offset, FALSE, err, err_info);
if ( len < 0 ) {
K12_DBG(1,("k12_open: BAD HEADER RECORD",len));
@ -863,7 +866,7 @@ int k12_open(wtap *wth, int *err, gchar **err_info) {
/*
* we are at the first packet record, rewind and leave.
*/
if (file_seek(wth->fh, offset, SEEK_SET, err) == -1) {
if (file_seek(wfth->fh, offset, SEEK_SET, err) == -1) {
destroy_k12_file_data(file_data);
return -1;
}
@ -993,14 +996,14 @@ int k12_open(wtap *wth, int *err, gchar **err_info) {
}
} while(1);
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_K12;
wth->file_encap = WTAP_ENCAP_K12;
wth->snapshot_length = 0;
wth->subtype_read = k12_read;
wth->subtype_seek_read = k12_seek_read;
wth->subtype_close = k12_close;
wth->priv = (void *)file_data;
wth->tsprecision = WTAP_FILE_TSPREC_NSEC;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_K12;
wfth->file_encap = WTAP_ENCAP_K12;
wfth->snapshot_length = 0;
wfth->subtype_read = k12_read;
wfth->subtype_seek_read = k12_seek_read;
wfth->subtype_close = k12_close;
wfth->priv = (void *)file_data;
wfth->tsprecision = WTAP_FILE_TSPREC_NSEC;
return 1;
}
@ -1024,24 +1027,24 @@ int k12_dump_can_write_encap(int encap) {
static const gchar dumpy_junk[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
static gboolean k12_dump_record(wtap_dumper *wdh, guint32 len, guint8* buffer, int *err_p) {
static gboolean k12_dump_record(wftap_dumper *wdh, guint32 len, guint8* buffer, int *err_p) {
k12_dump_t *k12 = (k12_dump_t *)wdh->priv;
guint32 junky_offset = (0x2000 - ( (k12->file_offset - 0x200) % 0x2000 )) % 0x2000;
if (len > junky_offset) {
if (junky_offset) {
if (! wtap_dump_file_write(wdh, buffer, junky_offset, err_p))
if (! wftap_dump_file_write(wdh, buffer, junky_offset, err_p))
return FALSE;
}
if (! wtap_dump_file_write(wdh, dumpy_junk, 0x10, err_p))
if (! wftap_dump_file_write(wdh, dumpy_junk, 0x10, err_p))
return FALSE;
if (! wtap_dump_file_write(wdh, buffer+junky_offset, len - junky_offset, err_p))
if (! wftap_dump_file_write(wdh, buffer+junky_offset, len - junky_offset, err_p))
return FALSE;
k12->file_offset += len + 0x10;
} else {
if (! wtap_dump_file_write(wdh, buffer, len, err_p))
if (! wftap_dump_file_write(wdh, buffer, len, err_p))
return FALSE;
k12->file_offset += len;
}
@ -1052,7 +1055,7 @@ static gboolean k12_dump_record(wtap_dumper *wdh, guint32 len, guint8* buffer,
static void k12_dump_src_setting(gpointer k _U_, gpointer v, gpointer p) {
k12_src_desc_t* src_desc = (k12_src_desc_t*)v;
wtap_dumper *wdh = (wtap_dumper *)p;
wftap_dumper *wdh = (wftap_dumper *)p;
guint32 len;
guint offset;
guint i;
@ -1158,7 +1161,7 @@ static void k12_dump_src_setting(gpointer k _U_, gpointer v, gpointer p) {
k12_dump_record(wdh,len,obj.buffer, &errxxx); /* fwrite errs ignored: see k12_dump below */
}
static gboolean k12_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
static gboolean k12_dump(wftap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err) {
const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header;
k12_dump_t *k12 = (k12_dump_t *)wdh->priv;
@ -1208,41 +1211,41 @@ static gboolean k12_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
static const guint8 k12_eof[] = {0xff,0xff};
static gboolean k12_dump_close(wtap_dumper *wdh, int *err) {
static gboolean k12_dump_close(wftap_dumper *wdh, int *err) {
k12_dump_t *k12 = (k12_dump_t *)wdh->priv;
union {
guint8 b[sizeof(guint32)];
guint32 u;
} d;
if (! wtap_dump_file_write(wdh, k12_eof, 2, err))
if (! wftap_dump_file_write(wdh, k12_eof, 2, err))
return FALSE;
if (wtap_dump_file_seek(wdh, 8, SEEK_SET, err) == -1)
if (wftap_dump_file_seek(wdh, 8, SEEK_SET, err) == -1)
return FALSE;
d.u = g_htonl(k12->file_len);
if (! wtap_dump_file_write(wdh, d.b, 4, err))
if (! wftap_dump_file_write(wdh, d.b, 4, err))
return FALSE;
d.u = g_htonl(k12->num_of_records);
if (! wtap_dump_file_write(wdh, d.b, 4, err))
if (! wftap_dump_file_write(wdh, d.b, 4, err))
return FALSE;
return TRUE;
}
gboolean k12_dump_open(wtap_dumper *wdh, int *err) {
gboolean k12_dump_open(wftap_dumper *wdh, int *err) {
k12_dump_t *k12;
if ( ! wtap_dump_file_write(wdh, k12_file_magic, 8, err)) {
if ( ! wftap_dump_file_write(wdh, k12_file_magic, 8, err)) {
return FALSE;
}
if (wtap_dump_file_seek(wdh, 0x200, SEEK_SET, err) == -1)
if (wftap_dump_file_seek(wdh, 0x200, SEEK_SET, err) == -1)
return FALSE;
wdh->subtype_write = k12_dump;

View File

@ -24,12 +24,12 @@
#include <glib.h>
#include <wtap.h>
int k12_open(wtap *wth, int *err, gchar **err_info);
int k12_open(wftap *wfth, int *err, gchar **err_info);
int k12_dump_can_write_encap(int encap);
gboolean k12_dump_open(wtap_dumper *wdh, int *err);
int k12text_open(wtap *wth, int *err, gchar **err_info _U_);
gboolean k12_dump_open(wftap_dumper *wdh, int *err);
int k12text_open(wftap *wfth, int *err, gchar **err_info _U_);
int k12text_dump_can_write_encap(int encap);
gboolean k12text_dump_open(wtap_dumper *wdh, int *err);
gboolean k12text_dump_open(wftap_dumper *wdh, int *err);
#endif

View File

@ -72,6 +72,7 @@
#include <string.h>
#include <errno.h>
#include <time.h>
#include "wftap-int.h"
#include "wtap-int.h"
#include "wtap.h"
#include "file_wrappers.h"
@ -245,9 +246,10 @@ k12text_reset(FILE_T fh)
}
static gboolean
k12text_read(wtap *wth, int *err, char ** err_info, gint64 *data_offset)
k12text_read(wftap *wfth, int *err, char ** err_info, gint64 *data_offset)
{
k12text_t *k12text = (k12text_t *)wth->priv;
k12text_t *k12text = (k12text_t *)wfth->priv;
wtap* wth = (wtap*)wfth->tap_specific_data;
/*
* We seek to the file position after the end of the previous frame
@ -258,10 +260,10 @@ k12text_read(wtap *wth, int *err, char ** err_info, gint64 *data_offset)
* init vars set by lexer.
*/
if ( file_seek(wth->fh, k12text->next_frame_offset, SEEK_SET, err) == -1) {
if ( file_seek(wfth->fh, k12text->next_frame_offset, SEEK_SET, err) == -1) {
return FALSE;
}
k12text_reset(wth->fh); /* init lexer buffer and vars set by lexer */
k12text_reset(wfth->fh); /* init lexer buffer and vars set by lexer */
BEGIN(NEXT_FRAME);
yylex();
@ -282,19 +284,20 @@ k12text_read(wtap *wth, int *err, char ** err_info, gint64 *data_offset)
k12text_set_headers(&wth->phdr);
buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
memcpy(buffer_start_ptr(wth->frame_buffer), bb, wth->phdr.caplen);
buffer_assure_space(wfth->frame_buffer, wth->phdr.caplen);
memcpy(buffer_start_ptr(wfth->frame_buffer), bb, wth->phdr.caplen);
return TRUE;
}
static gboolean
k12text_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, char **err_info)
k12text_seek_read(wftap *wfth, gint64 seek_off, void* header, Buffer *buf, int *err, char **err_info)
{
if ( file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) {
struct wtap_pkthdr *phdr = (struct wtap_pkthdr *)header;
if ( file_seek(wfth->random_fh, seek_off, SEEK_SET, err) == -1) {
return FALSE;
}
k12text_reset(wth->random_fh); /* init lexer buffer and vars set by lexer */
k12text_reset(wfth->random_fh); /* init lexer buffer and vars set by lexer */
BEGIN(NEXT_FRAME);
yylex();
@ -319,30 +322,30 @@ k12text_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *
}
int
k12text_open(wtap *wth, int *err, gchar **err_info _U_)
k12text_open(wftap *wfth, int *err, gchar **err_info _U_)
{
k12text_t *k12text;
k12text_reset(wth->fh); /* init lexer buffer and vars set by lexer */
k12text_reset(wfth->fh); /* init lexer buffer and vars set by lexer */
BEGIN(MAGIC);
yylex();
if (! is_k12text) return 0;
if ( file_seek(wth->fh, 0, SEEK_SET, err) == -1) {
if ( file_seek(wfth->fh, 0, SEEK_SET, err) == -1) {
return -1;
}
k12text = (k12text_t *)g_malloc(sizeof(k12text_t));
wth->priv = (void *)k12text;
wfth->priv = (void *)k12text;
k12text->next_frame_offset = 0;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_K12TEXT;
wth->file_encap = WTAP_ENCAP_PER_PACKET;
wth->snapshot_length = 0;
wth->subtype_read = k12text_read;
wth->subtype_seek_read = k12text_seek_read;
wth->tsprecision = WTAP_FILE_TSPREC_NSEC;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_K12TEXT;
wfth->file_encap = WTAP_ENCAP_PER_PACKET;
wfth->snapshot_length = 0;
wfth->subtype_read = k12text_read;
wfth->subtype_seek_read = k12text_seek_read;
wfth->tsprecision = WTAP_FILE_TSPREC_NSEC;
return 1;
}
@ -359,7 +362,7 @@ static const struct { int e; const char* s; } encaps[] = {
};
static gboolean
k12text_dump(wtap_dumper *wdh _U_, const struct wtap_pkthdr *phdr,
k12text_dump(wftap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err) {
#define K12BUF_SIZE 196808
char *buf;
@ -422,7 +425,7 @@ k12text_dump(wtap_dumper *wdh _U_, const struct wtap_pkthdr *phdr,
wl = g_snprintf(p, left, "\r\n\r\n");
left -= wl;
ret = wtap_dump_file_write(wdh, buf, K12BUF_SIZE - left, err);
ret = wftap_dump_file_write(wdh, buf, K12BUF_SIZE - left, err);
g_free(buf);
return ret;
@ -430,17 +433,17 @@ k12text_dump(wtap_dumper *wdh _U_, const struct wtap_pkthdr *phdr,
gboolean
k12text_dump_open(wtap_dumper *wdh, int *err _U_)
k12text_dump_open(wftap_dumper *wdh, int *err _U_)
{
wdh->subtype_write = k12text_dump;
wdh->subtype_write = k12text_dump;
return TRUE;
return TRUE;
}
int
k12text_dump_can_write_encap(int encap)
{
switch (encap) {
switch (encap) {
case WTAP_ENCAP_PER_PACKET:
case WTAP_ENCAP_ETHERNET:
case WTAP_ENCAP_MTP3:
@ -450,7 +453,7 @@ k12text_dump_can_write_encap(int encap)
case WTAP_ENCAP_ATM_PDUS:
default:
return WTAP_ERR_UNSUPPORTED_ENCAP;
}
}
}
/*

View File

@ -21,6 +21,7 @@
#include "config.h"
#include <stdlib.h>
#include <errno.h>
#include "wftap-int.h"
#include "wtap-int.h"
#include "file_wrappers.h"
#include "buffer.h"
@ -270,13 +271,13 @@ typedef struct {
time_t start;
} lanalyzer_t;
static gboolean lanalyzer_read(wtap *wth, int *err, gchar **err_info,
static gboolean lanalyzer_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean lanalyzer_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
static gboolean lanalyzer_dump_close(wtap_dumper *wdh, int *err);
static gboolean lanalyzer_seek_read(wftap *wth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info);
static gboolean lanalyzer_dump_close(wftap_dumper *wdh, int *err);
int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
int lanalyzer_open(wftap *wfth, int *err, gchar **err_info)
{
int bytes_read;
LA_RecordHeader rec_header;
@ -289,11 +290,12 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
guint16 cr_year;
struct tm tm;
lanalyzer_t *lanalyzer;
wtap* wth = (wtap*)wfth->tap_specific_data;
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(&rec_header, LA_RecordHeaderSize, wth->fh);
bytes_read = file_read(&rec_header, LA_RecordHeaderSize, wfth->fh);
if (bytes_read != LA_RecordHeaderSize) {
*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;
@ -313,9 +315,9 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
*/
return 0;
}
bytes_read = file_read(&header_fixed, sizeof header_fixed, wth->fh);
bytes_read = file_read(&header_fixed, sizeof header_fixed, wfth->fh);
if (bytes_read != sizeof header_fixed) {
*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;
@ -325,9 +327,9 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
if (record_length != 0) {
/* Read the rest of the record as a comment. */
comment = (char *)g_malloc(record_length + 1);
bytes_read = file_read(comment, record_length, wth->fh);
bytes_read = file_read(comment, record_length, wfth->fh);
if (bytes_read != record_length) {
*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;
@ -337,22 +339,22 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
}
/* If we made it this far, then the file is a LANAlyzer file.
* Let's get some info from it. Note that we get wth->snapshot_length
* Let's get some info from it. Note that we get wfth->snapshot_length
* from a record later in the file. */
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_LANALYZER;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_LANALYZER;
lanalyzer = (lanalyzer_t *)g_malloc(sizeof(lanalyzer_t));
wth->priv = (void *)lanalyzer;
wth->subtype_read = lanalyzer_read;
wth->subtype_seek_read = lanalyzer_seek_read;
wth->snapshot_length = 0;
wth->tsprecision = WTAP_FILE_TSPREC_NSEC;
wfth->priv = (void *)lanalyzer;
wfth->subtype_read = lanalyzer_read;
wfth->subtype_seek_read = lanalyzer_seek_read;
wfth->snapshot_length = 0;
wfth->tsprecision = WTAP_FILE_TSPREC_NSEC;
/* Read records until we find the start of packets */
while (1) {
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(&rec_header, LA_RecordHeaderSize, wth->fh);
bytes_read = file_read(&rec_header, LA_RecordHeaderSize, wfth->fh);
if (bytes_read != LA_RecordHeaderSize) {
*err = file_error(wth->fh, err_info);
*err = file_error(wfth->fh, err_info);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
return -1;
@ -367,9 +369,9 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
case RT_Summary:
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(summary, sizeof summary,
wth->fh);
wfth->fh);
if (bytes_read != sizeof summary) {
*err = file_error(wth->fh, err_info);
*err = file_error(wfth->fh, err_info);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
return -1;
@ -401,15 +403,15 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
/*g_message("Day %d Month %d Year %d", tm.tm_mday,
tm.tm_mon, tm.tm_year);*/
mxslc = pletoh16(&summary[30]);
wth->snapshot_length = mxslc;
wfth->snapshot_length = mxslc;
board_type = pletoh16(&summary[188]);
switch (board_type) {
case BOARD_325:
wth->file_encap = WTAP_ENCAP_ETHERNET;
wfth->file_encap = WTAP_ENCAP_ETHERNET;
break;
case BOARD_325TR:
wth->file_encap = WTAP_ENCAP_TOKEN_RING;
wfth->file_encap = WTAP_ENCAP_TOKEN_RING;
break;
default:
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
@ -423,13 +425,13 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
case RT_PacketData:
/* Go back header number of bytes so that lanalyzer_read
* can read this header */
if (file_seek(wth->fh, -LA_RecordHeaderSize, SEEK_CUR, err) == -1) {
if (file_seek(wfth->fh, -LA_RecordHeaderSize, SEEK_CUR, err) == -1) {
return -1;
}
return 1;
default:
if (file_seek(wth->fh, record_length, SEEK_CUR, err) == -1) {
if (file_seek(wfth->fh, record_length, SEEK_CUR, err) == -1) {
return -1;
}
break;
@ -439,7 +441,7 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
#define DESCRIPTOR_LEN 32
static gboolean lanalyzer_read_trace_record(wtap *wth, FILE_T fh,
static gboolean lanalyzer_read_trace_record(wftap *wfth, FILE_T fh,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
{
int bytes_read;
@ -531,7 +533,7 @@ static gboolean lanalyzer_read_trace_record(wtap *wth, FILE_T fh,
t = (((guint64)time_low) << 0) + (((guint64)time_med) << 16) +
(((guint64)time_high) << 32);
tsecs = (time_t) (t/2000000);
lanalyzer = (lanalyzer_t *)wth->priv;
lanalyzer = (lanalyzer_t *)wfth->priv;
phdr->ts.secs = tsecs + lanalyzer->start;
phdr->ts.nsecs = ((guint32) (t - tsecs*2000000)) * 500;
@ -547,7 +549,7 @@ static gboolean lanalyzer_read_trace_record(wtap *wth, FILE_T fh,
phdr->len = true_size;
phdr->caplen = packet_size;
switch (wth->file_encap) {
switch (wfth->file_encap) {
case WTAP_ENCAP_ETHERNET:
/* We assume there's no FCS in this frame. */
@ -560,24 +562,26 @@ static gboolean lanalyzer_read_trace_record(wtap *wth, FILE_T fh,
}
/* Read the next packet */
static gboolean lanalyzer_read(wtap *wth, int *err, gchar **err_info,
static gboolean lanalyzer_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset)
{
*data_offset = file_tell(wth->fh);
wtap* wth = (wtap*)wfth->tap_specific_data;
*data_offset = file_tell(wfth->fh);
/* Read the record */
return lanalyzer_read_trace_record(wth, wth->fh, &wth->phdr,
wth->frame_buffer, err, err_info);
return lanalyzer_read_trace_record(wfth, wfth->fh, &wth->phdr,
wfth->frame_buffer, err, err_info);
}
static gboolean lanalyzer_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
static gboolean lanalyzer_seek_read(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
struct wtap_pkthdr *phdr = (struct wtap_pkthdr *)header;
if (file_seek(wfth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
/* Read the record */
if (!lanalyzer_read_trace_record(wth, wth->random_fh, phdr, buf,
if (!lanalyzer_read_trace_record(wfth, wfth->random_fh, phdr, buf,
err, err_info)) {
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
@ -590,14 +594,14 @@ static gboolean lanalyzer_seek_read(wtap *wth, gint64 seek_off,
* Returns TRUE on success, FALSE on error
* Write "cnt" bytes of zero with error control
*---------------------------------------------------*/
static gboolean s0write(wtap_dumper *wdh, size_t cnt, int *err)
static gboolean s0write(wftap_dumper *wdh, size_t cnt, int *err)
{
size_t snack;
while (cnt) {
snack = cnt > 64 ? 64 : cnt;
if (!wtap_dump_file_write(wdh, z64, snack, err))
if (!wftap_dump_file_write(wdh, z64, snack, err))
return FALSE;
cnt -= snack;
}
@ -608,25 +612,25 @@ static gboolean s0write(wtap_dumper *wdh, size_t cnt, int *err)
* Returns TRUE on success, FALSE on error
* Write an 8-bit value with error control
*---------------------------------------------------*/
static gboolean s8write(wtap_dumper *wdh, const guint8 s8, int *err)
static gboolean s8write(wftap_dumper *wdh, const guint8 s8, int *err)
{
return wtap_dump_file_write(wdh, &s8, 1, err);
return wftap_dump_file_write(wdh, &s8, 1, err);
}
/*---------------------------------------------------
* Returns TRUE on success, FALSE on error
* Write a 16-bit value with error control
*---------------------------------------------------*/
static gboolean s16write(wtap_dumper *wdh, const guint16 s16, int *err)
static gboolean s16write(wftap_dumper *wdh, const guint16 s16, int *err)
{
return wtap_dump_file_write(wdh, &s16, 2, err);
return wftap_dump_file_write(wdh, &s16, 2, err);
}
/*---------------------------------------------------
* Returns TRUE on success, FALSE on error
* Write a 32-bit value with error control
*---------------------------------------------------*/
static gboolean s32write(wtap_dumper *wdh, const guint32 s32, int *err)
static gboolean s32write(wftap_dumper *wdh, const guint32 s32, int *err)
{
return wtap_dump_file_write(wdh, &s32, 4, err);
return wftap_dump_file_write(wdh, &s32, 4, err);
}
/*---------------------------------------------------
*
@ -649,7 +653,7 @@ static void my_timersub(const struct timeval *a,
* Write a record for a packet to a dump file.
* Returns TRUE on success, FALSE on failure.
*---------------------------------------------------*/
static gboolean lanalyzer_dump(wtap_dumper *wdh,
static gboolean lanalyzer_dump(wftap_dumper *wdh,
const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err)
{
@ -726,7 +730,7 @@ static gboolean lanalyzer_dump(wtap_dumper *wdh,
if (!s0write(wdh, 12, err))
return FALSE;
if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err))
if (!wftap_dump_file_write(wdh, pd, phdr->caplen, err))
return FALSE;
wdh->bytes_dumped += thisSize;
@ -757,16 +761,16 @@ int lanalyzer_dump_can_write_encap(int encap)
* Returns TRUE on success, FALSE on failure; sets "*err" to an
* error code on failure
*---------------------------------------------------*/
gboolean lanalyzer_dump_open(wtap_dumper *wdh, int *err)
gboolean lanalyzer_dump_open(wftap_dumper *wdh, int *err)
{
int jump;
void *tmp;
tmp = g_malloc(sizeof(LA_TmpInfo));
if (!tmp) {
*err = errno;
return FALSE;
}
*err = errno;
return FALSE;
}
((LA_TmpInfo*)tmp)->init = FALSE;
wdh->priv = tmp;
@ -788,8 +792,8 @@ gboolean lanalyzer_dump_open(wtap_dumper *wdh, int *err)
+ sizeof (LA_CyclicInformationFake)
+ LA_IndexRecordSize;
if (wtap_dump_file_seek(wdh, jump, SEEK_SET, err) == -1)
return FALSE;
if (wftap_dump_file_seek(wdh, jump, SEEK_SET, err) == -1)
return FALSE;
wdh->bytes_dumped = jump;
return TRUE;
@ -798,7 +802,7 @@ gboolean lanalyzer_dump_open(wtap_dumper *wdh, int *err)
/*---------------------------------------------------
*
*---------------------------------------------------*/
static gboolean lanalyzer_dump_header(wtap_dumper *wdh, int *err)
static gboolean lanalyzer_dump_header(wftap_dumper *wdh, int *err)
{
LA_TmpInfo *itmp = (LA_TmpInfo*)(wdh->priv);
guint16 board_type = itmp->encap == WTAP_ENCAP_TOKEN_RING
@ -818,27 +822,27 @@ static gboolean lanalyzer_dump_header(wtap_dumper *wdh, int *err)
if (fT == NULL)
return FALSE;
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;
if (!wtap_dump_file_write(wdh, &LA_HeaderRegularFake,
if (!wftap_dump_file_write(wdh, &LA_HeaderRegularFake,
sizeof LA_HeaderRegularFake, err))
return FALSE;
if (!wtap_dump_file_write(wdh, &LA_RxChannelNameFake,
return FALSE;
if (!wftap_dump_file_write(wdh, &LA_RxChannelNameFake,
sizeof LA_RxChannelNameFake, err))
return FALSE;
if (!wtap_dump_file_write(wdh, &LA_TxChannelNameFake,
return FALSE;
if (!wftap_dump_file_write(wdh, &LA_TxChannelNameFake,
sizeof LA_TxChannelNameFake, err))
return FALSE;
if (!wtap_dump_file_write(wdh, &LA_RxTemplateNameFake,
return FALSE;
if (!wftap_dump_file_write(wdh, &LA_RxTemplateNameFake,
sizeof LA_RxTemplateNameFake, err))
return FALSE;
if (!wtap_dump_file_write(wdh, &LA_TxTemplateNameFake,
return FALSE;
if (!wftap_dump_file_write(wdh, &LA_TxTemplateNameFake,
sizeof LA_TxTemplateNameFake, err))
return FALSE;
if (!wtap_dump_file_write(wdh, &LA_DisplayOptionsFake,
return FALSE;
if (!wftap_dump_file_write(wdh, &LA_DisplayOptionsFake,
sizeof LA_DisplayOptionsFake, err))
return FALSE;
return FALSE;
/*-----------------------------------------------------------------*/
if (!s16write(wdh, GUINT16_TO_LE(RT_Summary), err)) /* rid */
return FALSE;
@ -911,7 +915,7 @@ static gboolean lanalyzer_dump_header(wtap_dumper *wdh, int *err)
if (!s32write(wdh, GUINT32_TO_LE(itmp->pkts), err)) /* ssr.totpkts */
return FALSE;
/*-----------------------------------------------------------------*/
if (!wtap_dump_file_write(wdh, &LA_CyclicInformationFake,
if (!wftap_dump_file_write(wdh, &LA_CyclicInformationFake,
sizeof LA_CyclicInformationFake, err))
return FALSE;
/*-----------------------------------------------------------------*/
@ -931,7 +935,7 @@ static gboolean lanalyzer_dump_header(wtap_dumper *wdh, int *err)
* Finish writing to a dump file.
* Returns TRUE on success, FALSE on failure.
*---------------------------------------------------*/
static gboolean lanalyzer_dump_close(wtap_dumper *wdh, int *err)
static gboolean lanalyzer_dump_close(wftap_dumper *wdh, int *err)
{
lanalyzer_dump_header(wdh,err);
return *err ? FALSE : TRUE;

View File

@ -24,8 +24,8 @@
#include <glib.h>
#include <wtap.h>
int lanalyzer_open(wtap *wth, int *err, gchar **err_info);
gboolean lanalyzer_dump_open(wtap_dumper *wdh, int *err);
int lanalyzer_open(wftap *wfth, int *err, gchar **err_info);
gboolean lanalyzer_dump_open(wftap_dumper *wdh, int *err);
int lanalyzer_dump_can_write_encap(int encap);
#endif

View File

@ -23,6 +23,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "wftap-int.h"
#include "wtap-int.h"
#include "file_wrappers.h"
#include "buffer.h"
@ -61,21 +62,21 @@ typedef enum {
BAD_READ, /* the file is probably not valid */
OTHER_FORMAT /* the file may be valid, but not in this format */
} libpcap_try_t;
static libpcap_try_t libpcap_try(wtap *wth, int *err);
static libpcap_try_t libpcap_try(wftap *wfth, int *err);
static gboolean libpcap_read(wtap *wth, int *err, gchar **err_info,
static gboolean libpcap_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean libpcap_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
static int libpcap_read_header(wtap *wth, FILE_T fh, int *err, gchar **err_info,
static gboolean libpcap_seek_read(wftap *wth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info);
static int libpcap_read_header(wftap *wfth, FILE_T fh, int *err, gchar **err_info,
struct pcaprec_ss990915_hdr *hdr);
static void adjust_header(wtap *wth, struct pcaprec_hdr *hdr);
static gboolean libpcap_read_packet(wtap *wth, FILE_T fh,
static void adjust_header(wftap *wfth, struct pcaprec_hdr *hdr);
static gboolean libpcap_read_packet(wftap *wfth, FILE_T fh,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
static gboolean libpcap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
static gboolean libpcap_dump(wftap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err);
int libpcap_open(wtap *wth, int *err, gchar **err_info)
int libpcap_open(wftap *wfth, int *err, gchar **err_info)
{
int bytes_read;
guint32 magic;
@ -86,12 +87,13 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
int file_encap;
gint64 first_packet_offset;
libpcap_t *libpcap;
wtap* wth = (wtap*)wfth->tap_specific_data;
/* Read in the number that should be at the start of a "libpcap" 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;
@ -104,7 +106,7 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
a program using either standard or ss990417 libpcap. */
byte_swapped = FALSE;
modified = FALSE;
wth->tsprecision = WTAP_FILE_TSPREC_USEC;
wfth->tsprecision = WTAP_FILE_TSPREC_USEC;
break;
case PCAP_MODIFIED_MAGIC:
@ -112,7 +114,7 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
a program using either ss990915 or ss991029 libpcap. */
byte_swapped = FALSE;
modified = TRUE;
wth->tsprecision = WTAP_FILE_TSPREC_USEC;
wfth->tsprecision = WTAP_FILE_TSPREC_USEC;
break;
case PCAP_SWAPPED_MAGIC:
@ -121,7 +123,7 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
ss990417 libpcap. */
byte_swapped = TRUE;
modified = FALSE;
wth->tsprecision = WTAP_FILE_TSPREC_USEC;
wfth->tsprecision = WTAP_FILE_TSPREC_USEC;
break;
case PCAP_SWAPPED_MODIFIED_MAGIC:
@ -130,7 +132,7 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
or ss991029 libpcap. */
byte_swapped = TRUE;
modified = TRUE;
wth->tsprecision = WTAP_FILE_TSPREC_USEC;
wfth->tsprecision = WTAP_FILE_TSPREC_USEC;
break;
case PCAP_NSEC_MAGIC:
@ -139,7 +141,7 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
except that the time stamps have nanosecond resolution. */
byte_swapped = FALSE;
modified = FALSE;
wth->tsprecision = WTAP_FILE_TSPREC_NSEC;
wfth->tsprecision = WTAP_FILE_TSPREC_NSEC;
break;
case PCAP_SWAPPED_NSEC_MAGIC:
@ -149,7 +151,7 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
nanosecond resolution. */
byte_swapped = TRUE;
modified = FALSE;
wth->tsprecision = WTAP_FILE_TSPREC_NSEC;
wfth->tsprecision = WTAP_FILE_TSPREC_NSEC;
break;
default:
@ -159,9 +161,9 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
/* Read the rest of the header. */
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(&hdr, sizeof hdr, wth->fh);
bytes_read = file_read(&hdr, sizeof hdr, wfth->fh);
if (bytes_read != sizeof 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;
@ -256,11 +258,11 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
libpcap->byte_swapped = byte_swapped;
libpcap->version_major = hdr.version_major;
libpcap->version_minor = hdr.version_minor;
wth->priv = (void *)libpcap;
wth->subtype_read = libpcap_read;
wth->subtype_seek_read = libpcap_seek_read;
wth->file_encap = file_encap;
wth->snapshot_length = hdr.snaplen;
wfth->priv = (void *)libpcap;
wfth->subtype_read = libpcap_read;
wfth->subtype_seek_read = libpcap_seek_read;
wfth->file_encap = file_encap;
wfth->snapshot_length = hdr.snaplen;
/* In file format version 2.3, the order of the "incl_len" and
"orig_len" fields in the per-packet header was reversed,
@ -307,8 +309,8 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
* and for the ERF link-layer header type, and set the
* precision to nanosecond precision.
*/
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_PCAP_AIX;
wth->tsprecision = WTAP_FILE_TSPREC_NSEC;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_PCAP_AIX;
wfth->tsprecision = WTAP_FILE_TSPREC_NSEC;
return 1;
}
@ -352,9 +354,9 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
*
* Try ss991029, the last of his patches, first.
*/
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_PCAP_SS991029;
first_packet_offset = file_tell(wth->fh);
switch (libpcap_try(wth, err)) {
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_PCAP_SS991029;
first_packet_offset = file_tell(wfth->fh);
switch (libpcap_try(wfth, err)) {
case BAD_READ:
/*
@ -368,7 +370,7 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
* Well, it looks as if it might be 991029.
* Put the seek pointer back, and finish.
*/
if (file_seek(wth->fh, first_packet_offset, SEEK_SET, err) == -1) {
if (file_seek(wfth->fh, first_packet_offset, SEEK_SET, err) == -1) {
return -1;
}
goto done;
@ -387,8 +389,8 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
* so we put the seek pointer back and treat
* it as 990915.
*/
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_PCAP_SS990915;
if (file_seek(wth->fh, first_packet_offset, SEEK_SET, err) == -1) {
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_PCAP_SS990915;
if (file_seek(wfth->fh, first_packet_offset, SEEK_SET, err) == -1) {
return -1;
}
} else {
@ -397,13 +399,13 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
*
* Try the standard format first.
*/
if(wth->tsprecision == WTAP_FILE_TSPREC_NSEC) {
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC;
if(wfth->tsprecision == WTAP_FILE_TSPREC_NSEC) {
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC;
} else {
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_PCAP;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_PCAP;
}
first_packet_offset = file_tell(wth->fh);
switch (libpcap_try(wth, err)) {
first_packet_offset = file_tell(wfth->fh);
switch (libpcap_try(wfth, err)) {
case BAD_READ:
/*
@ -418,7 +420,7 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
* libpcap file.
* Put the seek pointer back, and finish.
*/
if (file_seek(wth->fh, first_packet_offset, SEEK_SET, err) == -1) {
if (file_seek(wfth->fh, first_packet_offset, SEEK_SET, err) == -1) {
return -1;
}
goto done;
@ -435,11 +437,11 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
* a standard file. Put the seek pointer back and try
* ss990417.
*/
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_PCAP_SS990417;
if (file_seek(wth->fh, first_packet_offset, SEEK_SET, err) == -1) {
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_PCAP_SS990417;
if (file_seek(wfth->fh, first_packet_offset, SEEK_SET, err) == -1) {
return -1;
}
switch (libpcap_try(wth, err)) {
switch (libpcap_try(wfth, err)) {
case BAD_READ:
/*
@ -453,7 +455,7 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
* Well, it looks as if it might be ss990417.
* Put the seek pointer back, and finish.
*/
if (file_seek(wth->fh, first_packet_offset, SEEK_SET, err) == -1) {
if (file_seek(wfth->fh, first_packet_offset, SEEK_SET, err) == -1) {
return -1;
}
goto done;
@ -472,8 +474,8 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
* to try after that, so we put the seek pointer back
* and treat it as a Nokia file.
*/
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_PCAP_NOKIA;
if (file_seek(wth->fh, first_packet_offset, SEEK_SET, err) == -1) {
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_PCAP_NOKIA;
if (file_seek(wfth->fh, first_packet_offset, SEEK_SET, err) == -1) {
return -1;
}
}
@ -488,10 +490,10 @@ done:
* If this is a Nokia capture, treat 13 as WTAP_ENCAP_ATM_PDUS,
* rather than as what we normally treat it.
*/
if (wth->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_PCAP_NOKIA && hdr.network == 13)
wth->file_encap = WTAP_ENCAP_ATM_PDUS;
if (wfth->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_PCAP_NOKIA && hdr.network == 13)
wfth->file_encap = WTAP_ENCAP_ATM_PDUS;
if (wth->file_encap == WTAP_ENCAP_ERF) {
if (wfth->file_encap == WTAP_ENCAP_ERF) {
/*
* Populate set of interface IDs for ERF format.
* Currently, this *has* to be done at open time.
@ -502,7 +504,7 @@ done:
}
/* Try to read the first two records of the capture file. */
static libpcap_try_t libpcap_try(wtap *wth, int *err)
static libpcap_try_t libpcap_try(wftap *wfth, int *err)
{
/*
* pcaprec_ss990915_hdr is the largest header type.
@ -513,7 +515,7 @@ static libpcap_try_t libpcap_try(wtap *wth, int *err)
/*
* Attempt to read the first record's header.
*/
if (libpcap_read_header(wth, wth->fh, err, NULL, &first_rec_hdr) == -1) {
if (libpcap_read_header(wfth, wfth->fh, err, NULL, &first_rec_hdr) == -1) {
if (*err == 0 || *err == WTAP_ERR_SHORT_READ) {
/*
* EOF or short read - assume the file is in this
@ -546,13 +548,13 @@ static libpcap_try_t libpcap_try(wtap *wth, int *err)
* Now skip over the first record's data, under the assumption
* that the header is sane.
*/
if (file_seek(wth->fh, first_rec_hdr.hdr.incl_len, SEEK_CUR, err) == -1)
if (file_seek(wfth->fh, first_rec_hdr.hdr.incl_len, SEEK_CUR, err) == -1)
return BAD_READ;
/*
* Now attempt to read the second record's header.
*/
if (libpcap_read_header(wth, wth->fh, err, NULL, &second_rec_hdr) == -1) {
if (libpcap_read_header(wfth, wfth->fh, err, NULL, &second_rec_hdr) == -1) {
if (*err == 0 || *err == WTAP_ERR_SHORT_READ) {
/*
* EOF or short read - assume the file is in this
@ -590,23 +592,25 @@ static libpcap_try_t libpcap_try(wtap *wth, int *err)
}
/* Read the next packet */
static gboolean libpcap_read(wtap *wth, int *err, gchar **err_info,
static gboolean libpcap_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset)
{
*data_offset = file_tell(wth->fh);
wtap* wth = (wtap*)wfth->tap_specific_data;
*data_offset = file_tell(wfth->fh);
return libpcap_read_packet(wth, wth->fh, &wth->phdr,
wth->frame_buffer, err, err_info);
return libpcap_read_packet(wfth, wfth->fh, &wth->phdr,
wfth->frame_buffer, err, err_info);
}
static gboolean
libpcap_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
libpcap_seek_read(wftap *wfth, gint64 seek_off, void* header,
Buffer *buf, int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
struct wtap_pkthdr *phdr = (struct wtap_pkthdr *)header;
if (file_seek(wfth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
if (!libpcap_read_packet(wth, wth->random_fh, phdr, buf, err,
if (!libpcap_read_packet(wfth, wfth->random_fh, phdr, buf, err,
err_info)) {
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
@ -616,7 +620,7 @@ libpcap_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
}
static gboolean
libpcap_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
libpcap_read_packet(wftap *wfth, FILE_T fh, struct wtap_pkthdr *phdr,
Buffer *buf, int *err, gchar **err_info)
{
struct pcaprec_ss990915_hdr hdr;
@ -626,7 +630,7 @@ libpcap_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
int phdr_len;
libpcap_t *libpcap;
bytes_read = libpcap_read_header(wth, fh, err, err_info, &hdr);
bytes_read = libpcap_read_header(wfth, fh, err, err_info, &hdr);
if (bytes_read == -1) {
/*
* We failed to read the header.
@ -641,9 +645,9 @@ libpcap_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
* AIX appears to put 3 bytes of padding in front of FDDI
* frames; strip that crap off.
*/
if (wth->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_PCAP_AIX &&
(wth->file_encap == WTAP_ENCAP_FDDI ||
wth->file_encap == WTAP_ENCAP_FDDI_BITSWAPPED)) {
if (wfth->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_PCAP_AIX &&
(wfth->file_encap == WTAP_ENCAP_FDDI ||
wfth->file_encap == WTAP_ENCAP_FDDI_BITSWAPPED)) {
/*
* The packet size is really a record size and includes
* the padding.
@ -658,8 +662,8 @@ libpcap_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
return FALSE;
}
phdr_len = pcap_process_pseudo_header(fh, wth->file_type_subtype,
wth->file_encap, packet_size, TRUE, phdr, err, err_info);
phdr_len = pcap_process_pseudo_header(fh, wfth->file_type_subtype,
wfth->file_encap, packet_size, TRUE, phdr, err, err_info);
if (phdr_len < 0)
return FALSE; /* error */
@ -672,9 +676,9 @@ libpcap_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
/* Update the timestamp, if not already done */
if (wth->file_encap != WTAP_ENCAP_ERF) {
if (wfth->file_encap != WTAP_ENCAP_ERF) {
phdr->ts.secs = hdr.hdr.ts_sec;
if (wth->tsprecision == WTAP_FILE_TSPREC_NSEC)
if (wfth->tsprecision == WTAP_FILE_TSPREC_NSEC)
phdr->ts.nsecs = hdr.hdr.ts_usec;
else
phdr->ts.nsecs = hdr.hdr.ts_usec * 1000;
@ -692,8 +696,8 @@ libpcap_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; /* failed */
libpcap = (libpcap_t *)wth->priv;
pcap_read_post_process(wth->file_type_subtype, wth->file_encap,
libpcap = (libpcap_t *)wfth->priv;
pcap_read_post_process(wfth->file_type_subtype, wfth->file_encap,
phdr, buffer_start_ptr(buf), libpcap->byte_swapped, -1);
return TRUE;
}
@ -701,14 +705,14 @@ libpcap_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
/* Read the header of the next packet.
Return -1 on an error, or the number of bytes of header read on success. */
static int libpcap_read_header(wtap *wth, FILE_T fh, int *err, gchar **err_info,
static int libpcap_read_header(wftap *wfth, FILE_T fh, int *err, gchar **err_info,
struct pcaprec_ss990915_hdr *hdr)
{
int bytes_to_read, bytes_read;
/* Read record header. */
errno = WTAP_ERR_CANT_READ;
switch (wth->file_type_subtype) {
switch (wfth->file_type_subtype) {
case WTAP_FILE_TYPE_SUBTYPE_PCAP:
case WTAP_FILE_TYPE_SUBTYPE_PCAP_AIX:
@ -742,7 +746,7 @@ static int libpcap_read_header(wtap *wth, FILE_T fh, int *err, gchar **err_info,
return -1;
}
adjust_header(wth, &hdr->hdr);
adjust_header(wfth, &hdr->hdr);
if (hdr->hdr.incl_len > WTAP_MAX_PACKET_SIZE) {
/*
@ -789,7 +793,7 @@ static int libpcap_read_header(wtap *wth, FILE_T fh, int *err, gchar **err_info,
* about fixed-length buffers allocated based on the original
* snapshot length. */
#if 0
if (hdr->hdr.incl_len > wth->snapshot_length) {
if (hdr->hdr.incl_len > wfth->snapshot_length) {
g_warning("pcap: File has packet larger than file's snapshot length.");
}
#endif
@ -798,12 +802,12 @@ static int libpcap_read_header(wtap *wth, FILE_T fh, int *err, gchar **err_info,
}
static void
adjust_header(wtap *wth, struct pcaprec_hdr *hdr)
adjust_header(wftap *wfth, struct pcaprec_hdr *hdr)
{
guint32 temp;
libpcap_t *libpcap;
libpcap = (libpcap_t *)wth->priv;
libpcap = (libpcap_t *)wfth->priv;
if (libpcap->byte_swapped) {
/* Byte-swap the record header fields. */
hdr->ts_sec = GUINT32_SWAP_LE_BE(hdr->ts_sec);
@ -852,7 +856,7 @@ int libpcap_dump_can_write_encap(int encap)
/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on
failure */
gboolean libpcap_dump_open(wtap_dumper *wdh, int *err)
gboolean libpcap_dump_open(wftap_dumper *wdh, int *err)
{
guint32 magic;
struct pcap_hdr file_hdr;
@ -889,7 +893,7 @@ gboolean libpcap_dump_open(wtap_dumper *wdh, int *err)
return FALSE;
}
if (!wtap_dump_file_write(wdh, &magic, sizeof magic, err))
if (!wftap_dump_file_write(wdh, &magic, sizeof magic, err))
return FALSE;
wdh->bytes_dumped += sizeof magic;
@ -912,7 +916,7 @@ gboolean libpcap_dump_open(wtap_dumper *wdh, int *err)
file_hdr.snaplen = (wdh->snaplen != 0) ? wdh->snaplen :
WTAP_MAX_PACKET_SIZE;
file_hdr.network = wtap_wtap_encap_to_pcap_encap(wdh->encap);
if (!wtap_dump_file_write(wdh, &file_hdr, sizeof file_hdr, err))
if (!wftap_dump_file_write(wdh, &file_hdr, sizeof file_hdr, err))
return FALSE;
wdh->bytes_dumped += sizeof file_hdr;
@ -921,7 +925,7 @@ gboolean libpcap_dump_open(wtap_dumper *wdh, int *err)
/* Write a record for a packet to a dump file.
Returns TRUE on success, FALSE on failure. */
static gboolean libpcap_dump(wtap_dumper *wdh,
static gboolean libpcap_dump(wftap_dumper *wdh,
const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err)
{
@ -1014,15 +1018,16 @@ static gboolean libpcap_dump(wtap_dumper *wdh,
return FALSE;
}
if (!wtap_dump_file_write(wdh, &rec_hdr, hdr_size, err))
if (!wftap_dump_file_write(wdh, &rec_hdr, hdr_size, err))
return FALSE;
wdh->bytes_dumped += hdr_size;
if (!pcap_write_phdr(wdh, wdh->encap, pseudo_header, err))
return FALSE;
if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err))
if (!wftap_dump_file_write(wdh, pd, phdr->caplen, err))
return FALSE;
wdh->bytes_dumped += phdr->caplen;
wdh->bytes_dumped += phdr->caplen;
return TRUE;
}

View File

@ -100,8 +100,8 @@ struct pcaprec_nokia_hdr {
guint8 stuff[4]; /* mysterious stuff */
};
int libpcap_open(wtap *wth, int *err, gchar **err_info);
gboolean libpcap_dump_open(wtap_dumper *wdh, int *err);
int libpcap_open(wftap *wfth, int *err, gchar **err_info);
gboolean libpcap_dump_open(wftap_dumper *wdh, int *err);
int libpcap_dump_can_write_encap(int encap);
#endif

View File

@ -22,6 +22,7 @@
#include <string.h>
#include <time.h>
#include "wftap-int.h"
#include "wtap-int.h"
#include "file_wrappers.h"
#include "buffer.h"
@ -95,7 +96,7 @@ static gchar *logcat_log(const struct dumper_t *dumper, guint32 seconds,
}
static gint detect_version(wtap *wth, int *err, gchar **err_info)
static gint detect_version(wftap *wfth, int *err, gchar **err_info)
{
gint bytes_read;
guint16 payload_length;
@ -106,20 +107,20 @@ static gint detect_version(wtap *wth, int *err, gchar **err_info)
guint32 tag_length;
guint16 tmp;
file_offset = file_tell(wth->fh);
file_offset = file_tell(wfth->fh);
bytes_read = file_read(&tmp, 2, wth->fh);
bytes_read = file_read(&tmp, 2, wfth->fh);
if (bytes_read != 2) {
*err = file_error(wth->fh, err_info);
*err = file_error(wfth->fh, err_info);
if (*err == 0 && bytes_read != 0)
*err = WTAP_ERR_SHORT_READ;
return -1;
}
payload_length = pletoh16(&tmp);
bytes_read = file_read(&tmp, 2, wth->fh);
bytes_read = file_read(&tmp, 2, wfth->fh);
if (bytes_read != 2) {
*err = file_error(wth->fh, err_info);
*err = file_error(wfth->fh, err_info);
if (*err == 0 && bytes_read != 0)
*err = WTAP_ERR_SHORT_READ;
return -1;
@ -127,10 +128,10 @@ static gint detect_version(wtap *wth, int *err, gchar **err_info)
try_header_size = pletoh16(&tmp);
buffer = (guint8 *) g_malloc(5 * 4 + payload_length);
bytes_read = file_read(buffer, 5 * 4 + payload_length, wth->fh);
bytes_read = file_read(buffer, 5 * 4 + payload_length, wfth->fh);
if (bytes_read != 5 * 4 + payload_length) {
if (bytes_read != 4 * 4 + payload_length) {
*err = file_error(wth->fh, err_info);
*err = file_error(wfth->fh, err_info);
if (*err == 0 && bytes_read != 0)
*err = WTAP_ERR_SHORT_READ;
g_free(buffer);
@ -150,7 +151,7 @@ static gint detect_version(wtap *wth, int *err, gchar **err_info)
tag_length = (guint32)strlen(buffer + 4 * 4 + 1) + 1;
log_length = (guint32)strlen(buffer + 4 * 4 + 1 + tag_length) + 1;
if (payload_length == 1 + tag_length + log_length) {
if (file_seek(wth->fh, file_offset + 4 * 4 + 1 + tag_length + log_length, SEEK_SET, err) == -1) {
if (file_seek(wfth->fh, file_offset + 4 * 4 + 1 + tag_length + log_length, SEEK_SET, err) == -1) {
g_free(buffer);
return -1;
}
@ -214,23 +215,24 @@ static gboolean logcat_read_packet(struct logcat_phdr *logcat, FILE_T fh,
return TRUE;
}
static gboolean logcat_read(wtap *wth, int *err, gchar **err_info,
static gboolean logcat_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset)
{
*data_offset = file_tell(wth->fh);
wtap* wth = (wtap*)wfth->tap_specific_data;
*data_offset = file_tell(wfth->fh);
return logcat_read_packet((struct logcat_phdr *) wth->priv, wth->fh,
&wth->phdr, wth->frame_buffer, err, err_info);
return logcat_read_packet((struct logcat_phdr *) wfth->priv, wfth->fh,
&wth->phdr, wfth->frame_buffer, err, err_info);
}
static gboolean logcat_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf,
int *err, gchar **err_info)
static gboolean logcat_seek_read(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
struct wtap_pkthdr *phdr = (struct wtap_pkthdr *)header;
if (file_seek(wfth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
if (!logcat_read_packet((struct logcat_phdr *) wth->priv, wth->random_fh,
if (!logcat_read_packet((struct logcat_phdr *) wfth->priv, wfth->random_fh,
phdr, buf, err, err_info)) {
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
@ -239,7 +241,7 @@ static gboolean logcat_seek_read(wtap *wth, gint64 seek_off,
return TRUE;
}
int logcat_open(wtap *wth, int *err, gchar **err_info _U_)
int logcat_open(wftap *wfth, int *err, gchar **err_info _U_)
{
int local_err;
gchar *local_err_info;
@ -248,37 +250,37 @@ int logcat_open(wtap *wth, int *err, gchar **err_info _U_)
struct logcat_phdr *logcat;
/* check first 3 packets (or 2 or 1 if EOF) versions to check file format is correct */
version = detect_version(wth, &local_err, &local_err_info);
version = detect_version(wfth, &local_err, &local_err_info);
if (version <= 0)
return 0;
tmp_version = detect_version(wth, &local_err, &local_err_info);
if (tmp_version < 0 && !file_eof(wth->fh)) {
tmp_version = detect_version(wfth, &local_err, &local_err_info);
if (tmp_version < 0 && !file_eof(wfth->fh)) {
return 0;
} else if (tmp_version > 0) {
if (tmp_version != version)
return 0;
tmp_version = detect_version(wth, &local_err, &local_err_info);
if (tmp_version != version && !file_eof(wth->fh))
tmp_version = detect_version(wfth, &local_err, &local_err_info);
if (tmp_version != version && !file_eof(wfth->fh))
return 0;
}
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
if (file_seek(wfth->fh, 0, SEEK_SET, err) == -1)
return -1;
logcat = (struct logcat_phdr *) g_malloc(sizeof(struct logcat_phdr));
logcat->version = version;
wth->priv = logcat;
wfth->priv = logcat;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_LOGCAT;
wth->file_encap = WTAP_ENCAP_LOGCAT;
wth->snapshot_length = 0;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_LOGCAT;
wfth->file_encap = WTAP_ENCAP_LOGCAT;
wfth->snapshot_length = 0;
wth->subtype_read = logcat_read;
wth->subtype_seek_read = logcat_seek_read;
wth->tsprecision = WTAP_FILE_TSPREC_USEC;
wfth->subtype_read = logcat_read;
wfth->subtype_seek_read = logcat_seek_read;
wfth->tsprecision = WTAP_FILE_TSPREC_USEC;
return 1;
}
@ -294,11 +296,11 @@ int logcat_dump_can_write_encap(int encap)
return 0;
}
static gboolean logcat_binary_dump(wtap_dumper *wdh,
static gboolean logcat_binary_dump(wftap_dumper *wdh,
const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err)
{
if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err))
if (!wftap_dump_file_write(wdh, pd, phdr->caplen, err))
return FALSE;
wdh->bytes_dumped += phdr->caplen;
@ -306,7 +308,7 @@ static gboolean logcat_binary_dump(wtap_dumper *wdh,
return TRUE;
}
gboolean logcat_binary_dump_open(wtap_dumper *wdh, int *err)
gboolean logcat_binary_dump_open(wftap_dumper *wdh, int *err)
{
wdh->subtype_write = logcat_binary_dump;
wdh->subtype_close = NULL;
@ -324,7 +326,7 @@ gboolean logcat_binary_dump_open(wtap_dumper *wdh, int *err)
return TRUE;
}
static gboolean logcat_dump_text(wtap_dumper *wdh,
static gboolean logcat_dump_text(wftap_dumper *wdh,
const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err)
{
@ -380,7 +382,7 @@ static gboolean logcat_dump_text(wtap_dumper *wdh,
g_free(log_part);
length = (guint32)strlen(buf);
if (!wtap_dump_file_write(wdh, buf, length, err)) {
if (!wftap_dump_file_write(wdh, buf, length, err)) {
g_free(buf);
return FALSE;
}
@ -404,7 +406,7 @@ static gboolean logcat_dump_text(wtap_dumper *wdh,
g_free(log_part);
length = (guint32)strlen(buf);
if (!wtap_dump_file_write(wdh, buf, length, err)) {
if (!wftap_dump_file_write(wdh, buf, length, err)) {
g_free(buf);
return FALSE;
}
@ -416,7 +418,7 @@ static gboolean logcat_dump_text(wtap_dumper *wdh,
return TRUE;
}
gboolean logcat_text_brief_dump_open(wtap_dumper *wdh, int *err _U_)
gboolean logcat_text_brief_dump_open(wftap_dumper *wdh, int *err _U_)
{
struct dumper_t *dumper;
@ -430,7 +432,7 @@ gboolean logcat_text_brief_dump_open(wtap_dumper *wdh, int *err _U_)
return TRUE;
}
gboolean logcat_text_process_dump_open(wtap_dumper *wdh, int *err _U_)
gboolean logcat_text_process_dump_open(wftap_dumper *wdh, int *err _U_)
{
struct dumper_t *dumper;
@ -444,7 +446,7 @@ gboolean logcat_text_process_dump_open(wtap_dumper *wdh, int *err _U_)
return TRUE;
}
gboolean logcat_text_tag_dump_open(wtap_dumper *wdh, int *err _U_)
gboolean logcat_text_tag_dump_open(wftap_dumper *wdh, int *err _U_)
{
struct dumper_t *dumper;
@ -458,7 +460,7 @@ gboolean logcat_text_tag_dump_open(wtap_dumper *wdh, int *err _U_)
return TRUE;
}
gboolean logcat_text_time_dump_open(wtap_dumper *wdh, int *err _U_)
gboolean logcat_text_time_dump_open(wftap_dumper *wdh, int *err _U_)
{
struct dumper_t *dumper;
@ -472,7 +474,7 @@ gboolean logcat_text_time_dump_open(wtap_dumper *wdh, int *err _U_)
return TRUE;
}
gboolean logcat_text_thread_dump_open(wtap_dumper *wdh, int *err _U_)
gboolean logcat_text_thread_dump_open(wftap_dumper *wdh, int *err _U_)
{
struct dumper_t *dumper;
@ -486,7 +488,7 @@ gboolean logcat_text_thread_dump_open(wtap_dumper *wdh, int *err _U_)
return TRUE;
}
gboolean logcat_text_threadtime_dump_open(wtap_dumper *wdh, int *err _U_)
gboolean logcat_text_threadtime_dump_open(wftap_dumper *wdh, int *err _U_)
{
struct dumper_t *dumper;
@ -500,7 +502,7 @@ gboolean logcat_text_threadtime_dump_open(wtap_dumper *wdh, int *err _U_)
return TRUE;
}
gboolean logcat_text_long_dump_open(wtap_dumper *wdh, int *err _U_)
gboolean logcat_text_long_dump_open(wftap_dumper *wdh, int *err _U_)
{
struct dumper_t *dumper;

View File

@ -25,16 +25,16 @@
#include "wtap.h"
int logcat_open(wtap *wth, int *err, gchar **err_info);
int logcat_open(wftap *wfth, int *err, gchar **err_info);
gboolean logcat_binary_dump_open(wtap_dumper *wdh, int *err);
gboolean logcat_text_brief_dump_open(wtap_dumper *wdh, int *err);
gboolean logcat_text_process_dump_open(wtap_dumper *wdh, int *err);
gboolean logcat_text_tag_dump_open(wtap_dumper *wdh, int *err);
gboolean logcat_text_time_dump_open(wtap_dumper *wdh, int *err);
gboolean logcat_text_thread_dump_open(wtap_dumper *wdh, int *err);
gboolean logcat_text_threadtime_dump_open(wtap_dumper *wdh, int *err);
gboolean logcat_text_long_dump_open(wtap_dumper *wdh, int *err);
gboolean logcat_binary_dump_open(wftap_dumper *wdh, int *err);
gboolean logcat_text_brief_dump_open(wftap_dumper *wdh, int *err);
gboolean logcat_text_process_dump_open(wftap_dumper *wdh, int *err);
gboolean logcat_text_tag_dump_open(wftap_dumper *wdh, int *err);
gboolean logcat_text_time_dump_open(wftap_dumper *wdh, int *err);
gboolean logcat_text_thread_dump_open(wftap_dumper *wdh, int *err);
gboolean logcat_text_threadtime_dump_open(wftap_dumper *wdh, int *err);
gboolean logcat_text_long_dump_open(wftap_dumper *wdh, int *err);
int logcat_dump_can_write_encap(int encap);

View File

@ -1,4 +1,5 @@
/* Combine multiple dump files, either by appending or by merging by timestamp
/* merge.c
* Combine multiple dump files, either by appending or by merging by timestamp
*
* Written by Scott Renfro <scott@renfro.org> based on
* editcap by Richard Sharpe and Guy Harris
@ -60,21 +61,21 @@ merge_open_in_files(int in_file_count, char *const *in_file_names,
for (i = 0; i < in_file_count; i++) {
files[i].filename = in_file_names[i];
files[i].wth = wtap_open_offline(in_file_names[i], WTAP_TYPE_AUTO, err, err_info, FALSE);
files[i].wfth = wtap_open_offline(in_file_names[i], WTAP_TYPE_AUTO, err, err_info, FALSE);
files[i].data_offset = 0;
files[i].state = PACKET_NOT_PRESENT;
files[i].packet_num = 0;
if (!files[i].wth) {
if (!files[i].wfth) {
/* Close the files we've already opened. */
for (j = 0; j < i; j++)
wtap_close(files[j].wth);
wtap_close(files[j].wfth);
*err_fileno = i;
return FALSE;
}
size = wtap_file_size(files[i].wth, err);
size = wftap_file_size(files[i].wfth, err);
if (size == -1) {
for (j = 0; j <= i; j++)
wtap_close(files[j].wth);
wtap_close(files[j].wfth);
*err_fileno = i;
return FALSE;
}
@ -91,7 +92,7 @@ merge_close_in_files(int count, merge_in_file_t in_files[])
{
int i;
for (i = 0; i < count; i++) {
wtap_close(in_files[i].wth);
wtap_close(in_files[i].wfth);
}
}
@ -109,10 +110,10 @@ merge_select_frame_type(int count, merge_in_file_t files[])
int i;
int selected_frame_type;
selected_frame_type = wtap_file_encap(files[0].wth);
selected_frame_type = wftap_file_encap(files[0].wfth);
for (i = 1; i < count; i++) {
int this_frame_type = wtap_file_encap(files[i].wth);
int this_frame_type = wftap_file_encap(files[i].wfth);
if (selected_frame_type != this_frame_type) {
selected_frame_type = WTAP_ENCAP_PER_PACKET;
break;
@ -133,7 +134,7 @@ merge_max_snapshot_length(int count, merge_in_file_t in_files[])
int snapshot_length;
for (i = 0; i < count; i++) {
snapshot_length = wtap_snapshot_length(in_files[i].wth);
snapshot_length = wftap_snapshot_length(in_files[i].wfth);
if (snapshot_length == 0) {
/* Snapshot length of input file not known. */
snapshot_length = WTAP_MAX_PACKET_SIZE;
@ -196,7 +197,7 @@ merge_read_packet(int in_file_count, merge_in_file_t in_files[],
* No packet available, and we haven't seen an error or EOF yet,
* so try to read the next packet.
*/
if (!wtap_read(in_files[i].wth, err, err_info, &in_files[i].data_offset)) {
if (!wtap_read(in_files[i].wfth, err, err_info, &in_files[i].data_offset)) {
if (*err != 0) {
in_files[i].state = GOT_ERROR;
return &in_files[i];
@ -207,7 +208,7 @@ merge_read_packet(int in_file_count, merge_in_file_t in_files[],
}
if (in_files[i].state == PACKET_PRESENT) {
phdr = wtap_phdr(in_files[i].wth);
phdr = wtap_phdr(in_files[i].wfth);
if (is_earlier(&phdr->ts, &tv)) {
tv = phdr->ts;
ei = i;
@ -260,7 +261,7 @@ merge_append_read_packet(int in_file_count, merge_in_file_t in_files[],
for (i = 0; i < in_file_count; i++) {
if (in_files[i].state == AT_EOF)
continue; /* This file is already at EOF */
if (wtap_read(in_files[i].wth, err, err_info, &in_files[i].data_offset))
if (wtap_read(in_files[i].wfth, err, err_info, &in_files[i].data_offset))
break; /* We have a packet */
if (*err != 0) {
/* Read error - quit immediately. */

View File

@ -41,7 +41,7 @@ typedef enum {
*/
typedef struct merge_in_file_s {
const char *filename;
wtap *wth;
wftap *wfth;
gint64 data_offset;
in_file_state_e state;
guint32 packet_num; /* current packet number */

View File

@ -42,6 +42,7 @@
#include <string.h>
#include <time.h>
#include "wftap-int.h"
#include "wtap-int.h"
#include "file_wrappers.h"
#include "buffer.h"
@ -95,13 +96,13 @@ static const mime_files_t magic_files[] = {
#define MAX_FILE_SIZE (16*1024*1024)
static gboolean
mime_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
mime_read_file(wftap *wfth, FILE_T fh, struct wtap_pkthdr *phdr,
Buffer *buf, int *err, gchar **err_info)
{
gint64 file_size;
int packet_size;
if ((file_size = wtap_file_size(wth, err)) == -1)
if ((file_size = wftap_file_size(wfth, err)) == -1)
return FALSE;
if (file_size > MAX_FILE_SIZE) {
@ -128,13 +129,14 @@ mime_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
}
static gboolean
mime_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
mime_read(wftap *wfth, int *err, gchar **err_info, gint64 *data_offset)
{
gint64 offset;
wtap* wth = (wtap*)wfth->tap_specific_data;
*err = 0;
offset = file_tell(wth->fh);
offset = file_tell(wfth->fh);
/* there is only ever one packet */
if (offset != 0)
@ -142,26 +144,28 @@ mime_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
*data_offset = offset;
return mime_read_file(wth, wth->fh, &wth->phdr, wth->frame_buffer, err, err_info);
return mime_read_file(wfth, wfth->fh, &wth->phdr, wfth->frame_buffer, err, err_info);
}
static gboolean
mime_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
mime_seek_read(wftap *wfth, gint64 seek_off, void* header, Buffer *buf, int *err, gchar **err_info)
{
struct wtap_pkthdr *phdr = (struct wtap_pkthdr *)header;
/* there is only one packet */
if (seek_off > 0) {
*err = 0;
return FALSE;
}
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;
return mime_read_file(wth, wth->random_fh, phdr, buf, err, err_info);
return mime_read_file(wfth, wfth->random_fh, phdr, buf, err, err_info);
}
int
mime_file_open(wtap *wth, int *err, gchar **err_info)
mime_file_open(wftap *wfth, int *err, gchar **err_info)
{
char magic_buf[128]; /* increase buffer size when needed */
int bytes_read;
@ -175,10 +179,10 @@ mime_file_open(wtap *wth, int *err, gchar **err_info)
read_bytes = MAX(read_bytes, magic_files[i].magic_len);
read_bytes = (guint)MIN(read_bytes, sizeof(magic_buf));
bytes_read = file_read(magic_buf, read_bytes, wth->fh);
bytes_read = file_read(magic_buf, read_bytes, wfth->fh);
if (bytes_read < 0) {
*err = file_error(wth->fh, err_info);
*err = file_error(wfth->fh, err_info);
return -1;
}
if (bytes_read == 0)
@ -198,15 +202,15 @@ mime_file_open(wtap *wth, int *err, gchar **err_info)
if (!found_file)
return 0;
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
if (file_seek(wfth->fh, 0, SEEK_SET, err) == -1)
return -1;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_MIME;
wth->file_encap = WTAP_ENCAP_MIME;
wth->tsprecision = WTAP_FILE_TSPREC_SEC;
wth->subtype_read = mime_read;
wth->subtype_seek_read = mime_seek_read;
wth->snapshot_length = 0;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_MIME;
wfth->file_encap = WTAP_ENCAP_MIME;
wfth->tsprecision = WTAP_FILE_TSPREC_SEC;
wfth->subtype_read = mime_read;
wfth->subtype_seek_read = mime_seek_read;
wfth->snapshot_length = 0;
return 1;
}

View File

@ -24,6 +24,6 @@
#include <glib.h>
#include <wtap.h>
int mime_file_open(wtap *wth, int *err, gchar **err_info);
int mime_file_open(wftap *wfth, int *err, gchar **err_info);
#endif

View File

@ -32,6 +32,7 @@
#include "mp2t.h"
#include "wftap-int.h"
#include "wtap-int.h"
#include "buffer.h"
#include "file_wrappers.h"
@ -103,22 +104,23 @@ mp2t_read_packet(mp2t_filetype_t *mp2t, FILE_T fh, gint64 offset,
}
static gboolean
mp2t_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
mp2t_read(wftap *wfth, int *err, gchar **err_info, gint64 *data_offset)
{
wtap* wth = (wtap*)wfth->tap_specific_data;
mp2t_filetype_t *mp2t;
mp2t = (mp2t_filetype_t*) wth->priv;
mp2t = (mp2t_filetype_t*) wfth->priv;
*data_offset = file_tell(wth->fh);
*data_offset = file_tell(wfth->fh);
if (!mp2t_read_packet(mp2t, wth->fh, *data_offset, &wth->phdr,
wth->frame_buffer, err, err_info)) {
if (!mp2t_read_packet(mp2t, wfth->fh, *data_offset, &wth->phdr,
wfth->frame_buffer, err, err_info)) {
return FALSE;
}
/* if there's a trailer, skip it and go to the start of the next packet */
if (mp2t->trailer_len!=0) {
if (-1 == file_seek(wth->fh, mp2t->trailer_len, SEEK_CUR, err)) {
if (-1 == file_seek(wfth->fh, mp2t->trailer_len, SEEK_CUR, err)) {
return FALSE;
}
}
@ -127,18 +129,19 @@ mp2t_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
}
static gboolean
mp2t_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
mp2t_seek_read(wftap *wfth, gint64 seek_off, void* header,
Buffer *buf, int *err, gchar **err_info)
{
mp2t_filetype_t *mp2t;
struct wtap_pkthdr *phdr = (struct wtap_pkthdr *)header;
if (-1 == file_seek(wth->random_fh, seek_off, SEEK_SET, err)) {
if (-1 == file_seek(wfth->random_fh, seek_off, SEEK_SET, err)) {
return FALSE;
}
mp2t = (mp2t_filetype_t*) wth->priv;
mp2t = (mp2t_filetype_t*) wfth->priv;
if (!mp2t_read_packet(mp2t, wth->random_fh, seek_off, phdr, buf,
if (!mp2t_read_packet(mp2t, wfth->random_fh, seek_off, phdr, buf,
err, err_info)) {
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
@ -148,7 +151,7 @@ mp2t_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
}
int
mp2t_open(wtap *wth, int *err, gchar **err_info)
mp2t_open(wftap *wfth, int *err, gchar **err_info)
{
int bytes_read;
guint8 buffer[MP2T_SIZE+TRAILER_LEN_MAX];
@ -160,10 +163,10 @@ mp2t_open(wtap *wth, int *err, gchar **err_info)
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(buffer, MP2T_SIZE, wth->fh);
bytes_read = file_read(buffer, MP2T_SIZE, wfth->fh);
if (MP2T_SIZE != bytes_read) {
*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;
@ -180,18 +183,18 @@ mp2t_open(wtap *wth, int *err, gchar **err_info)
return 0; /* wrong file type - not an mpeg2 ts file */
}
if (-1 == file_seek(wth->fh, first, SEEK_SET, err)) {
if (-1 == file_seek(wfth->fh, first, SEEK_SET, err)) {
return -1;
}
/* read some packets and make sure they all start with a sync byte */
do {
bytes_read = file_read(buffer, MP2T_SIZE+trailer_len, wth->fh);
bytes_read = file_read(buffer, MP2T_SIZE+trailer_len, wfth->fh);
if (bytes_read < 0) {
*err = file_error(wth->fh, err_info);
*err = file_error(wfth->fh, err_info);
return -1; /* read error */
}
if (bytes_read < MP2T_SIZE+trailer_len) {
if(sync_steps<2) return 0; /* wrong file type - not an mpeg2 ts file */
if(sync_steps<2) return 0; /* wrong file type - not an mpeg2 ts file */
break; /* end of file, that's ok if we're still in sync */
}
if (buffer[0] == MP2T_SYNC_BYTE) {
@ -210,7 +213,7 @@ mp2t_open(wtap *wth, int *err, gchar **err_info)
for (i=0; i<TRAILER_LEN_MAX; i++) {
if (buffer[i] == MP2T_SYNC_BYTE) {
trailer_len = i;
if (-1 == file_seek(wth->fh, first, SEEK_SET, err)) {
if (-1 == file_seek(wfth->fh, first, SEEK_SET, err)) {
return -1;
}
sync_steps = 0;
@ -223,23 +226,23 @@ mp2t_open(wtap *wth, int *err, gchar **err_info)
}
} while (sync_steps < SYNC_STEPS);
if (-1 == file_seek(wth->fh, first, SEEK_SET, err)) {
if (-1 == file_seek(wfth->fh, first, SEEK_SET, err)) {
return -1;
}
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_MPEG_2_TS;
wth->file_encap = WTAP_ENCAP_MPEG_2_TS;
wth->tsprecision = WTAP_FILE_TSPREC_NSEC;
wth->subtype_read = mp2t_read;
wth->subtype_seek_read = mp2t_seek_read;
wth->snapshot_length = 0;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_MPEG_2_TS;
wfth->file_encap = WTAP_ENCAP_MPEG_2_TS;
wfth->tsprecision = WTAP_FILE_TSPREC_NSEC;
wfth->subtype_read = mp2t_read;
wfth->subtype_seek_read = mp2t_seek_read;
wfth->snapshot_length = 0;
mp2t = (mp2t_filetype_t*) g_malloc(sizeof(mp2t_filetype_t));
if (NULL == mp2t) {
return -1;
}
wth->priv = mp2t;
wfth->priv = mp2t;
mp2t->start_offset = first;
mp2t->trailer_len = trailer_len;

View File

@ -26,6 +26,6 @@
#include <glib.h>
#include <wtap.h>
int mp2t_open(wtap *wth, int *err, gchar **err_info);
int mp2t_open(wftap *wfth, int *err, gchar **err_info);
#endif

View File

@ -33,6 +33,7 @@
#include "mpeg.h"
#include "wsutil/mpeg-audio.h"
#include "wftap-int.h"
#include "wtap-int.h"
#include "buffer.h"
#include "file_wrappers.h"
@ -92,10 +93,10 @@ mpeg_read_header(FILE_T fh, int *err, gchar **err_info, guint32 *n)
#define SCRHZ 27000000
static gboolean
mpeg_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
mpeg_read_packet(wftap *wfth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
gboolean is_random, int *err, gchar **err_info)
{
mpeg_t *mpeg = (mpeg_t *)wth->priv;
mpeg_t *mpeg = (mpeg_t *)wfth->priv;
guint32 n;
int bytes_read;
unsigned int packet_size;
@ -221,23 +222,25 @@ mpeg_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
}
static gboolean
mpeg_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
mpeg_read(wftap *wfth, int *err, gchar **err_info, gint64 *data_offset)
{
*data_offset = file_tell(wth->fh);
wtap* wth = (wtap*)wfth->tap_specific_data;
*data_offset = file_tell(wfth->fh);
return mpeg_read_packet(wth, wth->fh, &wth->phdr, wth->frame_buffer,
return mpeg_read_packet(wfth, wfth->fh, &wth->phdr, wfth->frame_buffer,
FALSE, err, err_info);
}
static gboolean
mpeg_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf,
mpeg_seek_read(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf,
int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
struct wtap_pkthdr *phdr = (struct wtap_pkthdr *)header;
if (file_seek(wfth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
if (!mpeg_read_packet(wth, wth->random_fh, phdr, buf, TRUE, err,
if (!mpeg_read_packet(wfth, wfth->random_fh, phdr, buf, TRUE, err,
err_info)) {
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
@ -258,7 +261,7 @@ struct _mpeg_magic {
};
int
mpeg_open(wtap *wth, int *err, gchar **err_info)
mpeg_open(wftap *wfth, int *err, gchar **err_info)
{
int bytes_read;
char magic_buf[16];
@ -266,9 +269,9 @@ mpeg_open(wtap *wth, int *err, gchar **err_info)
mpeg_t *mpeg;
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(magic_buf, sizeof magic_buf, wth->fh);
bytes_read = file_read(magic_buf, sizeof magic_buf, wfth->fh);
if (bytes_read != (int) sizeof magic_buf) {
*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;
@ -283,18 +286,18 @@ mpeg_open(wtap *wth, int *err, gchar **err_info)
good_magic:
/* This appears to be a file with MPEG data. */
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
if (file_seek(wfth->fh, 0, SEEK_SET, err) == -1)
return -1;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_MPEG;
wth->file_encap = WTAP_ENCAP_MPEG;
wth->tsprecision = WTAP_FILE_TSPREC_NSEC;
wth->subtype_read = mpeg_read;
wth->subtype_seek_read = mpeg_seek_read;
wth->snapshot_length = 0;
wfth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_MPEG;
wfth->file_encap = WTAP_ENCAP_MPEG;
wfth->tsprecision = WTAP_FILE_TSPREC_NSEC;
wfth->subtype_read = mpeg_read;
wfth->subtype_seek_read = mpeg_seek_read;
wfth->snapshot_length = 0;
mpeg = (mpeg_t *)g_malloc(sizeof(mpeg_t));
wth->priv = (void *)mpeg;
wfth->priv = (void *)mpeg;
mpeg->now.secs = 0;
mpeg->now.nsecs = 0;
mpeg->t0 = mpeg->now.secs;

View File

@ -26,6 +26,6 @@
#include <glib.h>
#include <wtap.h>
int mpeg_open(wtap *wth, int *err, gchar **err_info);
int mpeg_open(wftap *wfth, int *err, gchar **err_info);
#endif

View File

@ -21,6 +21,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"
@ -175,20 +176,20 @@ static const int netmon_encap[] = {
#define NETMON_NET_DNS_CACHE 0xFFFE
#define NETMON_NET_NETMON_FILTER 0xFFFF
static gboolean netmon_read(wtap *wth, int *err, gchar **err_info,
static gboolean netmon_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean netmon_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
static gboolean netmon_seek_read(wftap *wth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info);
static gboolean netmon_read_atm_pseudoheader(FILE_T fh,
union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info);
static int netmon_read_rec_trailer(FILE_T fh, int trlr_size, int *err,
gchar **err_info);
static void netmon_sequential_close(wtap *wth);
static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
static void netmon_sequential_close(wftap *wth);
static gboolean netmon_dump(wftap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err);
static gboolean netmon_dump_close(wtap_dumper *wdh, int *err);
static gboolean netmon_dump_close(wftap_dumper *wdh, int *err);
int netmon_open(wtap *wth, int *err, gchar **err_info)
int netmon_open(wftap *wfth, int *err, gchar **err_info)
{
int bytes_read;
char magic[MAGIC_SIZE];
@ -207,9 +208,9 @@ int netmon_open(wtap *wth, int *err, gchar **err_info)
/* Read in the string that should be at the start of a Network
* Monitor file */
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(magic, MAGIC_SIZE, wth->fh);
bytes_read = file_read(magic, MAGIC_SIZE, wfth->fh);
if (bytes_read != MAGIC_SIZE) {
*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;
@ -222,9 +223,9 @@ int netmon_open(wtap *wth, int *err, gchar **err_info)
/* Read the rest of the header. */
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(&hdr, sizeof hdr, wth->fh);
bytes_read = file_read(&hdr, sizeof hdr, wfth->fh);
if (bytes_read != sizeof 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;
@ -256,21 +257,21 @@ int netmon_open(wtap *wth, int *err, gchar **err_info)
}
/* This is a netmon file */
wth->file_type_subtype = file_type;
wfth->file_type_subtype = file_type;
netmon = (netmon_t *)g_malloc(sizeof(netmon_t));
wth->priv = (void *)netmon;
wth->subtype_read = netmon_read;
wth->subtype_seek_read = netmon_seek_read;
wth->subtype_sequential_close = netmon_sequential_close;
wfth->priv = (void *)netmon;
wfth->subtype_read = netmon_read;
wfth->subtype_seek_read = netmon_seek_read;
wfth->subtype_sequential_close = netmon_sequential_close;
/* NetMon capture file formats v2.1+ use per-packet encapsulation types. NetMon 3 sets the value in
* the header to 1 (Ethernet) for backwards compability. */
if((hdr.ver_major == 2 && hdr.ver_minor >= 1) || hdr.ver_major > 2)
wth->file_encap = WTAP_ENCAP_PER_PACKET;
wfth->file_encap = WTAP_ENCAP_PER_PACKET;
else
wth->file_encap = netmon_encap[hdr.network];
wfth->file_encap = netmon_encap[hdr.network];
wth->snapshot_length = 0; /* not available in header */
wfth->snapshot_length = 0; /* not available in header */
/*
* Convert the time stamp to a "time_t" and a number of
* milliseconds.
@ -360,7 +361,7 @@ int netmon_open(wtap *wth, int *err, gchar **err_info)
frame_table_length);
return -1;
}
if (file_seek(wth->fh, frame_table_offset, SEEK_SET, err) == -1) {
if (file_seek(wfth->fh, frame_table_offset, SEEK_SET, err) == -1) {
return -1;
}
frame_table = (guint32 *)g_try_malloc(frame_table_length);
@ -369,9 +370,9 @@ int netmon_open(wtap *wth, int *err, gchar **err_info)
return -1;
}
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(frame_table, frame_table_length, wth->fh);
bytes_read = file_read(frame_table, frame_table_length, wfth->fh);
if ((guint32)bytes_read != frame_table_length) {
*err = file_error(wth->fh, err_info);
*err = file_error(wfth->fh, err_info);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
g_free(frame_table);
@ -397,7 +398,7 @@ int netmon_open(wtap *wth, int *err, gchar **err_info)
* Version 1.x of the file format supports
* millisecond precision.
*/
wth->tsprecision = WTAP_FILE_TSPREC_MSEC;
wfth->tsprecision = WTAP_FILE_TSPREC_MSEC;
break;
case 2:
@ -407,7 +408,7 @@ int netmon_open(wtap *wth, int *err, gchar **err_info)
* currently support that, so say
* "nanosecond precision" for now.
*/
wth->tsprecision = WTAP_FILE_TSPREC_NSEC;
wfth->tsprecision = WTAP_FILE_TSPREC_NSEC;
break;
}
return 1;
@ -476,10 +477,10 @@ netmon_set_pseudo_header_info(int pkt_encap, struct wtap_pkthdr *phdr,
}
}
static gboolean netmon_process_rec_header(wtap *wth, FILE_T fh,
static gboolean netmon_process_rec_header(wftap *wfth, FILE_T fh,
struct wtap_pkthdr *phdr, int *err, gchar **err_info)
{
netmon_t *netmon = (netmon_t *)wth->priv;
netmon_t *netmon = (netmon_t *)wfth->priv;
int hdr_size = 0;
union {
struct netmonrec_1_x_hdr hdr_1_x;
@ -545,7 +546,7 @@ static gboolean netmon_process_rec_header(wtap *wth, FILE_T fh,
* and the VPI and VCI; read them and generate the pseudo-header
* from them.
*/
switch (wth->file_encap) {
switch (wfth->file_encap) {
case WTAP_ENCAP_ATM_PDUS:
if (packet_size < sizeof (struct netmon_atm_hdr)) {
@ -677,10 +678,11 @@ static process_trailer_retval netmon_process_rec_trailer(netmon_t *netmon,
}
/* Read the next packet */
static gboolean netmon_read(wtap *wth, int *err, gchar **err_info,
static gboolean netmon_read(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset)
{
netmon_t *netmon = (netmon_t *)wth->priv;
netmon_t *netmon = (netmon_t *)wfth->priv;
wtap* wth = (wtap*)wfth->tap_specific_data;
gint64 rec_offset;
again:
@ -705,19 +707,19 @@ again:
file, but set the frame table up so it's the last
record in sequence. */
rec_offset = netmon->frame_table[netmon->current_frame];
if (file_tell(wth->fh) != rec_offset) {
if (file_seek(wth->fh, rec_offset, SEEK_SET, err) == -1)
if (file_tell(wfth->fh) != rec_offset) {
if (file_seek(wfth->fh, rec_offset, SEEK_SET, err) == -1)
return FALSE;
}
netmon->current_frame++;
*data_offset = file_tell(wth->fh);
*data_offset = file_tell(wfth->fh);
if (!netmon_process_rec_header(wth, wth->fh, &wth->phdr,
if (!netmon_process_rec_header(wfth, wfth->fh, &wth->phdr,
err, err_info))
return FALSE;
if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
if (!wtap_read_packet_bytes(wfth->fh, wfth->frame_buffer,
wth->phdr.caplen, err, err_info))
return FALSE; /* Read error */
@ -725,7 +727,7 @@ again:
* For version 2.1 and later, there's additional information
* after the frame data.
*/
switch (netmon_process_rec_trailer(netmon, wth->fh, &wth->phdr,
switch (netmon_process_rec_trailer(netmon, wfth->fh, &wth->phdr,
err, err_info)) {
case RETRY:
@ -739,27 +741,28 @@ again:
}
netmon_set_pseudo_header_info(wth->phdr.pkt_encap, &wth->phdr,
wth->frame_buffer);
wfth->frame_buffer);
return TRUE;
}
static gboolean
netmon_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
netmon_seek_read(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info)
{
netmon_t *netmon = (netmon_t *)wth->priv;
struct wtap_pkthdr *phdr = (struct wtap_pkthdr *)header;
netmon_t *netmon = (netmon_t *)wfth->priv;
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 (!netmon_process_rec_header(wth, wth->random_fh, phdr,
if (!netmon_process_rec_header(wfth, wfth->random_fh, phdr,
err, err_info))
return FALSE;
/*
* Read the packet data.
*/
if (!wtap_read_packet_bytes(wth->random_fh, buf, phdr->caplen, err,
if (!wtap_read_packet_bytes(wfth->random_fh, buf, phdr->caplen, err,
err_info))
return FALSE;
@ -767,7 +770,7 @@ netmon_seek_read(wtap *wth, gint64 seek_off,
* For version 2.1 and later, there's additional information
* after the frame data.
*/
switch (netmon_process_rec_trailer(netmon, wth->random_fh, phdr,
switch (netmon_process_rec_trailer(netmon, wfth->random_fh, phdr,
err, err_info)) {
case RETRY:
@ -911,9 +914,9 @@ netmon_read_rec_trailer(FILE_T fh, int trlr_size, int *err, gchar **err_info)
/* Throw away the frame table used by the sequential I/O stream. */
static void
netmon_sequential_close(wtap *wth)
netmon_sequential_close(wftap *wfth)
{
netmon_t *netmon = (netmon_t *)wth->priv;
netmon_t *netmon = (netmon_t *)wfth->priv;
if (netmon->frame_table != NULL) {
g_free(netmon->frame_table);
@ -980,7 +983,7 @@ int netmon_dump_can_write_encap_2_x(int encap)
/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on
failure */
gboolean netmon_dump_open(wtap_dumper *wdh, int *err)
gboolean netmon_dump_open(wftap_dumper *wdh, int *err)
{
netmon_dump_t *netmon;
@ -988,7 +991,7 @@ gboolean netmon_dump_open(wtap_dumper *wdh, int *err)
haven't yet written any packets. As we'll have to rewrite
the header when we've written out all the packets, we just
skip over the header for now. */
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;
wdh->subtype_write = netmon_dump;
@ -1008,7 +1011,7 @@ gboolean netmon_dump_open(wtap_dumper *wdh, int *err)
/* Write a record for a packet to a dump file.
Returns TRUE on success, FALSE on failure. */
static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
static gboolean netmon_dump(wftap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err)
{
const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header;
@ -1163,7 +1166,7 @@ static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
*/
rec_size = 0;
if (!wtap_dump_file_write(wdh, hdrp, hdr_size, err))
if (!wftap_dump_file_write(wdh, hdrp, hdr_size, err))
return FALSE;
rec_size += hdr_size;
@ -1176,12 +1179,12 @@ static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
memset(&atm_hdr.src, 0, sizeof atm_hdr.src);
atm_hdr.vpi = g_htons(pseudo_header->atm.vpi);
atm_hdr.vci = g_htons(pseudo_header->atm.vci);
if (!wtap_dump_file_write(wdh, &atm_hdr, sizeof atm_hdr, err))
if (!wftap_dump_file_write(wdh, &atm_hdr, sizeof atm_hdr, err))
return FALSE;
rec_size += sizeof atm_hdr;
}
if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err))
if (!wftap_dump_file_write(wdh, pd, phdr->caplen, err))
return FALSE;
rec_size += phdr->caplen;
@ -1189,7 +1192,7 @@ static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
/*
* Write out the trailer.
*/
if (!wtap_dump_file_write(wdh, &rec_2_x_trlr,
if (!wftap_dump_file_write(wdh, &rec_2_x_trlr,
sizeof rec_2_x_trlr, err))
return FALSE;
rec_size += sizeof rec_2_x_trlr;
@ -1249,7 +1252,7 @@ static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
/* Finish writing to a dump file.
Returns TRUE on success, FALSE on failure. */
static gboolean netmon_dump_close(wtap_dumper *wdh, int *err)
static gboolean netmon_dump_close(wftap_dumper *wdh, int *err)
{
netmon_dump_t *netmon = (netmon_dump_t *)wdh->priv;
size_t n_to_write;
@ -1261,11 +1264,11 @@ static gboolean netmon_dump_close(wtap_dumper *wdh, int *err)
/* Write out the frame table. "netmon->frame_table_index" is
the number of entries we've put into it. */
n_to_write = netmon->frame_table_index * sizeof *netmon->frame_table;
if (!wtap_dump_file_write(wdh, netmon->frame_table, n_to_write, err))
if (!wftap_dump_file_write(wdh, netmon->frame_table, n_to_write, err))
return FALSE;
/* Now go fix up the file header. */
if (wtap_dump_file_seek(wdh, 0, SEEK_SET, err) == -1)
if (wftap_dump_file_seek(wdh, 0, SEEK_SET, err) == -1)
return FALSE;
memset(&file_hdr, '\0', sizeof file_hdr);
switch (wdh->file_type_subtype) {
@ -1309,7 +1312,7 @@ static gboolean netmon_dump_close(wtap_dumper *wdh, int *err)
*err = WTAP_ERR_UNSUPPORTED_FILE_TYPE;
return FALSE;
}
if (!wtap_dump_file_write(wdh, magicp, magic_size, err))
if (!wftap_dump_file_write(wdh, magicp, magic_size, err))
return FALSE;
if (wdh->encap == WTAP_ENCAP_PER_PACKET) {
@ -1343,7 +1346,7 @@ static gboolean netmon_dump_close(wtap_dumper *wdh, int *err)
file_hdr.frametableoffset = GUINT32_TO_LE(netmon->frame_table_offset);
file_hdr.frametablelength =
GUINT32_TO_LE(netmon->frame_table_index * sizeof *netmon->frame_table);
if (!wtap_dump_file_write(wdh, &file_hdr, sizeof file_hdr, err))
if (!wftap_dump_file_write(wdh, &file_hdr, sizeof file_hdr, err))
return FALSE;
return TRUE;

View File

@ -24,8 +24,8 @@
#include <glib.h>
#include <wtap.h>
int netmon_open(wtap *wth, int *err, gchar **err_info);
gboolean netmon_dump_open(wtap_dumper *wdh, int *err);
int netmon_open(wftap *wfth, int *err, gchar **err_info);
gboolean netmon_dump_open(wftap_dumper *wdh, int *err);
int netmon_dump_can_write_encap_1_x(int encap);
int netmon_dump_can_write_encap_2_x(int encap);

View File

@ -21,6 +21,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"
@ -612,33 +613,30 @@ typedef struct {
guint64 file_size;
} nstrace_t;
static guint32 nspm_signature_version(wtap*, gchar*, gint32);
static gboolean nstrace_read_v10(wtap *wth, int *err, gchar **err_info,
static guint32 nspm_signature_version(wftap*, gchar*, gint32);
static gboolean nstrace_read_v10(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info,
static gboolean nstrace_read_v20(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean nstrace_read_v30(wtap *wth, int *err, gchar **err_info,
static gboolean nstrace_read_v30(wftap *wfth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean nstrace_seek_read_v10(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr,
Buffer *buf,
static gboolean nstrace_seek_read_v10(wftap *wth, gint64 seek_off,
void* header, Buffer *buf,
int *err, gchar **err_info);
static gboolean nstrace_seek_read_v20(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr,
Buffer *buf,
static gboolean nstrace_seek_read_v20(wftap *wth, gint64 seek_off,
void* header, Buffer *buf,
int *err, gchar **err_info);
static gboolean nstrace_seek_read_v30(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr,
Buffer *buf,
static gboolean nstrace_seek_read_v30(wftap *wth, gint64 seek_off,
void* header, Buffer *buf,
int *err, gchar **err_info);
static void nstrace_close(wtap *wth);
static void nstrace_close(wftap *wth);
static gboolean nstrace_set_start_time_v10(wtap *wth);
static gboolean nstrace_set_start_time_v20(wtap *wth);
static gboolean nstrace_set_start_time(wtap *wth);
static gboolean nstrace_set_start_time_v10(wftap *wth);
static gboolean nstrace_set_start_time_v20(wftap *wth);
static gboolean nstrace_set_start_time(wftap *wth);
static guint64 ns_hrtime2nsec(guint32 tm);
static gboolean nstrace_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
static gboolean nstrace_dump(wftap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err);
@ -666,34 +664,35 @@ static guint64 ns_hrtime2nsec(guint32 tm)
/*
** Netscaler trace format open routines
*/
int nstrace_open(wtap *wth, int *err, gchar **err_info)
int nstrace_open(wftap *wfth, int *err, gchar **err_info)
{
gchar *nstrace_buf;
gint64 file_size;
gint32 page_size;
nstrace_t *nstrace;
int bytes_read;
wtap* wth = (wtap*)wfth->tap_specific_data;
errno = WTAP_ERR_CANT_READ;
if ((file_size = wtap_file_size(wth, err)) == -1)
if ((file_size = wftap_file_size(wfth, err)) == -1)
return 0;
nstrace_buf = (gchar *)g_malloc(NSPR_PAGESIZE);
page_size = GET_READ_PAGE_SIZE(file_size);
switch ((wth->file_type_subtype = nspm_signature_version(wth, nstrace_buf, page_size)))
switch ((wfth->file_type_subtype = nspm_signature_version(wfth, nstrace_buf, page_size)))
{
case WTAP_FILE_TYPE_SUBTYPE_NETSCALER_1_0:
wth->file_encap = WTAP_ENCAP_NSTRACE_1_0;
wfth->file_encap = WTAP_ENCAP_NSTRACE_1_0;
break;
case WTAP_FILE_TYPE_SUBTYPE_NETSCALER_2_0:
wth->file_encap = WTAP_ENCAP_NSTRACE_2_0;
wfth->file_encap = WTAP_ENCAP_NSTRACE_2_0;
break;
case WTAP_FILE_TYPE_SUBTYPE_NETSCALER_3_0:
wth->file_encap = WTAP_ENCAP_NSTRACE_3_0;
wfth->file_encap = WTAP_ENCAP_NSTRACE_3_0;
g_free(nstrace_buf);
nstrace_buf = (gchar *)g_malloc(NSPR_PAGESIZE_TRACE);
page_size = GET_READ_PAGE_SIZEV3(file_size);
@ -701,49 +700,49 @@ int nstrace_open(wtap *wth, int *err, gchar **err_info)
default:
*err = WTAP_ERR_UNSUPPORTED;
*err_info = g_strdup_printf("nstrace: file type %d unsupported", wth->file_type_subtype);
*err_info = g_strdup_printf("nstrace: file type %d unsupported", wfth->file_type_subtype);
g_free(nstrace_buf);
return 0;
}
if ((file_seek(wth->fh, 0, SEEK_SET, err)) == -1)
if ((file_seek(wfth->fh, 0, SEEK_SET, err)) == -1)
{
*err = file_error(wth->fh, err_info);
*err = file_error(wfth->fh, err_info);
g_free(nstrace_buf);
return 0;
}
bytes_read = file_read(nstrace_buf, page_size, wth->fh);
bytes_read = file_read(nstrace_buf, page_size, wfth->fh);
if (bytes_read != page_size)
{
*err = file_error(wth->fh, err_info);
*err = file_error(wfth->fh, err_info);
g_free(nstrace_buf);
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
return -1;
return 0;
}
switch (wth->file_type_subtype)
switch (wfth->file_type_subtype)
{
case WTAP_FILE_TYPE_SUBTYPE_NETSCALER_1_0:
wth->subtype_read = nstrace_read_v10;
wth->subtype_seek_read = nstrace_seek_read_v10;
wfth->subtype_read = nstrace_read_v10;
wfth->subtype_seek_read = nstrace_seek_read_v10;
break;
case WTAP_FILE_TYPE_SUBTYPE_NETSCALER_2_0:
wth->subtype_read = nstrace_read_v20;
wth->subtype_seek_read = nstrace_seek_read_v20;
wfth->subtype_read = nstrace_read_v20;
wfth->subtype_seek_read = nstrace_seek_read_v20;
break;
case WTAP_FILE_TYPE_SUBTYPE_NETSCALER_3_0:
wth->subtype_read = nstrace_read_v30;
wth->subtype_seek_read = nstrace_seek_read_v30;
wfth->subtype_read = nstrace_read_v30;
wfth->subtype_seek_read = nstrace_seek_read_v30;
break;
}
wth->subtype_close = nstrace_close;
wfth->subtype_close = nstrace_close;
nstrace = (nstrace_t *)g_malloc(sizeof(nstrace_t));
wth->priv = (void *)nstrace;
wfth->priv = (void *)nstrace;
nstrace->pnstrace_buf = nstrace_buf;
nstrace->xxx_offset = 0;
nstrace->nstrace_buflen = page_size;
@ -756,22 +755,22 @@ int nstrace_open(wtap *wth, int *err, gchar **err_info)
/* Set the start time by looking for the abstime record */
if ((nstrace_set_start_time(wth)) == FALSE)
if ((nstrace_set_start_time(wfth)) == FALSE)
{
/* Reset the read pointer to start of the file. */
if ((file_seek(wth->fh, 0, SEEK_SET, err)) == -1)
if ((file_seek(wfth->fh, 0, SEEK_SET, err)) == -1)
{
*err = file_error(wth->fh, err_info);
*err = file_error(wfth->fh, err_info);
g_free(nstrace->pnstrace_buf);
g_free(nstrace);
return 0;
}
/* Read the first page of data */
bytes_read = file_read(nstrace_buf, page_size, wth->fh);
bytes_read = file_read(nstrace_buf, page_size, wfth->fh);
if (bytes_read != page_size)
{
*err = file_error(wth->fh, err_info);
*err = file_error(wfth->fh, err_info);
g_free(nstrace->pnstrace_buf);
g_free(nstrace);
return 0;
@ -781,7 +780,7 @@ int nstrace_open(wtap *wth, int *err, gchar **err_info)
nstrace->nstrace_buf_offset = 0;
}
wth->tsprecision = WTAP_FILE_TSPREC_NSEC;
wfth->tsprecision = WTAP_FILE_TSPREC_NSEC;
wth->phdr.ts.secs = nstrace->nspm_curtime;
wth->phdr.ts.nsecs = 0;
@ -806,12 +805,12 @@ nspm_signature_func(30)
** has to be a file seek to return to the start of the first page.
*/
static guint32
nspm_signature_version(wtap *wth, gchar *nstrace_buf, gint32 len)
nspm_signature_version(wftap *wfth, gchar *nstrace_buf, gint32 len)
{
gchar *dp = nstrace_buf;
int bytes_read;
bytes_read = file_read(dp, len, wth->fh);
bytes_read = file_read(dp, len, wfth->fh);
if (bytes_read == len) {
for ( ; len > (gint32)(MIN(sizeof(NSPR_SIGSTR_V10), sizeof(NSPR_SIGSTR_V20))); dp++, len--)
@ -852,9 +851,9 @@ nspm_signature_version(wtap *wth, gchar *nstrace_buf, gint32 len)
#define nstrace_set_start_time_ver(ver) \
gboolean nstrace_set_start_time_v##ver(wtap *wth) \
gboolean nstrace_set_start_time_v##ver(wftap *wfth) \
{\
nstrace_t *nstrace = (nstrace_t *)wth->priv;\
nstrace_t *nstrace = (nstrace_t *)wfth->priv;\
gchar* nstrace_buf = nstrace->pnstrace_buf;\
gint32 nstrace_buf_offset = nstrace->nstrace_buf_offset;\
gint32 nstrace_buflen = nstrace->nstrace_buflen;\
@ -881,7 +880,7 @@ nspm_signature_version(wtap *wth, gchar *nstrace_buf, gint32 len)
nstrace_buf_offset = 0;\
nstrace->xxx_offset += nstrace_buflen;\
nstrace_buflen = GET_READ_PAGE_SIZE((nstrace->file_size - nstrace->xxx_offset));\
}while((nstrace_buflen > 0) && (bytes_read = file_read(nstrace_buf, nstrace_buflen, wth->fh)) && bytes_read == nstrace_buflen); \
}while((nstrace_buflen > 0) && (bytes_read = file_read(nstrace_buf, nstrace_buflen, wfth->fh)) && bytes_read == nstrace_buflen); \
return FALSE;\
}
@ -897,14 +896,14 @@ nstrace_set_start_time_ver(20)
** the next record after the ABSTIME record. Inorder to report correct time values, all trace
** records before the ABSTIME record are ignored.
*/
static gboolean nstrace_set_start_time(wtap *wth)
static gboolean nstrace_set_start_time(wftap *wfth)
{
if (wth->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_NETSCALER_1_0)
return nstrace_set_start_time_v10(wth);
else if (wth->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_NETSCALER_2_0)
return nstrace_set_start_time_v20(wth);
else if (wth->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_NETSCALER_3_0)
return nstrace_set_start_time_v20(wth);
if (wfth->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_NETSCALER_1_0)
return nstrace_set_start_time_v10(wfth);
else if (wfth->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_NETSCALER_2_0)
return nstrace_set_start_time_v20(wfth);
else if (wfth->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_NETSCALER_3_0)
return nstrace_set_start_time_v20(wfth);
return FALSE;
}
@ -925,9 +924,9 @@ static gboolean nstrace_set_start_time(wtap *wth)
/*
** Netscaler trace format read routines.
*/
static gboolean nstrace_read_v10(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
static gboolean nstrace_read_v10(wftap *wfth, int *err, gchar **err_info, gint64 *data_offset)
{
nstrace_t *nstrace = (nstrace_t *)wth->priv;
nstrace_t *nstrace = (nstrace_t *)wfth->priv;
guint64 nsg_creltime = nstrace->nsg_creltime;
gchar *nstrace_buf = nstrace->pnstrace_buf;
gint32 nstrace_buf_offset = nstrace->nstrace_buf_offset;
@ -935,6 +934,7 @@ static gboolean nstrace_read_v10(wtap *wth, int *err, gchar **err_info, gint64 *
nspr_pktracefull_v10_t *fp;
nspr_pktracepart_v10_t *pp;
int bytes_read;
wtap* wth = (wtap*)wfth->tap_specific_data;
*err = 0;
*err_info = NULL;
@ -959,8 +959,8 @@ static gboolean nstrace_read_v10(wtap *wth, int *err, gchar **err_info, gint64 *
(phdr)->ts.secs = nstrace->nspm_curtime + (guint32) (nsg_creltime / 1000000000);\
(phdr)->ts.nsecs = (guint32) (nsg_creltime % 1000000000);\
TRACE_FULL_V##type##_REC_LEN_OFF(phdr,v##type##_full,fp,pktracefull_v##type);\
buffer_assure_space(wth->frame_buffer, (phdr)->caplen);\
memcpy(buffer_start_ptr(wth->frame_buffer), fp, (phdr)->caplen);\
buffer_assure_space(wfth->frame_buffer, (phdr)->caplen);\
memcpy(buffer_start_ptr(wfth->frame_buffer), fp, (phdr)->caplen);\
*data_offset = nstrace->xxx_offset + nstrace_buf_offset;\
nstrace->nstrace_buf_offset = nstrace_buf_offset + (phdr)->len;\
nstrace->nstrace_buflen = nstrace_buflen;\
@ -982,8 +982,8 @@ static gboolean nstrace_read_v10(wtap *wth, int *err, gchar **err_info, gint64 *
(phdr)->ts.secs = nstrace->nspm_curtime + (guint32) (nsg_creltime / 1000000000);\
(phdr)->ts.nsecs = (guint32) (nsg_creltime % 1000000000);\
TRACE_PART_V##type##_REC_LEN_OFF(phdr,v##type##_part,pp,pktracepart_v##type);\
buffer_assure_space(wth->frame_buffer, (phdr)->caplen);\
memcpy(buffer_start_ptr(wth->frame_buffer), pp, (phdr)->caplen);\
buffer_assure_space(wfth->frame_buffer, (phdr)->caplen);\
memcpy(buffer_start_ptr(wfth->frame_buffer), pp, (phdr)->caplen);\
*data_offset = nstrace->xxx_offset + nstrace_buf_offset;\
nstrace->nstrace_buf_offset = nstrace_buf_offset + (phdr)->caplen;\
nstrace->nsg_creltime = nsg_creltime;\
@ -1028,7 +1028,7 @@ static gboolean nstrace_read_v10(wtap *wth, int *err, gchar **err_info, gint64 *
nstrace_buf_offset = 0;
nstrace->xxx_offset += nstrace_buflen;
nstrace_buflen = GET_READ_PAGE_SIZE((nstrace->file_size - nstrace->xxx_offset));
}while((nstrace_buflen > 0) && (bytes_read = file_read(nstrace_buf, nstrace_buflen, wth->fh)) && (bytes_read == nstrace_buflen));
}while((nstrace_buflen > 0) && (bytes_read = file_read(nstrace_buf, nstrace_buflen, wfth->fh)) && (bytes_read == nstrace_buflen));
return FALSE;
}
@ -1106,8 +1106,8 @@ static gboolean nstrace_read_v10(wtap *wth, int *err, gchar **err_info, gint64 *
SIZEDEF##ver((phdr),fp,ver);\
TRACE_V##ver##_REC_LEN_OFF((phdr),enumprefix,type,structname);\
(phdr)->pseudo_header.nstr.rec_type = NSPR_HEADER_VERSION##TYPE;\
buffer_assure_space(wth->frame_buffer, (phdr)->caplen);\
memcpy(buffer_start_ptr(wth->frame_buffer), fp, (phdr)->caplen);\
buffer_assure_space(wfth->frame_buffer, (phdr)->caplen);\
memcpy(buffer_start_ptr(wfth->frame_buffer), fp, (phdr)->caplen);\
*data_offset = nstrace->xxx_offset + nstrace_buf_offset;\
nstrace->nstrace_buf_offset = nstrace_buf_offset + nspr_getv20recordsize((nspr_hd_v20_t *)fp);\
nstrace->nstrace_buflen = nstrace_buflen;\
@ -1115,14 +1115,15 @@ static gboolean nstrace_read_v10(wtap *wth, int *err, gchar **err_info, gint64 *
return TRUE;\
}while(0)
static gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
static gboolean nstrace_read_v20(wftap *wfth, int *err, gchar **err_info, gint64 *data_offset)
{
nstrace_t *nstrace = (nstrace_t *)wth->priv;
nstrace_t *nstrace = (nstrace_t *)wfth->priv;
guint64 nsg_creltime = nstrace->nsg_creltime;
gchar *nstrace_buf = nstrace->pnstrace_buf;
gint32 nstrace_buf_offset = nstrace->nstrace_buf_offset;
gint32 nstrace_buflen = nstrace->nstrace_buflen;
int bytes_read;
wtap* wth = (wtap*)wfth->tap_specific_data;
*err = 0;
*err_info = NULL;
@ -1217,7 +1218,7 @@ static gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info, gint64 *
nstrace_buf_offset = 0;
nstrace->xxx_offset += nstrace_buflen;
nstrace_buflen = GET_READ_PAGE_SIZE((nstrace->file_size - nstrace->xxx_offset));
}while((nstrace_buflen > 0) && (bytes_read = file_read(nstrace_buf, nstrace_buflen, wth->fh)) && (bytes_read == nstrace_buflen));
}while((nstrace_buflen > 0) && (bytes_read = file_read(nstrace_buf, nstrace_buflen, wfth->fh)) && (bytes_read == nstrace_buflen));
return FALSE;
}
@ -1231,7 +1232,7 @@ static gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info, gint64 *
SIZEDEF##ver((phdr),fp,ver);\
TRACE_V##ver##_REC_LEN_OFF((phdr),enumprefix,type,structname);\
(phdr)->pseudo_header.nstr.rec_type = NSPR_HEADER_VERSION##TYPE;\
buffer_assure_space(wth->frame_buffer, (phdr)->caplen);\
buffer_assure_space(wfth->frame_buffer, (phdr)->caplen);\
*data_offset = nstrace->xxx_offset + nstrace_buf_offset;\
while (nstrace_tmpbuff_off < nspr_##structname##_s) {\
nstrace_tmpbuff[nstrace_tmpbuff_off++] = nstrace_buf[nstrace_buf_offset++];\
@ -1246,7 +1247,7 @@ static gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info, gint64 *
}\
nstrace_buflen = NSPR_PAGESIZE_TRACE;\
nstrace->xxx_offset += nstrace_buflen;\
bytes_read = file_read(nstrace_buf, NSPR_PAGESIZE_TRACE, wth->fh);\
bytes_read = file_read(nstrace_buf, NSPR_PAGESIZE_TRACE, wfth->fh);\
if (bytes_read != NSPR_PAGESIZE_TRACE) {\
return FALSE;\
} else {\
@ -1259,16 +1260,16 @@ static gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info, gint64 *
while (nstrace_tmpbuff_off < nst_dataSize) {\
nstrace_tmpbuff[nstrace_tmpbuff_off++] = nstrace_buf[nstrace_buf_offset++];\
}\
memcpy(buffer_start_ptr(wth->frame_buffer), nstrace_tmpbuff, (phdr)->caplen);\
memcpy(buffer_start_ptr(wfth->frame_buffer), nstrace_tmpbuff, (phdr)->caplen);\
nstrace->nstrace_buf_offset = nstrace_buf_offset;\
nstrace->nstrace_buflen = nstrace_buflen = ((gint32)NSPR_PAGESIZE_TRACE);\
nstrace->nsg_creltime = nsg_creltime;\
return TRUE;\
} while(0)
static gboolean nstrace_read_v30(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
static gboolean nstrace_read_v30(wftap *wfth, int *err, gchar **err_info, gint64 *data_offset)
{
nstrace_t *nstrace = (nstrace_t *)wth->priv;
nstrace_t *nstrace = (nstrace_t *)wfth->priv;
guint64 nsg_creltime = nstrace->nsg_creltime;
gchar *nstrace_buf = nstrace->pnstrace_buf;
gint32 nstrace_buf_offset = nstrace->nstrace_buf_offset;
@ -1277,6 +1278,8 @@ static gboolean nstrace_read_v30(wtap *wth, int *err, gchar **err_info, gint64 *
guint32 nstrace_tmpbuff_off=0,nst_dataSize=0,rec_size=0,nsg_nextPageOffset=0;
nspr_hd_v20_t *hdp;
int bytes_read;
wtap* wth = (wtap*)wfth->tap_specific_data;
*err = 0;
*err_info = NULL;
@ -1322,15 +1325,15 @@ static gboolean nstrace_read_v30(wtap *wth, int *err, gchar **err_info, gint64 *
nstrace_buf_offset = 0;
nstrace->xxx_offset += nstrace_buflen;
nstrace_buflen = NSPR_PAGESIZE_TRACE;
} while((nstrace_buflen > 0) && (bytes_read = file_read(nstrace_buf, nstrace_buflen, wth->fh)) && (bytes_read == nstrace_buflen));
} while((nstrace_buflen > 0) && (bytes_read = file_read(nstrace_buf, nstrace_buflen, wfth->fh)) && (bytes_read == nstrace_buflen));
return FALSE;
}
#undef PACKET_DESCRIBE
static gboolean nstrace_seek_read_v10(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
static gboolean nstrace_seek_read_v10(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info)
{
nspr_hd_v10_t hdr;
int bytes_read;
@ -1339,18 +1342,19 @@ static gboolean nstrace_seek_read_v10(wtap *wth, gint64 seek_off,
unsigned int bytes_to_read;
nspr_pktracefull_v10_t *fp;
nspr_pktracepart_v10_t *pp;
struct wtap_pkthdr *phdr = (struct wtap_pkthdr *)header;
*err = 0;
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 record header.
*/
bytes_read = file_read((void *)&hdr, sizeof hdr, wth->random_fh);
bytes_read = file_read((void *)&hdr, sizeof hdr, wfth->random_fh);
if (bytes_read != sizeof hdr) {
*err = file_error(wth->random_fh, err_info);
*err = file_error(wfth->random_fh, err_info);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
return FALSE;
@ -1368,10 +1372,10 @@ static gboolean nstrace_seek_read_v10(wtap *wth, gint64 seek_off,
pd = buffer_start_ptr(buf);
memcpy(pd, (void *)&hdr, sizeof hdr);
if (record_length > sizeof hdr) {
bytes_to_read = (unsigned int)(record_length - sizeof hdr);
bytes_read = file_read(pd + sizeof hdr, bytes_to_read, wth->random_fh);
bytes_to_read = (unsigned int)(record_length - sizeof hdr);
bytes_read = file_read(pd + sizeof hdr, bytes_to_read, wfth->random_fh);
if (bytes_read < 0 || (unsigned int)bytes_read != bytes_to_read) {
*err = file_error(wth->random_fh, err_info);
*err = file_error(wfth->random_fh, err_info);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
return FALSE;
@ -1420,8 +1424,8 @@ static gboolean nstrace_seek_read_v10(wtap *wth, gint64 seek_off,
return TRUE;\
}while(0)
static gboolean nstrace_seek_read_v20(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
static gboolean nstrace_seek_read_v20(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info)
{
nspr_hd_v20_t hdr;
int bytes_read;
@ -1429,18 +1433,19 @@ static gboolean nstrace_seek_read_v20(wtap *wth, gint64 seek_off,
guint hdrlen;
guint8 *pd;
unsigned int bytes_to_read;
struct wtap_pkthdr *phdr = (struct wtap_pkthdr *)header;
*err = 0;
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 first 2 bytes of the record header.
*/
bytes_read = file_read((void *)&hdr, 2, wth->random_fh);
bytes_read = file_read((void *)&hdr, 2, wfth->random_fh);
if (bytes_read != 2) {
*err = file_error(wth->random_fh, err_info);
*err = file_error(wfth->random_fh, err_info);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
return FALSE;
@ -1451,9 +1456,9 @@ static gboolean nstrace_seek_read_v20(wtap *wth, gint64 seek_off,
** Is there a third byte? If so, read it.
*/
if (hdr.phd_RecordSizeLow & NSPR_V20RECORDSIZE_2BYTES) {
bytes_read = file_read((void *)&hdr.phd_RecordSizeHigh, 1, wth->random_fh);
bytes_read = file_read((void *)&hdr.phd_RecordSizeHigh, 1, wfth->random_fh);
if (bytes_read != 1) {
*err = file_error(wth->random_fh, err_info);
*err = file_error(wfth->random_fh, err_info);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
return FALSE;
@ -1474,9 +1479,9 @@ static gboolean nstrace_seek_read_v20(wtap *wth, gint64 seek_off,
memcpy(pd, (void *)&hdr, hdrlen);
if (record_length > hdrlen) {
bytes_to_read = (unsigned int)(record_length - hdrlen);
bytes_read = file_read(pd + hdrlen, bytes_to_read, wth->random_fh);
bytes_read = file_read(pd + hdrlen, bytes_to_read, wfth->random_fh);
if (bytes_read < 0 || (unsigned int)bytes_read != bytes_to_read) {
*err = file_error(wth->random_fh, err_info);
*err = file_error(wfth->random_fh, err_info);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
return FALSE;
@ -1536,8 +1541,8 @@ static gboolean nstrace_seek_read_v20(wtap *wth, gint64 seek_off,
}
static gboolean nstrace_seek_read_v30(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
static gboolean nstrace_seek_read_v30(wftap *wfth, gint64 seek_off,
void* header, Buffer *buf, int *err, gchar **err_info)
{
nspr_hd_v20_t hdr;
int bytes_read;
@ -1545,17 +1550,18 @@ static gboolean nstrace_seek_read_v30(wtap *wth, gint64 seek_off,
guint hdrlen;
guint8 *pd;
unsigned int bytes_to_read;
struct wtap_pkthdr *phdr = (struct wtap_pkthdr *)header;
*err = 0;
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 first 2 bytes of the record header.
*/
bytes_read = file_read((void *)&hdr, 2, wth->random_fh);
bytes_read = file_read((void *)&hdr, 2, wfth->random_fh);
if (bytes_read != 2) {
*err = file_error(wth->random_fh, err_info);
*err = file_error(wfth->random_fh, err_info);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
return FALSE;
@ -1566,9 +1572,9 @@ static gboolean nstrace_seek_read_v30(wtap *wth, gint64 seek_off,
** Is there a third byte? If so, read it.
*/
if (hdr.phd_RecordSizeLow & NSPR_V20RECORDSIZE_2BYTES) {
bytes_read = file_read((void *)&hdr.phd_RecordSizeHigh, 1, wth->random_fh);
bytes_read = file_read((void *)&hdr.phd_RecordSizeHigh, 1, wfth->random_fh);
if (bytes_read != 1) {
*err = file_error(wth->random_fh, err_info);
*err = file_error(wfth->random_fh, err_info);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
return FALSE;
@ -1589,9 +1595,9 @@ static gboolean nstrace_seek_read_v30(wtap *wth, gint64 seek_off,
memcpy(pd, (void *)&hdr, hdrlen);
if (record_length > hdrlen) {
bytes_to_read = (unsigned int)(record_length - hdrlen);
bytes_read = file_read(pd + hdrlen, bytes_to_read, wth->random_fh);
bytes_read = file_read(pd + hdrlen, bytes_to_read, wfth->random_fh);
if (bytes_read < 0 || (unsigned int)bytes_read != bytes_to_read) {
*err = file_error(wth->random_fh, err_info);
*err = file_error(wfth->random_fh, err_info);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
return FALSE;
@ -1619,9 +1625,9 @@ static gboolean nstrace_seek_read_v30(wtap *wth, gint64 seek_off,
/*
** Netscaler trace format close routines.
*/
static void nstrace_close(wtap *wth)
static void nstrace_close(wftap *wfth)
{
nstrace_t *nstrace = (nstrace_t *)wth->priv;
nstrace_t *nstrace = (nstrace_t *)wfth->priv;
g_free(nstrace->pnstrace_buf);
}
@ -1666,7 +1672,7 @@ int nstrace_30_dump_can_write_encap(int encap)
/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on
** failure */
gboolean nstrace_dump_open(wtap_dumper *wdh, int *err _U_)
gboolean nstrace_dump_open(wftap_dumper *wdh, int *err _U_)
{
nstrace_dump_t *nstrace;
@ -1682,7 +1688,7 @@ gboolean nstrace_dump_open(wtap_dumper *wdh, int *err _U_)
}
static gboolean nstrace_add_signature(wtap_dumper *wdh, int *err)
static gboolean nstrace_add_signature(wftap_dumper *wdh, int *err)
{
nstrace_dump_t *nstrace = (nstrace_dump_t *)wdh->priv;
@ -1700,7 +1706,7 @@ static gboolean nstrace_add_signature(wtap_dumper *wdh, int *err)
g_strlcpy(sig10.sig_Signature, NSPR_SIGSTR_V10, NSPR_SIGSIZE_V10);
/* Write the record into the file */
if (!wtap_dump_file_write(wdh, &sig10, nspr_signature_v10_s,
if (!wftap_dump_file_write(wdh, &sig10, nspr_signature_v10_s,
err))
return FALSE;
@ -1716,7 +1722,7 @@ static gboolean nstrace_add_signature(wtap_dumper *wdh, int *err)
memcpy(sig20.sig_Signature, NSPR_SIGSTR_V20, sizeof(NSPR_SIGSTR_V20));
/* Write the record into the file */
if (!wtap_dump_file_write(wdh, &sig20, sig20.sig_RecordSize,
if (!wftap_dump_file_write(wdh, &sig20, sig20.sig_RecordSize,
err))
return FALSE;
@ -1732,7 +1738,7 @@ static gboolean nstrace_add_signature(wtap_dumper *wdh, int *err)
memcpy(sig30.sig_Signature, NSPR_SIGSTR_V30, sizeof(NSPR_SIGSTR_V30));
/* Write the record into the file */
if (!wtap_dump_file_write(wdh, &sig30, sig30.sig_RecordSize,
if (!wftap_dump_file_write(wdh, &sig30, sig30.sig_RecordSize,
err))
return FALSE;
@ -1749,7 +1755,7 @@ static gboolean nstrace_add_signature(wtap_dumper *wdh, int *err)
static gboolean
nstrace_add_abstime(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
nstrace_add_abstime(wftap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err)
{
nstrace_dump_t *nstrace = (nstrace_dump_t *)wdh->priv;
@ -1776,7 +1782,7 @@ nstrace_add_abstime(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
memcpy(abs10.abs_Time, &abstime, sizeof abs10.abs_Time);
/* Write the record into the file */
if (!wtap_dump_file_write(wdh, &abs10, nspr_abstime_v10_s, err))
if (!wftap_dump_file_write(wdh, &abs10, nspr_abstime_v10_s, err))
return FALSE;
/* Move forward the page offset */
@ -1799,7 +1805,7 @@ nstrace_add_abstime(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
memcpy(abs20.abs_RelTime, &abstime, sizeof abs20.abs_RelTime);
/* Write the record into the file */
if (!wtap_dump_file_write(wdh, &abs20, nspr_abstime_v20_s, err))
if (!wftap_dump_file_write(wdh, &abs20, nspr_abstime_v20_s, err))
return FALSE;
/* Move forward the page offset */
@ -1817,7 +1823,7 @@ nstrace_add_abstime(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
/* Write a record for a packet to a dump file.
Returns TRUE on success, FALSE on failure. */
static gboolean nstrace_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
static gboolean nstrace_dump(wftap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err)
{
nstrace_dump_t *nstrace = (nstrace_dump_t *)wdh->priv;
@ -1856,7 +1862,7 @@ static gboolean nstrace_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
if (nstrace->page_offset + phdr->caplen >= nstrace->page_len)
{
/* Start on the next page */
if (wtap_dump_file_seek(wdh, (nstrace->page_len - nstrace->page_offset), SEEK_CUR, err) == -1)
if (wftap_dump_file_seek(wdh, (nstrace->page_len - nstrace->page_offset), SEEK_CUR, err) == -1)
return FALSE;
nstrace->page_offset = 0;
@ -1867,7 +1873,7 @@ static gboolean nstrace_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
}
/* Write the actual record as is */
if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err))
if (!wftap_dump_file_write(wdh, pd, phdr->caplen, err))
return FALSE;
nstrace->page_offset += (guint16) phdr->caplen;
@ -1895,7 +1901,7 @@ static gboolean nstrace_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
if (nstrace->page_offset + phdr->caplen >= nstrace->page_len)
{
/* Start on the next page */
if (wtap_dump_file_seek(wdh, (nstrace->page_len - nstrace->page_offset), SEEK_CUR, err) == -1)
if (wftap_dump_file_seek(wdh, (nstrace->page_len - nstrace->page_offset), SEEK_CUR, err) == -1)
return FALSE;
nstrace->page_offset = 0;
@ -1906,7 +1912,7 @@ static gboolean nstrace_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
}
/* Write the actual record as is */
if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err))
if (!wftap_dump_file_write(wdh, pd, phdr->caplen, err))
return FALSE;
nstrace->page_offset += (guint16) phdr->caplen;
@ -1928,7 +1934,7 @@ static gboolean nstrace_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
if (nstrace->page_offset + phdr->caplen >= nstrace->page_len)
{
/* Start on the next page */
if (wtap_dump_file_seek(wdh, (nstrace->page_len - nstrace->page_offset), SEEK_CUR, err) == -1)
if (wftap_dump_file_seek(wdh, (nstrace->page_len - nstrace->page_offset), SEEK_CUR, err) == -1)
return FALSE;
nstrace->page_offset = 0;
@ -1939,7 +1945,7 @@ static gboolean nstrace_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
}
/* Write the actual record as is */
if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err))
if (!wftap_dump_file_write(wdh, pd, phdr->caplen, err))
return FALSE;
nstrace->page_offset += (guint16) phdr->caplen;

Some files were not shown because too many files have changed in this diff Show More