forked from osmocom/wireshark
sharkd: add sharkd_get_frame() to get frame_data, optimize.
Add sharkd_get_frame() wrapper to limit number of cfile usage. Don't get frame_data when not needed. Change-Id: I24b96b5b184196e9dbf632c0891b2954c8281eed Reviewed-on: https://code.wireshark.org/review/24728 Petri-Dish: Jakub Zawadzki <darkjames-ws@darkjames.pl> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <guy@alum.mit.edu>pespin/amr
parent
847585f938
commit
0baa4458c5
21
sharkd.c
21
sharkd.c
|
@ -530,6 +530,12 @@ sharkd_load_cap_file(void)
|
|||
return load_cap_file(&cfile, 0, 0);
|
||||
}
|
||||
|
||||
frame_data *
|
||||
sharkd_get_frame(guint32 framenum)
|
||||
{
|
||||
return frame_data_sequence_find(cfile.frame_set_info.frames, framenum);
|
||||
}
|
||||
|
||||
int
|
||||
sharkd_dissect_request(unsigned int framenum, void (*cb)(epan_dissect_t *, proto_tree *, struct epan_column_info *, const GSList *, void *), int dissect_bytes, int dissect_columns, int dissect_tree, void *data)
|
||||
{
|
||||
|
@ -543,7 +549,7 @@ sharkd_dissect_request(unsigned int framenum, void (*cb)(epan_dissect_t *, proto
|
|||
int err;
|
||||
char *err_info = NULL;
|
||||
|
||||
fdata = frame_data_sequence_find(cfile.frame_set_info.frames, framenum);
|
||||
fdata = sharkd_get_frame(framenum);
|
||||
if (fdata == NULL)
|
||||
return -1;
|
||||
|
||||
|
@ -582,9 +588,8 @@ sharkd_dissect_request(unsigned int framenum, void (*cb)(epan_dissect_t *, proto
|
|||
|
||||
/* based on packet_list_dissect_and_cache_record */
|
||||
int
|
||||
sharkd_dissect_columns(int framenum, column_info *cinfo, gboolean dissect_color)
|
||||
sharkd_dissect_columns(frame_data *fdata, column_info *cinfo, gboolean dissect_color)
|
||||
{
|
||||
frame_data *fdata;
|
||||
epan_dissect_t edt;
|
||||
gboolean create_proto_tree;
|
||||
struct wtap_pkthdr phdr; /* Packet header */
|
||||
|
@ -593,12 +598,6 @@ sharkd_dissect_columns(int framenum, column_info *cinfo, gboolean dissect_color)
|
|||
int err;
|
||||
char *err_info = NULL;
|
||||
|
||||
fdata = frame_data_sequence_find(cfile.frame_set_info.frames, framenum);
|
||||
if (fdata == NULL) {
|
||||
col_fill_in_error(cinfo, fdata, FALSE, TRUE/* fill_fd_columns */);
|
||||
return -1; /* error reading the record */
|
||||
}
|
||||
|
||||
wtap_phdr_init(&phdr);
|
||||
ws_buffer_init(&buf, 1500);
|
||||
|
||||
|
@ -676,7 +675,7 @@ sharkd_retap(void)
|
|||
reset_tap_listeners();
|
||||
|
||||
for (framenum = 1; framenum <= cfile.count; framenum++) {
|
||||
fdata = frame_data_sequence_find(cfile.frame_set_info.frames, framenum);
|
||||
fdata = sharkd_get_frame(framenum);
|
||||
|
||||
if (!wtap_seek_read(cfile.frame_set_info.wth, fdata->file_off, &phdr, &buf, &err, &err_info))
|
||||
break;
|
||||
|
@ -726,7 +725,7 @@ sharkd_filter(const char *dftext, guint8 **result)
|
|||
result_bits = (guint8 *) g_malloc(2 + (frames_count / 8));
|
||||
|
||||
for (framenum = 1; framenum <= frames_count; framenum++) {
|
||||
frame_data *fdata = frame_data_sequence_find(cfile.frame_set_info.frames, framenum);
|
||||
frame_data *fdata = sharkd_get_frame(framenum);
|
||||
|
||||
if ((framenum & 7) == 0) {
|
||||
result_bits[(framenum / 8) - 1] = passed_bits;
|
||||
|
|
3
sharkd.h
3
sharkd.h
|
@ -20,7 +20,8 @@ cf_status_t sharkd_cf_open(const char *fname, unsigned int type, gboolean is_tem
|
|||
int sharkd_load_cap_file(void);
|
||||
int sharkd_retap(void);
|
||||
int sharkd_filter(const char *dftext, guint8 **result);
|
||||
int sharkd_dissect_columns(int framenum, column_info *cinfo, gboolean dissect_color);
|
||||
frame_data *sharkd_get_frame(guint32 framenum);
|
||||
int sharkd_dissect_columns(frame_data *fdata, column_info *cinfo, gboolean dissect_color);
|
||||
int sharkd_dissect_request(unsigned int framenum, void (*cb)(epan_dissect_t *, proto_tree *, struct epan_column_info *, const GSList *, void *), int dissect_bytes, int dissect_columns, int dissect_tree, void *data);
|
||||
const char *sharkd_get_user_comment(const frame_data *fd);
|
||||
int sharkd_set_user_comment(frame_data *fd, const gchar *new_comment);
|
||||
|
|
|
@ -845,7 +845,7 @@ sharkd_session_process_frames(const char *buf, const jsmntok_t *tokens, int coun
|
|||
printf("[");
|
||||
for (framenum = 1; framenum <= cfile.count; framenum++)
|
||||
{
|
||||
frame_data *fdata = frame_data_sequence_find(cfile.frame_set_info.frames, framenum);
|
||||
frame_data *fdata;
|
||||
|
||||
if (filter_data && !(filter_data[framenum / 8] & (1 << (framenum % 8))))
|
||||
continue;
|
||||
|
@ -856,7 +856,9 @@ sharkd_session_process_frames(const char *buf, const jsmntok_t *tokens, int coun
|
|||
continue;
|
||||
}
|
||||
|
||||
sharkd_dissect_columns(framenum, cinfo, (fdata->color_filter == NULL));
|
||||
fdata = sharkd_get_frame(framenum);
|
||||
|
||||
sharkd_dissect_columns(fdata, cinfo, (fdata->color_filter == NULL));
|
||||
|
||||
printf("%s{\"c\":[", frame_sepa);
|
||||
for (col = 0; col < cinfo->num_cols; ++col)
|
||||
|
@ -2938,7 +2940,7 @@ sharkd_session_process_intervals(char *buf, const jsmntok_t *tokens, int count)
|
|||
guint64 bytes;
|
||||
} st, st_total;
|
||||
|
||||
nstime_t *start_ts = NULL;
|
||||
nstime_t *start_ts;
|
||||
|
||||
guint32 interval_ms = 1000; /* default: one per second */
|
||||
|
||||
|
@ -2973,18 +2975,19 @@ sharkd_session_process_intervals(char *buf, const jsmntok_t *tokens, int count)
|
|||
|
||||
printf("{\"intervals\":[");
|
||||
|
||||
start_ts = (cfile.count >= 1) ? &(sharkd_get_frame(1)->abs_ts) : NULL;
|
||||
|
||||
for (framenum = 1; framenum <= cfile.count; framenum++)
|
||||
{
|
||||
frame_data *fdata = frame_data_sequence_find(cfile.frame_set_info.frames, framenum);
|
||||
frame_data *fdata;
|
||||
gint64 msec_rel;
|
||||
gint64 new_idx;
|
||||
|
||||
if (start_ts == NULL)
|
||||
start_ts = &fdata->abs_ts;
|
||||
|
||||
if (filter_data && !(filter_data[framenum / 8] & (1 << (framenum % 8))))
|
||||
continue;
|
||||
|
||||
fdata = sharkd_get_frame(framenum);
|
||||
|
||||
msec_rel = (fdata->abs_ts.secs - start_ts->secs) * (gint64) 1000 + (fdata->abs_ts.nsecs - start_ts->nsecs) / 1000000;
|
||||
new_idx = msec_rel / interval_ms;
|
||||
|
||||
|
@ -3312,7 +3315,7 @@ sharkd_session_process_setcomment(char *buf, const jsmntok_t *tokens, int count)
|
|||
if (!tok_frame || !ws_strtou32(tok_frame, NULL, &framenum) || framenum == 0)
|
||||
return;
|
||||
|
||||
fdata = frame_data_sequence_find(cfile.frame_set_info.frames, framenum);
|
||||
fdata = sharkd_get_frame(framenum);
|
||||
if (!fdata)
|
||||
return;
|
||||
|
||||
|
|
Loading…
Reference in New Issue