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 =