Abuse epan_t more: add callback to get interface name.
authorJakub Zawadzki <darkjames-ws@darkjames.pl>
Mon, 22 Jul 2013 19:38:38 +0000 (19:38 -0000)
committerJakub Zawadzki <darkjames-ws@darkjames.pl>
Mon, 22 Jul 2013 19:38:38 +0000 (19:38 -0000)
svn path=/trunk/; revision=50794

cfile.c
cfile.h
epan/dissectors/packet-frame.c
epan/epan-int.h
epan/epan.c
epan/epan.h
file.c
rawshark.c
tshark.c

diff --git a/cfile.c b/cfile.c
index 8fe484622c30af4205cb1fb6b7b253d62f33fa60..50c532eb6267038bbe975abfab99b9606847cc79 100644 (file)
--- a/cfile.c
+++ b/cfile.c
 
 #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)
 {
diff --git a/cfile.h b/cfile.h
index e9fb2afb999271ff4e40c74a26cf1ccd5c9baff5..c1ff88f1b2c4da77e944e34e869cccf13869f9f1 100644 (file)
--- a/cfile.h
+++ b/cfile.h
@@ -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 */
index c3e40f116deb3a4fa5131989b1cb88f0991a0eb2..1abdbe8d883848c268e16a0ce8f315a1aac39214 100644 (file)
@@ -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;
index 6580c55c269a1bc70713cd07b59b5c54f5f9cb0e..0fa38d0427b2257e1e4770ec241e1c0b4861c1cb 100644 (file)
@@ -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
index e4a7c2dd489bf62c37b7feae8947e26bfdafec55..70db022c538fc4b6c9e47b1ee18bd75d462bfde7 100644 (file)
@@ -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)
 {
index 252d748ee8a56ee6326e489312111de9bf5d8d89..63d1e418283079647095613248c7dc125ae4539b 100644 (file)
@@ -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);
diff --git a/file.c b/file.c
index e7c110b7c7c7c410981c999f53b099f8bedd0e4e..ef28127d52382a05ad2eb534f25a141518f15c05 100644 (file)
--- a/file.c
+++ b/file.c
@@ -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;
@@ -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;
 }
index dcf86b96ea5fe0a9ca39ab499365c8ae1a2b4b9c..69e417b4954cb1d29c74af3a47a37d80456bb441 100644 (file)
@@ -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;
 }
index 115ecc12eea24ddec7af6ed45293f7b0e376bd02..0d48f1506bfe35ed8d96dcc9921594f4e6fe6b2d 100644 (file)
--- a/tshark.c
+++ b/tshark.c
@@ -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;
 }