diff --git a/cfile.c b/cfile.c index ef0f31a8d8..cf30f3b899 100644 --- a/cfile.c +++ b/cfile.c @@ -54,6 +54,28 @@ cap_file_get_interface_name(void *data, guint32 interface_id) return "unknown"; } +const char * +cap_file_get_interface_description(void *data, guint32 interface_id) +{ + capture_file *cf = (capture_file *) data; + wtapng_iface_descriptions_t *idb_info; + wtap_block_t wtapng_if_descr = NULL; + char* interface_name; + + idb_info = wtap_file_get_idb_info(cf->wth); + + if (interface_id < idb_info->interface_data->len) + wtapng_if_descr = g_array_index(idb_info->interface_data, wtap_block_t, interface_id); + + g_free(idb_info); + + if (wtapng_if_descr) { + if (wtap_block_get_string_option_value(wtapng_if_descr, OPT_IDB_DESCR, &interface_name) == WTAP_OPTTYPE_SUCCESS) + return interface_name; + } + return NULL; +} + void cap_file_init(capture_file *cf) { diff --git a/cfile.h b/cfile.h index 2e4c1cb244..d406c22f21 100644 --- a/cfile.h +++ b/cfile.h @@ -137,6 +137,7 @@ 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); +extern const char *cap_file_get_interface_description(void *data, guint32 interface_id); #ifdef __cplusplus } diff --git a/epan/dissectors/packet-frame.c b/epan/dissectors/packet-frame.c index d5c793404f..b4f17367b4 100644 --- a/epan/dissectors/packet-frame.c +++ b/epan/dissectors/packet-frame.c @@ -75,6 +75,7 @@ static int hf_frame_color_filter_name = -1; static int hf_frame_color_filter_text = -1; static int hf_frame_interface_id = -1; static int hf_frame_interface_name = -1; +static int hf_frame_interface_description = -1; static int hf_frame_pack_flags = -1; static int hf_frame_pack_direction = -1; static int hf_frame_pack_reception_type = -1; @@ -342,21 +343,26 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* fh_tree = proto_item_add_subtree(ti, ett_frame); if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID && - (proto_field_is_referenced(tree, hf_frame_interface_id) || - proto_field_is_referenced(tree, hf_frame_interface_name))) { + (proto_field_is_referenced(tree, hf_frame_interface_id) || proto_field_is_referenced(tree, hf_frame_interface_name) || proto_field_is_referenced(tree, hf_frame_interface_description))) { const char *interface_name = epan_get_interface_name(pinfo->epan, pinfo->phdr->interface_id); + const char *interface_description = epan_get_interface_description(pinfo->epan, pinfo->phdr->interface_id); + proto_tree *if_tree; + proto_item *if_item; if (interface_name) { - proto_tree *if_tree; - proto_item *if_item; if_item = proto_tree_add_uint_format_value(fh_tree, hf_frame_interface_id, tvb, 0, 0, pinfo->phdr->interface_id, "%u (%s)", pinfo->phdr->interface_id, interface_name); if_tree = proto_item_add_subtree(if_item, ett_ifname); proto_tree_add_string(if_tree, hf_frame_interface_name, tvb, 0, 0, interface_name); } else { - proto_tree_add_uint(fh_tree, hf_frame_interface_id, tvb, 0, 0, pinfo->phdr->interface_id); + if_item = proto_tree_add_uint(fh_tree, hf_frame_interface_id, tvb, 0, 0, pinfo->phdr->interface_id); } + + if (interface_description) { + if_tree = proto_item_add_subtree(if_item, ett_ifname); + proto_tree_add_string(if_tree, hf_frame_interface_description, tvb, 0, 0, interface_description); + } } if (pinfo->phdr->presence_flags & WTAP_HAS_PACK_FLAGS) { @@ -816,6 +822,11 @@ proto_register_frame(void) FT_STRING, BASE_NONE, NULL, 0x0, "The friendly name for this interface", HFILL }}, + { &hf_frame_interface_description, + { "Interface description", "frame.interface_description", + FT_STRING, BASE_NONE, NULL, 0x0, + "The descriptionfor this interface", HFILL }}, + { &hf_frame_pack_flags, { "Packet flags", "frame.packet_flags", FT_UINT32, BASE_HEX, NULL, 0x0, diff --git a/epan/epan-int.h b/epan/epan-int.h index 35e91975be..15b059f388 100644 --- a/epan/epan-int.h +++ b/epan/epan-int.h @@ -30,6 +30,7 @@ struct epan_session { const nstime_t *(*get_frame_ts)(void *data, guint32 frame_num); const char *(*get_interface_name)(void *data, guint32 interface_id); + const char *(*get_interface_description)(void *data, guint32 interface_id); const char *(*get_user_comment)(void *data, const frame_data *fd); }; diff --git a/epan/epan.c b/epan/epan.c index 54d5292fe8..e0ebd5b215 100644 --- a/epan/epan.c +++ b/epan/epan.c @@ -271,6 +271,15 @@ epan_get_interface_name(const epan_t *session, guint32 interface_id) return NULL; } +const char * +epan_get_interface_description(const epan_t *session, guint32 interface_id) +{ + if (session->get_interface_description) + return session->get_interface_description(session->data, interface_id); + + return NULL; +} + const nstime_t * epan_get_frame_ts(const epan_t *session, guint32 frame_num) { diff --git a/epan/epan.h b/epan/epan.h index e1dacdc390..3a1e742d14 100644 --- a/epan/epan.h +++ b/epan/epan.h @@ -131,7 +131,7 @@ void epan_circuit_cleanup(void); /** A client will create one epan_t for an entire dissection session. * A single epan_t will be used to analyze the entire sequence of packets, * sequentially, in a single session. A session corresponds to a single - * packet trace file. The reaons epan_t exists is that some packets in + * packet trace file. The reasons epan_t exists is that some packets in * some protocols cannot be decoded without knowledge of previous packets. * This inter-packet "state" is stored in the epan_t. */ @@ -143,6 +143,8 @@ WS_DLL_PUBLIC const char *epan_get_user_comment(const epan_t *session, const fra WS_DLL_PUBLIC const char *epan_get_interface_name(const epan_t *session, guint32 interface_id); +WS_DLL_PUBLIC const char *epan_get_interface_description(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); diff --git a/file.c b/file.c index c8c9c13449..ff39a9dffe 100644 --- a/file.c +++ b/file.c @@ -283,6 +283,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; + epan->get_interface_description = cap_file_get_interface_description; epan->get_user_comment = ws_get_user_comment; return epan; diff --git a/rawshark.c b/rawshark.c index 074a08b4b2..0366c9f5d1 100644 --- a/rawshark.c +++ b/rawshark.c @@ -1542,6 +1542,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; + epan->get_interface_description = cap_file_get_interface_description; epan->get_user_comment = NULL; return epan; diff --git a/sharkd.c b/sharkd.c index 964ea92a05..974948f8f1 100644 --- a/sharkd.c +++ b/sharkd.c @@ -331,6 +331,7 @@ sharkd_epan_new(capture_file *cf) epan->data = cf; epan->get_frame_ts = sharkd_get_frame_ts; epan->get_interface_name = cap_file_get_interface_name; + epan->get_interface_description = cap_file_get_interface_description; epan->get_user_comment = NULL; return epan; diff --git a/tshark.c b/tshark.c index f209acc429..fa5f0468ba 100644 --- a/tshark.c +++ b/tshark.c @@ -2345,6 +2345,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; + epan->get_interface_description = cap_file_get_interface_description; epan->get_user_comment = NULL; return epan;