Skip to content

Commit

Permalink
Abuse epan_t more: add callback to get interface name.
Browse files Browse the repository at this point in the history
svn path=/trunk/; revision=50794
  • Loading branch information
jwzawadzki committed Jul 22, 2013
1 parent b0a94d2 commit 7ec1a78
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 3 deletions.
23 changes: 23 additions & 0 deletions cfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,29 @@

#include "cfile.h"

const char *
cap_file_get_interface_name(void *data, guint32 interface_id)
{
capture_file *cf = (capture_file *) data;
wtapng_iface_descriptions_t *idb_info;
const wtapng_if_descr_t *wtapng_if_descr = NULL;

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

g_free(idb_info);

if (wtapng_if_descr) {
if (wtapng_if_descr->if_name)
return wtapng_if_descr->if_name;
else if (wtapng_if_descr->if_description)
return wtapng_if_descr->if_description;
}
return "unknown";
}

void
cap_file_init(capture_file *cf)
{
Expand Down
2 changes: 2 additions & 0 deletions cfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ typedef struct _capture_file {

extern void cap_file_init(capture_file *cf);

extern const char *cap_file_get_interface_name(void *data, guint32 interface_id);

#ifdef __cplusplus
}
#endif /* __cplusplus */
Expand Down
10 changes: 8 additions & 2 deletions epan/dissectors/packet-frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,14 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)

fh_tree = proto_item_add_subtree(ti, ett_frame);

if (pinfo->fd->flags.has_if_id)
proto_tree_add_uint(fh_tree, hf_frame_interface_id, tvb, 0, 0, pinfo->fd->interface_id);
if (pinfo->fd->flags.has_if_id && proto_field_is_referenced(tree, hf_frame_interface_id)) {
const char *interface_name = epan_get_interface_name(pinfo->epan, pinfo->fd->interface_id);

if (interface_name)
proto_tree_add_uint_format_value(fh_tree, hf_frame_interface_id, tvb, 0, 0, pinfo->fd->interface_id, "%u (%s)", pinfo->fd->interface_id, interface_name);
else
proto_tree_add_uint(fh_tree, hf_frame_interface_id, tvb, 0, 0, pinfo->fd->interface_id);
}

if (pinfo->fd->flags.has_pack_flags) {
proto_tree *flags_tree;
Expand Down
1 change: 1 addition & 0 deletions epan/epan-int.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct epan_session {
void *data;

const nstime_t *(*get_frame_ts)(void *data, guint32 frame_num);
const char *(*get_interface_name)(void *data, guint32 interface_id);
};

#endif
9 changes: 9 additions & 0 deletions epan/epan.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ epan_new(void)
return session;
}

const char *
epan_get_interface_name(const epan_t *session, guint32 interface_id)
{
if (session->get_interface_name)
return session->get_interface_name(session->data, interface_id);

return NULL;
}

const nstime_t *
epan_get_frame_ts(const epan_t *session, guint32 frame_num)
{
Expand Down
2 changes: 2 additions & 0 deletions epan/epan.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ typedef struct epan_session epan_t;

WS_DLL_PUBLIC epan_t *epan_new(void);

const char *epan_get_interface_name(const epan_t *session, guint32 interface_id);

const nstime_t *epan_get_frame_ts(const epan_t *session, guint32 frame_num);

WS_DLL_PUBLIC void epan_free(epan_t *session);
Expand Down
3 changes: 2 additions & 1 deletion file.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ static void compute_elapsed(GTimeVal *start_time)
computed_elapsed = (gulong) (delta_time / 1000); /* ms */
}

const nstime_t *
static const nstime_t *
ws_get_frame_ts(void *data, guint32 frame_num)
{
capture_file *cf = (capture_file *) data;
Expand All @@ -330,6 +330,7 @@ ws_epan_new(capture_file *cf)

epan->data = cf;
epan->get_frame_ts = ws_get_frame_ts;
epan->get_interface_name = cap_file_get_interface_name;

return epan;
}
Expand Down
1 change: 1 addition & 0 deletions rawshark.c
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,7 @@ raw_epan_new(capture_file *cf)

epan->data = cf;
epan->get_frame_ts = raw_get_frame_ts;
epan->get_interface_name = cap_file_get_interface_name;

return epan;
}
Expand Down
1 change: 1 addition & 0 deletions tshark.c
Original file line number Diff line number Diff line change
Expand Up @@ -2189,6 +2189,7 @@ tshark_epan_new(capture_file *cf)

epan->data = cf;
epan->get_frame_ts = tshark_get_frame_ts;
epan->get_interface_name = cap_file_get_interface_name;

return epan;
}
Expand Down

0 comments on commit 7ec1a78

Please sign in to comment.