aboutsummaryrefslogtreecommitdiffstats
path: root/tfshark.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2017-12-07 19:31:43 -0800
committerGuy Harris <guy@alum.mit.edu>2017-12-08 03:32:25 +0000
commit797d2f6a87607b146a2ef62e1ff501031dce8212 (patch)
tree7c18adbd5b86d5f2843dd760f6fa492f7c05fef4 /tfshark.c
parent0baa4458c5780b143ad4479d387202ddf4add06f (diff)
Move the frame_set stuff back into the capture_file structure.
libwireshark now expects an epan_t to be created with a pointer to a "packet provider" structure; that structure is opaque within libwireshark, and a pointer to it is passed to the callbacks that provide interface names, interface, descriptions, user comments, and packet time stamps, and that set user comments. The code that calls epan_new() is expected to provide those callbacks, and to define the structure, which can be used by the providers. If none of the callbacks need that extra information, the "packet provider" structure can be null. Have a "file" packet provider for all the programs that provide packets from a file. Change-Id: I4b5709a3dd7b098ebd7d2a7d95bcdd7b5903c1a0 Reviewed-on: https://code.wireshark.org/review/24731 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'tfshark.c')
-rw-r--r--tfshark.c95
1 files changed, 47 insertions, 48 deletions
diff --git a/tfshark.c b/tfshark.c
index 017de96c52..d6e696f268 100644
--- a/tfshark.c
+++ b/tfshark.c
@@ -998,9 +998,9 @@ main(int argc, char *argv[])
g_free(cf_name);
- if (cfile.frame_set_info.frames != NULL) {
- free_frame_data_sequence(cfile.frame_set_info.frames);
- cfile.frame_set_info.frames = NULL;
+ if (cfile.provider.frames != NULL) {
+ free_frame_data_sequence(cfile.provider.frames);
+ cfile.provider.frames = NULL;
}
draw_tap_listeners(TRUE);
@@ -1023,19 +1023,19 @@ clean_exit:
}
static const nstime_t *
-tfshark_get_frame_ts(frame_set *fs, guint32 frame_num)
+tfshark_get_frame_ts(struct packet_provider *prov, guint32 frame_num)
{
- if (fs->ref && fs->ref->num == frame_num)
- return &fs->ref->abs_ts;
+ if (prov->ref && prov->ref->num == frame_num)
+ return &prov->ref->abs_ts;
- if (fs->prev_dis && fs->prev_dis->num == frame_num)
- return &fs->prev_dis->abs_ts;
+ if (prov->prev_dis && prov->prev_dis->num == frame_num)
+ return &prov->prev_dis->abs_ts;
- if (fs->prev_cap && fs->prev_cap->num == frame_num)
- return &fs->prev_cap->abs_ts;
+ if (prov->prev_cap && prov->prev_cap->num == frame_num)
+ return &prov->prev_cap->abs_ts;
- if (fs->frames) {
- frame_data *fd = frame_data_sequence_find(fs->frames, frame_num);
+ if (prov->frames) {
+ frame_data *fd = frame_data_sequence_find(prov->frames, frame_num);
return (fd) ? &fd->abs_ts : NULL;
}
@@ -1044,7 +1044,7 @@ tfshark_get_frame_ts(frame_set *fs, guint32 frame_num)
}
static const char *
-no_interface_name(frame_set *fs _U_, guint32 interface_id _U_)
+no_interface_name(struct packet_provider *prov _U_, guint32 interface_id _U_)
{
return "";
}
@@ -1052,9 +1052,8 @@ no_interface_name(frame_set *fs _U_, guint32 interface_id _U_)
static epan_t *
tfshark_epan_new(capture_file *cf)
{
- epan_t *epan = epan_new();
+ epan_t *epan = epan_new(&cf->provider);
- epan->fs = &cf->frame_set_info;
epan->get_frame_ts = tfshark_get_frame_ts;
epan->get_interface_name = no_interface_name;
epan->get_user_comment = NULL;
@@ -1096,10 +1095,10 @@ process_packet_first_pass(capture_file *cf, epan_dissect_t *edt,
prime_epan_dissect_with_postdissector_wanted_hfids(edt);
frame_data_set_before_dissect(&fdlocal, &cf->elapsed_time,
- &cf->frame_set_info.ref, cf->frame_set_info.prev_dis);
- if (cf->frame_set_info.ref == &fdlocal) {
+ &cf->provider.ref, cf->provider.prev_dis);
+ if (cf->provider.ref == &fdlocal) {
ref_frame = fdlocal;
- cf->frame_set_info.ref = &ref_frame;
+ cf->provider.ref = &ref_frame;
}
epan_dissect_file_run(edt, whdr, file_tvbuff_new(&fdlocal, pd), &fdlocal, NULL);
@@ -1111,14 +1110,14 @@ process_packet_first_pass(capture_file *cf, epan_dissect_t *edt,
if (passed) {
frame_data_set_after_dissect(&fdlocal, &cum_bytes);
- cf->frame_set_info.prev_cap = cf->frame_set_info.prev_dis = frame_data_sequence_add(cf->frame_set_info.frames, &fdlocal);
+ cf->provider.prev_cap = cf->provider.prev_dis = frame_data_sequence_add(cf->provider.frames, &fdlocal);
/* If we're not doing dissection then there won't be any dependent frames.
* More importantly, edt.pi.dependent_frames won't be initialized because
* epan hasn't been initialized.
*/
if (edt) {
- g_slist_foreach(edt->pi.dependent_frames, find_and_mark_frame_depended_upon, cf->frame_set_info.frames);
+ g_slist_foreach(edt->pi.dependent_frames, find_and_mark_frame_depended_upon, cf->provider.frames);
}
cf->count++;
@@ -1175,10 +1174,10 @@ process_packet_second_pass(capture_file *cf, epan_dissect_t *edt,
cinfo = NULL;
frame_data_set_before_dissect(fdata, &cf->elapsed_time,
- &cf->frame_set_info.ref, cf->frame_set_info.prev_dis);
- if (cf->frame_set_info.ref == fdata) {
+ &cf->provider.ref, cf->provider.prev_dis);
+ if (cf->provider.ref == fdata) {
ref_frame = *fdata;
- cf->frame_set_info.ref = &ref_frame;
+ cf->provider.ref = &ref_frame;
}
epan_dissect_file_run_with_taps(edt, phdr, file_tvbuff_new_buffer(fdata, buf), fdata, cinfo);
@@ -1207,9 +1206,9 @@ process_packet_second_pass(capture_file *cf, epan_dissect_t *edt,
return FALSE;
}
}
- cf->frame_set_info.prev_dis = fdata;
+ cf->provider.prev_dis = fdata;
}
- cf->frame_set_info.prev_cap = fdata;
+ cf->provider.prev_cap = fdata;
if (edt) {
epan_dissect_reset(edt);
@@ -1221,14 +1220,14 @@ static gboolean
local_wtap_read(capture_file *cf, struct wtap_pkthdr* file_phdr _U_, int *err, gchar **err_info _U_, gint64 *data_offset _U_, guint8** data_buffer)
{
/* int bytes_read; */
- gint64 packet_size = wtap_file_size(cf->frame_set_info.wth, err);
+ gint64 packet_size = wtap_file_size(cf->provider.wth, err);
*data_buffer = (guint8*)g_malloc((gsize)packet_size);
- /* bytes_read =*/ file_read(*data_buffer, (unsigned int)packet_size, cf->frame_set_info.wth->fh);
+ /* bytes_read =*/ file_read(*data_buffer, (unsigned int)packet_size, cf->provider.wth->fh);
#if 0 /* no more filetap */
if (bytes_read < 0) {
- *err = file_error(cf->frame_set_info.wth->fh, err_info);
+ *err = file_error(cf->provider.wth->fh, err_info);
if (*err == 0)
*err = FTAP_ERR_SHORT_READ;
return FALSE;
@@ -1323,7 +1322,7 @@ process_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
frame_data *fdata;
/* Allocate a frame_data_sequence for all the frames. */
- cf->frame_set_info.frames = new_frame_data_sequence();
+ cf->provider.frames = new_frame_data_sequence();
if (do_dissection) {
gboolean create_proto_tree;
@@ -1345,8 +1344,8 @@ process_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
edt = epan_dissect_new(cf->epan, create_proto_tree, FALSE);
}
while (local_wtap_read(cf, &file_phdr, &err, &err_info, &data_offset, &raw_data)) {
- if (process_packet_first_pass(cf, edt, data_offset, &file_phdr/*wtap_phdr(cf->frame_set_info.wth)*/,
- wtap_buf_ptr(cf->frame_set_info.wth))) {
+ if (process_packet_first_pass(cf, edt, data_offset, &file_phdr/*wtap_phdr(cf->provider.wth)*/,
+ wtap_buf_ptr(cf->provider.wth))) {
/* Stop reading if we have the maximum number of packets;
* When the -c option has not been used, max_packet_count
@@ -1367,15 +1366,15 @@ process_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
#if 0
/* Close the sequential I/O side, to free up memory it requires. */
- wtap_sequential_close(cf->frame_set_info.wth);
+ wtap_sequential_close(cf->provider.wth);
#endif
/* Allow the protocol dissectors to free up memory that they
* don't need after the sequential run-through of the packets. */
postseq_cleanup_all_protocols();
- cf->frame_set_info.prev_dis = NULL;
- cf->frame_set_info.prev_cap = NULL;
+ cf->provider.prev_dis = NULL;
+ cf->provider.prev_cap = NULL;
ws_buffer_init(&buf, 1500);
if (do_dissection) {
@@ -1406,9 +1405,9 @@ process_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
}
for (framenum = 1; err == 0 && framenum <= cf->count; framenum++) {
- fdata = frame_data_sequence_find(cf->frame_set_info.frames, framenum);
+ fdata = frame_data_sequence_find(cf->provider.frames, framenum);
#if 0
- if (wtap_seek_read(cf->frame_set_info.wth, fdata->file_off,
+ if (wtap_seek_read(cf->provider.wth, fdata->file_off,
&buf, fdata->cap_len, &err, &err_info)) {
process_packet_second_pass(cf, edt, fdata, &cf->phdr, &buf, tap_flags);
}
@@ -1469,7 +1468,7 @@ process_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
framenum++;
if (!process_packet_single_pass(cf, edt, data_offset,
- &file_phdr/*wtap_phdr(cf->frame_set_info.wth)*/,
+ &file_phdr/*wtap_phdr(cf->provider.wth)*/,
raw_data, tap_flags))
return FALSE;
@@ -1569,8 +1568,8 @@ process_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
}
out:
- wtap_close(cf->frame_set_info.wth);
- cf->frame_set_info.wth = NULL;
+ wtap_close(cf->provider.wth);
+ cf->provider.wth = NULL;
return (err != 0);
}
@@ -1618,10 +1617,10 @@ process_packet_single_pass(capture_file *cf, epan_dissect_t *edt, gint64 offset,
cinfo = NULL;
frame_data_set_before_dissect(&fdata, &cf->elapsed_time,
- &cf->frame_set_info.ref, cf->frame_set_info.prev_dis);
- if (cf->frame_set_info.ref == &fdata) {
+ &cf->provider.ref, cf->provider.prev_dis);
+ if (cf->provider.ref == &fdata) {
ref_frame = fdata;
- cf->frame_set_info.ref = &ref_frame;
+ cf->provider.ref = &ref_frame;
}
epan_dissect_file_run_with_taps(edt, whdr, frame_tvbuff_new(&fdata, pd), &fdata, cinfo);
@@ -1654,11 +1653,11 @@ process_packet_single_pass(capture_file *cf, epan_dissect_t *edt, gint64 offset,
/* this must be set after print_packet() [bug #8160] */
prev_dis_frame = fdata;
- cf->frame_set_info.prev_dis = &prev_dis_frame;
+ cf->provider.prev_dis = &prev_dis_frame;
}
prev_cap_frame = fdata;
- cf->frame_set_info.prev_cap = &prev_cap_frame;
+ cf->provider.prev_cap = &prev_cap_frame;
if (edt) {
epan_dissect_reset(edt);
@@ -2066,7 +2065,7 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp
epan_free(cf->epan);
cf->epan = tfshark_epan_new(cf);
- cf->frame_set_info.wth = NULL; /**** XXX - DOESN'T WORK RIGHT NOW!!!! */
+ cf->provider.wth = NULL; /**** XXX - DOESN'T WORK RIGHT NOW!!!! */
cf->f_datalen = 0; /* not used, but set it anyway */
/* Set the file name because we need it to set the follow stream filter.
@@ -2087,9 +2086,9 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp
cf->drops = 0;
cf->snap = 0; /**** XXX - DOESN'T WORK RIGHT NOW!!!! */
nstime_set_zero(&cf->elapsed_time);
- cf->frame_set_info.ref = NULL;
- cf->frame_set_info.prev_dis = NULL;
- cf->frame_set_info.prev_cap = NULL;
+ cf->provider.ref = NULL;
+ cf->provider.prev_dis = NULL;
+ cf->provider.prev_cap = NULL;
cf->state = FILE_READ_IN_PROGRESS;