forked from osmocom/wireshark
Revert "Refactor Wiretap"
This reverts commit 1abeb277f5
.
This isn't building, and looks as if it requires significant work to fix.
Change-Id: I622b1bb243e353e874883a302ab419532b7601f2
Reviewed-on: https://code.wireshark.org/review/1568
Reviewed-by: Guy Harris <guy@alum.mit.edu>
daniel/osmux
parent
a651f3e5ed
commit
a1b1c8bed5
18
capinfos.c
18
capinfos.c
|
@ -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 = asctime(localtime(&timer));
|
||||
time_string_ctime = ctime(&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(wftap *wth, const char *filename)
|
||||
process_cap_file(wtap *wth, const char *filename)
|
||||
{
|
||||
int status = 0;
|
||||
int err;
|
||||
|
@ -868,7 +868,7 @@ process_cap_file(wftap *wth, const char *filename)
|
|||
}
|
||||
|
||||
/* Per-packet encapsulation */
|
||||
if (wftap_file_encap(wth) == WTAP_ENCAP_PER_PACKET) {
|
||||
if (wtap_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(wftap *wth, const char *filename)
|
|||
}
|
||||
|
||||
/* File size */
|
||||
size = wftap_file_size(wth, &err);
|
||||
size = wtap_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(wftap *wth, const char *filename)
|
|||
cf_info.filesize = size;
|
||||
|
||||
/* File Type */
|
||||
cf_info.file_type = wftap_file_type_subtype(wth);
|
||||
cf_info.iscompressed = wftap_iscompressed(wth);
|
||||
cf_info.file_type = wtap_file_type_subtype(wth);
|
||||
cf_info.iscompressed = wtap_iscompressed(wth);
|
||||
|
||||
/* File Encapsulation */
|
||||
cf_info.file_encap = wftap_file_encap(wth);
|
||||
cf_info.file_encap = wtap_file_encap(wth);
|
||||
|
||||
/* Packet size limit (snaplen) */
|
||||
cf_info.snaplen = wftap_snapshot_length(wth);
|
||||
cf_info.snaplen = wtap_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[])
|
||||
{
|
||||
wftap *wth;
|
||||
wtap *wth;
|
||||
int err;
|
||||
gchar *err_info;
|
||||
int opt;
|
||||
|
|
|
@ -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 wftap* wftap; /* current wftap file */
|
||||
struct wtap* wtap; /* current wtap 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.wftap = NULL;
|
||||
info_data.wtap = 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.wftap != NULL) {
|
||||
wftap_close(info_data.wftap);
|
||||
if(info_data.wtap != NULL) {
|
||||
wtap_close(info_data.wtap);
|
||||
}
|
||||
|
||||
info_data.wftap = wtap_open_offline(new_filename, WTAP_TYPE_AUTO, &err, &err_info, FALSE);
|
||||
if (!info_data.wftap) {
|
||||
info_data.wtap = wtap_open_offline(new_filename, WTAP_TYPE_AUTO, &err, &err_info, FALSE);
|
||||
if (!info_data.wtap) {
|
||||
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) {
|
||||
wftap_cleareof(info_data.wftap);
|
||||
if (wtap_read(info_data.wftap, &err, &err_info, &data_offset)) {
|
||||
phdr = wtap_phdr(info_data.wftap);
|
||||
wtap_cleareof(info_data.wtap);
|
||||
if (wtap_read(info_data.wtap, &err, &err_info, &data_offset)) {
|
||||
phdr = wtap_phdr(info_data.wtap);
|
||||
pseudo_header = &phdr->pseudo_header;
|
||||
wtap_linktype = phdr->pkt_encap;
|
||||
buf = wftap_buf_ptr(info_data.wftap);
|
||||
buf = wtap_buf_ptr(info_data.wtap);
|
||||
|
||||
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.wftap)
|
||||
wtap_close(info_data.wftap);
|
||||
if(info_data.wtap)
|
||||
wtap_close(info_data.wtap);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ failure_message(const char *msg_format _U_, va_list ap _U_)
|
|||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
wftap *wth;
|
||||
wtap *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(wftap_file_type_subtype(wth)));
|
||||
wftap_close(wth);
|
||||
printf("%s: %s\n", argv[i], wtap_file_type_subtype_short_string(wtap_file_type_subtype(wth)));
|
||||
wtap_close(wth);
|
||||
} else {
|
||||
if (err == WTAP_ERR_FILE_UNKNOWN_FORMAT)
|
||||
printf("%s: unknown\n", argv[i]);
|
||||
|
|
2
cfile.c
2
cfile.c
|
@ -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->wfth);
|
||||
idb_info = wtap_file_get_idb_info(cf->wth);
|
||||
|
||||
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
10
cfile.h
|
@ -63,11 +63,6 @@ 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 */
|
||||
|
@ -92,7 +87,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 */
|
||||
wftap *wfth; /* Tap session */
|
||||
wtap *wth; /* Wiretap session */
|
||||
dfilter_t *rfcode; /* Compiled read filter program */
|
||||
dfilter_t *dfcode; /* Compiled display filter program */
|
||||
gchar *dfilter; /* Display filter string */
|
||||
|
@ -109,7 +104,8 @@ 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 */
|
||||
phdr_t hdr; /* Packet/File header */
|
||||
/* packet data */
|
||||
struct wtap_pkthdr phdr; /* Packet header */
|
||||
Buffer buf; /* Packet data */
|
||||
/* frames */
|
||||
frame_data_sequence *frames; /* Sequence of frames, if we're keeping that information */
|
||||
|
|
32
editcap.c
32
editcap.c
|
@ -310,9 +310,9 @@ selected(int recno)
|
|||
|
||||
/* is the packet in the selected timeframe */
|
||||
static gboolean
|
||||
check_timestamp(wftap *wfth)
|
||||
check_timestamp(wtap *wth)
|
||||
{
|
||||
struct wtap_pkthdr *pkthdr = wtap_phdr(wfth);
|
||||
struct wtap_pkthdr *pkthdr = wtap_phdr(wth);
|
||||
|
||||
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[])
|
||||
{
|
||||
wftap *wth;
|
||||
wtap *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;
|
||||
wftap_dumper *pdh = NULL;
|
||||
wtap_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 = g_strtod(optarg, &p);
|
||||
err_prob = 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(wftap_file_type_subtype(wth)));
|
||||
wtap_file_type_subtype_string(wtap_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 = wftap_file_encap(wth);
|
||||
out_frame_type = wtap_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 = wftap_buf_ptr(wth);
|
||||
buf = wtap_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, wftap_snapshot_length(wth)) : wftap_snapshot_length(wth),
|
||||
snaplen ? MIN(snaplen, wtap_snapshot_length(wth)) : wtap_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 (!wftap_dump_close(pdh, &err)) {
|
||||
if (!wtap_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, wftap_snapshot_length(wth)) : wftap_snapshot_length(wth),
|
||||
snaplen ? MIN(snaplen, wtap_snapshot_length(wth)) : wtap_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 (!wftap_dump_close(pdh, &err)) {
|
||||
if (!wtap_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, wftap_snapshot_length(wth)) : wftap_snapshot_length(wth),
|
||||
snaplen ? MIN(snaplen, wtap_snapshot_length(wth)) : wtap_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 (wftap_file_type_subtype(wth) == WTAP_FILE_TYPE_SUBTYPE_CATAPULT_DCT2000)
|
||||
if (wtap_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, wftap_snapshot_length(wth)): wftap_snapshot_length(wth),
|
||||
snaplen ? MIN(snaplen, wtap_snapshot_length(wth)): wtap_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 (!wftap_dump_close(pdh, &err)) {
|
||||
if (!wtap_dump_close(pdh, &err)) {
|
||||
fprintf(stderr, "editcap: Error writing to %s: %s\n", filename,
|
||||
wtap_strerror(err));
|
||||
exit(2);
|
||||
|
|
|
@ -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 wftap_dumper struct during write operations. A wtap_dumper struct
|
||||
can be a wtap_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;
|
||||
wftap_dumper *wdh; /* will be NULL during read usage */
|
||||
wtap_dumper *wdh; /* will be NULL during read usage */
|
||||
gboolean expired;
|
||||
};
|
||||
|
||||
/* a "CaptureInfo" object can also be different things under the hood. */
|
||||
struct _wslua_captureinfo {
|
||||
wftap *wfth; /* will be NULL during write usage */
|
||||
wftap_dumper *wdh; /* will be NULL during read usage */
|
||||
wtap *wth; /* will be NULL during write usage */
|
||||
wtap_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 wftap_dumper* Dumper;
|
||||
typedef wtap_dumper* Dumper;
|
||||
typedef struct lua_pseudo_header* PseudoHeader;
|
||||
typedef tvbparse_t* Parser;
|
||||
typedef tvbparse_wanted_t* Rule;
|
||||
|
|
|
@ -266,7 +266,7 @@ WSLUA_METHOD Dumper_close(lua_State* L) {
|
|||
|
||||
g_hash_table_remove(dumper_encaps,*dp);
|
||||
|
||||
if (!wftap_dump_close(*dp, &err)) {
|
||||
if (!wtap_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;
|
||||
|
||||
wftap_dump_flush(d);
|
||||
wtap_dump_flush(d);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -455,7 +455,7 @@ static int Dumper__gc(lua_State* L) {
|
|||
|
||||
g_hash_table_remove(dumper_encaps,*dp);
|
||||
|
||||
if (!wftap_dump_close(*dp, &err)) {
|
||||
if (!wtap_dump_close(*dp, &err)) {
|
||||
luaL_error(L,"error closing: %s",
|
||||
wtap_strerror(err));
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
|
||||
#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>
|
||||
|
@ -98,7 +97,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 wftap_dumper struct during write operations. A wtap_dumper struct
|
||||
can be a wtap_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) {
|
||||
|
@ -109,7 +108,7 @@ static File* push_File(lua_State* L, FILE_T ft) {
|
|||
return pushFile(L,f);
|
||||
}
|
||||
|
||||
static File* push_Wdh(lua_State* L, wftap_dumper *wdh) {
|
||||
static File* push_Wdh(lua_State* L, wtap_dumper *wdh) {
|
||||
File f = (File) g_malloc(sizeof(struct _wslua_file));
|
||||
f->file = (FILE_T)wdh->fh;
|
||||
f->wdh = wdh;
|
||||
|
@ -358,7 +357,7 @@ WSLUA_METHOD File_seek(lua_State* L) {
|
|||
lua_pushnumber(L, (lua_Number)(file_tell(f->file)));
|
||||
}
|
||||
else {
|
||||
offset = wftap_dump_file_seek(f->wdh, offset, mode[op], &err);
|
||||
offset = wtap_dump_file_seek(f->wdh, offset, mode[op], &err);
|
||||
|
||||
if (offset < 0) {
|
||||
lua_pushnil(L); /* error */
|
||||
|
@ -366,7 +365,7 @@ WSLUA_METHOD File_seek(lua_State* L) {
|
|||
return 2;
|
||||
}
|
||||
|
||||
offset = wftap_dump_file_tell(f->wdh, &err);
|
||||
offset = wtap_dump_file_tell(f->wdh, &err);
|
||||
|
||||
if (offset < 0) {
|
||||
lua_pushnil(L); /* error */
|
||||
|
@ -435,7 +434,7 @@ WSLUA_METHOD File_write(lua_State* L) {
|
|||
for (; nargs--; arg++) {
|
||||
size_t len;
|
||||
const char *s = luaL_checklstring(L, arg, &len);
|
||||
status = wftap_dump_file_write(f->wdh, s, len, &err);
|
||||
status = wtap_dump_file_write(f->wdh, s, len, &err);
|
||||
if (!status) break;
|
||||
f->wdh->bytes_dumped += len;
|
||||
}
|
||||
|
@ -516,7 +515,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 wftap_dumper,
|
||||
* In other words it handles the "priv" member of wtap and wtap_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
|
||||
|
@ -532,20 +531,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, wftap *wfth) {
|
||||
static void create_wth_priv(lua_State* L, wtap *wth) {
|
||||
file_priv_t *priv = (file_priv_t*)g_malloc(sizeof(file_priv_t));
|
||||
|
||||
if (wfth->priv != NULL) {
|
||||
if (wth->priv != NULL) {
|
||||
luaL_error(L, "Cannot create wtap private data because there already is private data");
|
||||
return;
|
||||
}
|
||||
priv->table_ref = LUA_NOREF;
|
||||
wfth->priv = (void*) priv;
|
||||
wth->priv = (void*) priv;
|
||||
}
|
||||
|
||||
/* gets the private data table from wtap */
|
||||
static int get_wth_priv_table_ref(lua_State* L, wftap *wfth) {
|
||||
file_priv_t *priv = (file_priv_t*) wfth->priv;
|
||||
static int get_wth_priv_table_ref(lua_State* L, wtap *wth) {
|
||||
file_priv_t *priv = (file_priv_t*) wth->priv;
|
||||
|
||||
if (!priv) {
|
||||
/* shouldn't be possible */
|
||||
|
@ -560,8 +559,8 @@ static int get_wth_priv_table_ref(lua_State* L, wftap *wfth) {
|
|||
}
|
||||
|
||||
/* sets the private data to wtap - the table is presumed on top of stack */
|
||||
static int set_wth_priv_table_ref(lua_State* L, wftap *wfth) {
|
||||
file_priv_t *priv = (file_priv_t*) wfth->priv;
|
||||
static int set_wth_priv_table_ref(lua_State* L, wtap *wth) {
|
||||
file_priv_t *priv = (file_priv_t*) wth->priv;
|
||||
|
||||
if (!priv) {
|
||||
/* shouldn't be possible */
|
||||
|
@ -592,8 +591,8 @@ static int set_wth_priv_table_ref(lua_State* L, wftap *wfth) {
|
|||
}
|
||||
|
||||
/* remove, deref, and free the wtap->priv data */
|
||||
static void remove_wth_priv(lua_State* L, wftap *wfth) {
|
||||
file_priv_t *priv = (file_priv_t*) wfth->priv;
|
||||
static void remove_wth_priv(lua_State* L, wtap *wth) {
|
||||
file_priv_t *priv = (file_priv_t*) wth->priv;
|
||||
|
||||
if (!priv) {
|
||||
/* shouldn't be possible */
|
||||
|
@ -603,29 +602,29 @@ static void remove_wth_priv(lua_State* L, wftap *wfth) {
|
|||
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, priv->table_ref);
|
||||
|
||||
g_free(wfth->priv);
|
||||
wfth->priv = NULL;
|
||||
g_free(wth->priv);
|
||||
wth->priv = NULL;
|
||||
}
|
||||
|
||||
/* create and set the wftap_dumper->priv private data for the file instance */
|
||||
static void create_wdh_priv(lua_State* L, wftap_dumper *wdh) {
|
||||
/* create and set the wtap_dumper->priv private data for the file instance */
|
||||
static void create_wdh_priv(lua_State* L, wtap_dumper *wdh) {
|
||||
file_priv_t *priv = (file_priv_t*)g_malloc(sizeof(file_priv_t));
|
||||
|
||||
if (wdh->priv != NULL) {
|
||||
luaL_error(L, "Cannot create wftap_dumper private data because there already is private data");
|
||||
luaL_error(L, "Cannot create wtap_dumper private data because there already is private data");
|
||||
return;
|
||||
}
|
||||
priv->table_ref = LUA_NOREF;
|
||||
wdh->priv = (void*) priv;
|
||||
}
|
||||
|
||||
/* get the private data from wftap_dumper */
|
||||
static int get_wdh_priv_table_ref(lua_State* L, wftap_dumper *wdh) {
|
||||
/* get the private data from wtap_dumper */
|
||||
static int get_wdh_priv_table_ref(lua_State* L, wtap_dumper *wdh) {
|
||||
file_priv_t *priv = (file_priv_t*) wdh->priv;
|
||||
|
||||
if (!priv) {
|
||||
/* shouldn't be possible */
|
||||
luaL_error(L, "Cannot get wftap_dumper private data: it is null");
|
||||
luaL_error(L, "Cannot get wtap_dumper private data: it is null");
|
||||
return LUA_NOREF;
|
||||
}
|
||||
|
||||
|
@ -636,7 +635,7 @@ static int get_wdh_priv_table_ref(lua_State* L, wftap_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, wftap_dumper *wdh) {
|
||||
static int set_wdh_priv_table_ref(lua_State* L, wtap_dumper *wdh) {
|
||||
file_priv_t *priv = (file_priv_t*) wdh->priv;
|
||||
|
||||
if (!priv) {
|
||||
|
@ -667,22 +666,22 @@ static int set_wdh_priv_table_ref(lua_State* L, wftap_dumper *wdh) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* remove and deref the wftap_dumper->priv data */
|
||||
static void remove_wdh_priv(lua_State* L, wftap_dumper *wdh) {
|
||||
/* remove and deref the wtap_dumper->priv data */
|
||||
static void remove_wdh_priv(lua_State* L, wtap_dumper *wdh) {
|
||||
file_priv_t *priv = (file_priv_t*) wdh->priv;
|
||||
|
||||
if (!priv) {
|
||||
/* shouldn't be possible */
|
||||
luaL_error(L, "Cannot remove wftap_dumper private data: it is null");
|
||||
luaL_error(L, "Cannot remove wtap_dumper private data: it is null");
|
||||
return;
|
||||
}
|
||||
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, priv->table_ref);
|
||||
/* we do NOT free wftap_dumper's priv member - wftap_dump_close() free's it */
|
||||
/* we do NOT free wtap_dumper's priv member - wtap_dump_close() free's it */
|
||||
}
|
||||
|
||||
|
||||
WSLUA_CLASS_DEFINE(CaptureInfo,FAIL_ON_NULL_MEMBER_OR_EXPIRED("CaptureInfo",wfth),NOP);
|
||||
WSLUA_CLASS_DEFINE(CaptureInfo,FAIL_ON_NULL_MEMBER_OR_EXPIRED("CaptureInfo",wth),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()`.
|
||||
|
@ -697,17 +696,17 @@ WSLUA_CLASS_DEFINE(CaptureInfo,FAIL_ON_NULL_MEMBER_OR_EXPIRED("CaptureInfo",wfth
|
|||
@since 1.11.3
|
||||
*/
|
||||
|
||||
static CaptureInfo* push_CaptureInfo(lua_State* L, wftap *wfth, const gboolean first_time) {
|
||||
static CaptureInfo* push_CaptureInfo(lua_State* L, wtap *wth, const gboolean first_time) {
|
||||
CaptureInfo f = (CaptureInfo) g_malloc0(sizeof(struct _wslua_captureinfo));
|
||||
f->wfth = wfth;
|
||||
f->wth = wth;
|
||||
f->wdh = NULL;
|
||||
f->expired = FALSE;
|
||||
|
||||
if (first_time) {
|
||||
/* XXX: need to do this? */
|
||||
wfth->file_encap = WTAP_ENCAP_UNKNOWN;
|
||||
wfth->tsprecision = WTAP_FILE_TSPREC_SEC;
|
||||
wfth->snapshot_length = 0;
|
||||
wth->file_encap = WTAP_ENCAP_UNKNOWN;
|
||||
wth->tsprecision = WTAP_FILE_TSPREC_SEC;
|
||||
wth->snapshot_length = 0;
|
||||
}
|
||||
|
||||
return pushCaptureInfo(L,f);
|
||||
|
@ -717,13 +716,12 @@ WSLUA_METAMETHOD CaptureInfo__tostring(lua_State* L) {
|
|||
/* Generates a string of debug info for the CaptureInfo */
|
||||
CaptureInfo fi = toCaptureInfo(L,1);
|
||||
|
||||
if (!fi || !fi->wfth) {
|
||||
if (!fi || !fi->wth) {
|
||||
lua_pushstring(L,"CaptureInfo pointer is NULL!");
|
||||
} else {
|
||||
wftap *wfth = fi->wfth;
|
||||
wtap* wth = (wtap*)wfth->tap_specific_data;
|
||||
wtap *wth = fi->wth;
|
||||
lua_pushfstring(L, "CaptureInfo: file_type_subtype=%d, snapshot_length=%d, pkt_encap=%d, tsprecision='%s'",
|
||||
wfth->file_type_subtype, wfth->snapshot_length, wth->phdr.pkt_encap, wfth->tsprecision);
|
||||
wth->file_type_subtype, wth->snapshot_length, wth->phdr.pkt_encap, wth->tsprecision);
|
||||
}
|
||||
|
||||
WSLUA_RETURN(1); /* String of debug information. */
|
||||
|
@ -742,24 +740,23 @@ 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,wfth->file_encap);
|
||||
WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(CaptureInfo,encap,wfth->file_encap,int);
|
||||
WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(CaptureInfo,encap,wth->file_encap);
|
||||
WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(CaptureInfo,encap,wth->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,wfth->tsprecision);
|
||||
WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(CaptureInfo,time_precision,wfth->tsprecision,int);
|
||||
WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(CaptureInfo,time_precision,wth->tsprecision);
|
||||
WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(CaptureInfo,time_precision,wth->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,wfth->snapshot_length);
|
||||
WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(CaptureInfo,snapshot_length,wfth->snapshot_length,guint);
|
||||
WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(CaptureInfo,snapshot_length,wth->snapshot_length);
|
||||
WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(CaptureInfo,snapshot_length,wth->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);
|
||||
|
@ -779,7 +776,6 @@ 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.
|
||||
|
||||
|
@ -795,8 +791,7 @@ 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);
|
||||
wftap *wfth = fi->wfth;
|
||||
wtap *wth = (wtap*)wfth->tap_specific_data;
|
||||
wtap *wth = fi->wth;
|
||||
const char *addr = NULL;
|
||||
const char *name = NULL;
|
||||
size_t addr_len = 0;
|
||||
|
@ -919,24 +914,22 @@ 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->wfth);
|
||||
return get_wth_priv_table_ref(L, fi->wth);
|
||||
}
|
||||
|
||||
static int CaptureInfo_set_private_table(lua_State* L) {
|
||||
CaptureInfo fi = checkCaptureInfo(L,1);
|
||||
return set_wth_priv_table_ref(L, fi->wfth);
|
||||
return set_wth_priv_table_ref(L, fi->wth);
|
||||
}
|
||||
|
||||
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 }
|
||||
|
@ -970,9 +963,9 @@ WSLUA_CLASS_DEFINE(CaptureInfoConst,FAIL_ON_NULL_MEMBER_OR_EXPIRED("CaptureInfoC
|
|||
@since 1.11.3
|
||||
*/
|
||||
|
||||
static CaptureInfoConst* push_CaptureInfoConst(lua_State* L, wftap_dumper *wdh) {
|
||||
static CaptureInfoConst* push_CaptureInfoConst(lua_State* L, wtap_dumper *wdh) {
|
||||
CaptureInfoConst f = (CaptureInfoConst) g_malloc0(sizeof(struct _wslua_captureinfo));
|
||||
f->wfth = NULL;
|
||||
f->wth = NULL;
|
||||
f->wdh = wdh;
|
||||
f->expired = FALSE;
|
||||
return pushCaptureInfoConst(L,f);
|
||||
|
@ -985,7 +978,7 @@ WSLUA_METAMETHOD CaptureInfoConst__tostring(lua_State* L) {
|
|||
if (!fi || !fi->wdh) {
|
||||
lua_pushstring(L,"CaptureInfoConst pointer is NULL!");
|
||||
} else {
|
||||
wftap_dumper *wdh = fi->wdh;
|
||||
wtap_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);
|
||||
}
|
||||
|
@ -1007,7 +1000,6 @@ 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);
|
||||
|
@ -1023,7 +1015,6 @@ 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
|
||||
|
@ -1037,8 +1028,7 @@ 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);
|
||||
wftap_dumper *wfdh = fi->wdh;
|
||||
wtap_dumper *wdh = (wtap_dumper*)wfdh->tap_specific_data;
|
||||
wtap_dumper *wdh = fi->wdh;
|
||||
|
||||
/* create the main table to return */
|
||||
lua_newtable(L);
|
||||
|
@ -1136,12 +1126,10 @@ 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 }
|
||||
|
@ -1430,7 +1418,7 @@ WSLUA_METHOD FrameInfoConst_write_data(lua_State* L) {
|
|||
if (len > fi->phdr->caplen)
|
||||
len = fi->phdr->caplen;
|
||||
|
||||
if (!wftap_dump_file_write(fh->wdh, fi->pd, (size_t)(len), &err)) {
|
||||
if (!wtap_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);
|
||||
|
@ -1630,16 +1618,16 @@ static gboolean in_routine = FALSE;
|
|||
|
||||
/* some declarations */
|
||||
static gboolean
|
||||
wslua_filehandler_read(wftap *wfth, int *err, gchar **err_info,
|
||||
wslua_filehandler_read(wtap *wth, int *err, gchar **err_info,
|
||||
gint64 *data_offset);
|
||||
static gboolean
|
||||
wslua_filehandler_seek_read(wftap *wfth, gint64 seek_off,
|
||||
void* header, Buffer *buf,
|
||||
wslua_filehandler_seek_read(wtap *wth, gint64 seek_off,
|
||||
struct wtap_pkthdr *phdr, Buffer *buf,
|
||||
int *err, gchar **err_info);
|
||||
static void
|
||||
wslua_filehandler_close(wftap *wfth);
|
||||
wslua_filehandler_close(wtap *wth);
|
||||
static void
|
||||
wslua_filehandler_sequential_close(wftap *wfth);
|
||||
wslua_filehandler_sequential_close(wtap *wth);
|
||||
|
||||
|
||||
/* This is our one-and-only open routine for file handling. When called by
|
||||
|
@ -1654,9 +1642,9 @@ wslua_filehandler_sequential_close(wftap *wfth);
|
|||
* field in the "struct wtap" to the type of the file.
|
||||
*/
|
||||
static int
|
||||
wslua_filehandler_open(wftap *wfth, int *err _U_, gchar **err_info)
|
||||
wslua_filehandler_open(wtap *wth, int *err _U_, gchar **err_info)
|
||||
{
|
||||
FileHandler fh = (FileHandler)(wfth->wslua_data);
|
||||
FileHandler fh = (FileHandler)(wth->wslua_data);
|
||||
int retval = 0;
|
||||
lua_State* L = NULL;
|
||||
File *fp = NULL;
|
||||
|
@ -1664,10 +1652,10 @@ wslua_filehandler_open(wftap *wfth, int *err _U_, gchar **err_info)
|
|||
|
||||
INIT_FILEHANDLER_ROUTINE(read_open,0);
|
||||
|
||||
create_wth_priv(L, wfth);
|
||||
create_wth_priv(L, wth);
|
||||
|
||||
fp = push_File(L, wfth->fh);
|
||||
fc = push_CaptureInfo(L, wfth, TRUE);
|
||||
fp = push_File(L, wth->fh);
|
||||
fc = push_CaptureInfo(L, wth, TRUE);
|
||||
|
||||
errno = WTAP_ERR_CANT_READ;
|
||||
switch ( lua_pcall(L,2,1,1) ) {
|
||||
|
@ -1686,32 +1674,32 @@ wslua_filehandler_open(wftap *wfth, int *err _U_, gchar **err_info)
|
|||
/* this is our file type - set the routines and settings into wtap */
|
||||
|
||||
if (fh->read_ref != LUA_NOREF) {
|
||||
wfth->subtype_read = wslua_filehandler_read;
|
||||
wth->subtype_read = wslua_filehandler_read;
|
||||
}
|
||||
else return 0;
|
||||
|
||||
if (fh->seek_read_ref != LUA_NOREF) {
|
||||
wfth->subtype_seek_read = wslua_filehandler_seek_read;
|
||||
wth->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)
|
||||
wfth->subtype_close = wslua_filehandler_close;
|
||||
wth->subtype_close = wslua_filehandler_close;
|
||||
else
|
||||
wfth->subtype_close = NULL;
|
||||
wth->subtype_close = NULL;
|
||||
|
||||
/* it's ok to not have a sequential close routine */
|
||||
if (fh->seq_read_close_ref != LUA_NOREF)
|
||||
wfth->subtype_sequential_close = wslua_filehandler_sequential_close;
|
||||
wth->subtype_sequential_close = wslua_filehandler_sequential_close;
|
||||
else
|
||||
wfth->subtype_sequential_close = NULL;
|
||||
wth->subtype_sequential_close = NULL;
|
||||
|
||||
wfth->file_type_subtype = fh->file_type;
|
||||
wth->file_type_subtype = fh->file_type;
|
||||
}
|
||||
else {
|
||||
/* not our file type */
|
||||
remove_wth_priv(L, wfth);
|
||||
remove_wth_priv(L, wth);
|
||||
}
|
||||
|
||||
lua_settop(L,0);
|
||||
|
@ -1725,16 +1713,15 @@ wslua_filehandler_open(wftap *wfth, int *err _U_, gchar **err_info)
|
|||
* This will be the seek_off parameter when this frame is re-read.
|
||||
*/
|
||||
static gboolean
|
||||
wslua_filehandler_read(wftap *wfth, int *err, gchar **err_info,
|
||||
wslua_filehandler_read(wtap *wth, int *err, gchar **err_info,
|
||||
gint64 *data_offset)
|
||||
{
|
||||
FileHandler fh = (FileHandler)(wfth->wslua_data);
|
||||
FileHandler fh = (FileHandler)(wth->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);
|
||||
|
||||
|
@ -1743,9 +1730,9 @@ wslua_filehandler_read(wftap *wfth, int *err, gchar **err_info,
|
|||
|
||||
wth->phdr.opt_comment = NULL;
|
||||
|
||||
fp = push_File(L, wfth->fh);
|
||||
fc = push_CaptureInfo(L, wfth, FALSE);
|
||||
fi = push_FrameInfo(L, &wth->phdr, wfth->frame_buffer);
|
||||
fp = push_File(L, wth->fh);
|
||||
fc = push_CaptureInfo(L, wth, FALSE);
|
||||
fi = push_FrameInfo(L, &wth->phdr, wth->frame_buffer);
|
||||
|
||||
errno = WTAP_ERR_CANT_READ;
|
||||
switch ( lua_pcall(L,3,1,1) ) {
|
||||
|
@ -1774,17 +1761,16 @@ wslua_filehandler_read(wftap *wfth, int *err, gchar **err_info,
|
|||
* success, FALSE on error.
|
||||
*/
|
||||
static gboolean
|
||||
wslua_filehandler_seek_read(wftap *wfth, gint64 seek_off,
|
||||
void* header, Buffer *buf,
|
||||
wslua_filehandler_seek_read(wtap *wth, gint64 seek_off,
|
||||
struct wtap_pkthdr *phdr, Buffer *buf,
|
||||
int *err, gchar **err_info)
|
||||
{
|
||||
FileHandler fh = (FileHandler)(wfth->wslua_data);
|
||||
FileHandler fh = (FileHandler)(wth->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);
|
||||
|
||||
|
@ -1792,8 +1778,8 @@ wslua_filehandler_seek_read(wftap *wfth, gint64 seek_off,
|
|||
*err = errno = 0;
|
||||
phdr->opt_comment = NULL;
|
||||
|
||||
fp = push_File(L, wfth->random_fh);
|
||||
fc = push_CaptureInfo(L, wfth, FALSE);
|
||||
fp = push_File(L, wth->random_fh);
|
||||
fc = push_CaptureInfo(L, wth, FALSE);
|
||||
fi = push_FrameInfo(L, phdr, buf);
|
||||
lua_pushnumber(L, (lua_Number)seek_off);
|
||||
|
||||
|
@ -1826,17 +1812,17 @@ wslua_filehandler_seek_read(wftap *wfth, gint64 seek_off,
|
|||
/* Classic wtap close function, called by wtap core.
|
||||
*/
|
||||
static void
|
||||
wslua_filehandler_close(wftap *wfth)
|
||||
wslua_filehandler_close(wtap *wth)
|
||||
{
|
||||
FileHandler fh = (FileHandler)(wfth->wslua_data);
|
||||
FileHandler fh = (FileHandler)(wth->wslua_data);
|
||||
lua_State* L = NULL;
|
||||
File *fp = NULL;
|
||||
CaptureInfo *fc = NULL;
|
||||
|
||||
INIT_FILEHANDLER_ROUTINE(read_close,);
|
||||
|
||||
fp = push_File(L, wfth->fh);
|
||||
fc = push_CaptureInfo(L, wfth, FALSE);
|
||||
fp = push_File(L, wth->fh);
|
||||
fc = push_CaptureInfo(L, wth, FALSE);
|
||||
|
||||
switch ( lua_pcall(L,2,1,1) ) {
|
||||
case 0:
|
||||
|
@ -1846,7 +1832,7 @@ wslua_filehandler_close(wftap *wfth)
|
|||
|
||||
END_FILEHANDLER_ROUTINE();
|
||||
|
||||
remove_wth_priv(L, wfth);
|
||||
remove_wth_priv(L, wth);
|
||||
|
||||
(*fp)->expired = TRUE;
|
||||
(*fc)->expired = TRUE;
|
||||
|
@ -1858,17 +1844,17 @@ wslua_filehandler_close(wftap *wfth)
|
|||
/* Classic wtap sequential close function, called by wtap core.
|
||||
*/
|
||||
static void
|
||||
wslua_filehandler_sequential_close(wftap *wfth)
|
||||
wslua_filehandler_sequential_close(wtap *wth)
|
||||
{
|
||||
FileHandler fh = (FileHandler)(wfth->wslua_data);
|
||||
FileHandler fh = (FileHandler)(wth->wslua_data);
|
||||
lua_State* L = NULL;
|
||||
File *fp = NULL;
|
||||
CaptureInfo *fc = NULL;
|
||||
|
||||
INIT_FILEHANDLER_ROUTINE(seq_read_close,);
|
||||
|
||||
fp = push_File(L, wfth->fh);
|
||||
fc = push_CaptureInfo(L, wfth, FALSE);
|
||||
fp = push_File(L, wth->fh);
|
||||
fc = push_CaptureInfo(L, wth, FALSE);
|
||||
|
||||
switch ( lua_pcall(L,2,1,1) ) {
|
||||
case 0:
|
||||
|
@ -1932,17 +1918,17 @@ wslua_filehandler_can_write_encap(int encap, void* data)
|
|||
|
||||
/* some declarations */
|
||||
static gboolean
|
||||
wslua_filehandler_dump(wftap_dumper *wdh, const struct wtap_pkthdr *phdr,
|
||||
wslua_filehandler_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
|
||||
const guint8 *pd, int *err);
|
||||
static gboolean
|
||||
wslua_filehandler_dump_close(wftap_dumper *wdh, int *err);
|
||||
wslua_filehandler_dump_close(wtap_dumper *wdh, int *err);
|
||||
|
||||
|
||||
/* The classic wtap dump_open function.
|
||||
* This returns 1 (TRUE) on success.
|
||||
*/
|
||||
static int
|
||||
wslua_filehandler_dump_open(wftap_dumper *wdh, int *err)
|
||||
wslua_filehandler_dump_open(wtap_dumper *wdh, int *err)
|
||||
{
|
||||
FileHandler fh = (FileHandler)(wdh->wslua_data);
|
||||
int retval = 0;
|
||||
|
@ -2001,7 +1987,7 @@ wslua_filehandler_dump_open(wftap_dumper *wdh, int *err)
|
|||
* else FALSE.
|
||||
*/
|
||||
static gboolean
|
||||
wslua_filehandler_dump(wftap_dumper *wdh, const struct wtap_pkthdr *phdr,
|
||||
wslua_filehandler_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
|
||||
const guint8 *pd, int *err)
|
||||
{
|
||||
FileHandler fh = (FileHandler)(wdh->wslua_data);
|
||||
|
@ -2041,7 +2027,7 @@ wslua_filehandler_dump(wftap_dumper *wdh, const struct wtap_pkthdr *phdr,
|
|||
* else FALSE.
|
||||
*/
|
||||
static gboolean
|
||||
wslua_filehandler_dump_close(wftap_dumper *wdh, int *err)
|
||||
wslua_filehandler_dump_close(wtap_dumper *wdh, int *err)
|
||||
{
|
||||
FileHandler fh = (FileHandler)(wdh->wslua_data);
|
||||
int retval = -1;
|
||||
|
|
158
file.c
158
file.c
|
@ -237,7 +237,7 @@ cf_timestamp_auto_precision(capture_file *cf)
|
|||
prec == TS_PREC_AUTO_USEC ||
|
||||
prec == TS_PREC_AUTO_NSEC)
|
||||
{
|
||||
switch(wftap_file_tsprecision(cf->wfth)) {
|
||||
switch(wtap_file_tsprecision(cf->wth)) {
|
||||
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)
|
||||
{
|
||||
wftap *wth;
|
||||
wtap *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->wfth = wth;
|
||||
cf->wth = 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 = wftap_file_type_subtype(cf->wfth);
|
||||
cf->cd_t = wtap_file_type_subtype(cf->wth);
|
||||
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 = wftap_snapshot_length(cf->wfth);
|
||||
cf->snap = wtap_snapshot_length(cf->wth);
|
||||
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->wfth, add_ipv4_name);
|
||||
wtap_set_cb_new_ipv6(cf->wfth, (wtap_new_ipv6_callback_t) add_ipv6_name);
|
||||
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);
|
||||
|
||||
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->wfth) {
|
||||
wtap_close(cf->wfth);
|
||||
cf->wfth = NULL;
|
||||
if (cf->wth) {
|
||||
wtap_close(cf->wth);
|
||||
cf->wth = 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 = wftap_file_size(cf->wfth, NULL);
|
||||
size = wtap_file_size(cf->wth, NULL);
|
||||
|
||||
if (size >= 0)
|
||||
progbar_val = (gfloat) file_pos / (gfloat) size;
|
||||
|
||||
/* If it's still > 1, either "wftap_file_size()" failed (in which
|
||||
/* If it's still > 1, either "wtap_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 = wftap_iscompressed(cf->wfth);
|
||||
cf->iscompressed = wtap_iscompressed(cf->wth);
|
||||
|
||||
/* 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 = wftap_file_size(cf->wfth, NULL);
|
||||
size = wtap_file_size(cf->wth, 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->wfth, &err, &err_info, &data_offset))) {
|
||||
while ((wtap_read(cf->wth, &err, &err_info, &data_offset))) {
|
||||
if (size >= 0) {
|
||||
count++;
|
||||
file_pos = wftap_read_so_far(cf->wfth);
|
||||
file_pos = wtap_read_so_far(cf->wth);
|
||||
|
||||
/* 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. */
|
||||
wftap_sequential_close(cf->wfth);
|
||||
wtap_sequential_close(cf->wth);
|
||||
|
||||
/* 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 = wftap_file_encap(cf->wfth);
|
||||
cf->lnk_t = wtap_file_encap(cf->wth);
|
||||
|
||||
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) {
|
||||
wftap_cleareof(cf->wfth);
|
||||
if (!wtap_read(cf->wfth, err, &err_info, &data_offset)) {
|
||||
wtap_cleareof(cf->wth);
|
||||
if (!wtap_read(cf->wth, 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 = wftap_file_encap(cf->wfth);
|
||||
cf->lnk_t = wtap_file_encap(cf->wth);
|
||||
|
||||
/* 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->wfth == NULL) {
|
||||
if (cf->wth == NULL) {
|
||||