aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2017-12-07 20:33:22 -0800
committerGuy Harris <guy@alum.mit.edu>2017-12-08 04:33:55 +0000
commit48e65c4af4e35c90d7cbc9fb789ecc6e740b300b (patch)
tree2f6e56d3734bb626584c7bdefeb5c7dce6b066c1
parent797d2f6a87607b146a2ef62e1ff501031dce8212 (diff)
Hand the packet provider functions to epan_new().
Have separate packet_provider_data structures and packet_provider_funcs structures; the latter holds a table of functions that libwireshark can call for information about packets, the latter holds the data that those functions use. This means we no longer need to expose the structure of an epan_t outside epan/epan.c; get rid of epan/epan-int.h. Change-Id: I381b88993aa19e55720ce02c42ad33738e3f51f4 Reviewed-on: https://code.wireshark.org/review/24732 Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r--cfile.h12
-rw-r--r--epan/Makefile.am1
-rw-r--r--epan/epan-int.h37
-rw-r--r--epan/epan.c30
-rw-r--r--epan/epan.h16
-rw-r--r--file.c19
-rw-r--r--file_packet_provider.c12
-rw-r--r--rawshark.c17
-rw-r--r--sharkd.c19
-rw-r--r--tfshark.c18
-rw-r--r--tools/oss-fuzzshark/fuzzshark.c19
-rw-r--r--tshark.c17
12 files changed, 98 insertions, 119 deletions
diff --git a/cfile.h b/cfile.h
index 05a0979..d1c4e37 100644
--- a/cfile.h
+++ b/cfile.h
@@ -46,7 +46,7 @@ typedef enum {
/*
* Packet provider for programs using a capture file.
*/
-struct packet_provider {
+struct packet_provider_data {
wtap *wth; /* Wiretap session */
const frame_data *ref;
frame_data *prev_dis;
@@ -102,7 +102,7 @@ typedef struct _capture_file {
struct wtap_pkthdr phdr; /* Packet header */
Buffer buf; /* Packet data */
/* packet provider */
- struct packet_provider provider;
+ struct packet_provider_data provider;
/* frames */
guint32 first_displayed; /* Frame number of first frame displayed */
guint32 last_displayed; /* Frame number of last frame displayed */
@@ -120,10 +120,10 @@ typedef struct _capture_file {
extern void cap_file_init(capture_file *cf);
-const char *cap_file_provider_get_interface_name(struct packet_provider *prov, guint32 interface_id);
-const char *cap_file_provider_get_interface_description(struct packet_provider *prov, guint32 interface_id);
-const char *cap_file_provider_get_user_comment(struct packet_provider *prov, const frame_data *fd);
-void cap_file_provider_set_user_comment(struct packet_provider *prov, frame_data *fd, const char *new_comment);
+const char *cap_file_provider_get_interface_name(struct packet_provider_data *prov, guint32 interface_id);
+const char *cap_file_provider_get_interface_description(struct packet_provider_data *prov, guint32 interface_id);
+const char *cap_file_provider_get_user_comment(struct packet_provider_data *prov, const frame_data *fd);
+void cap_file_provider_set_user_comment(struct packet_provider_data *prov, frame_data *fd, const char *new_comment);
#ifdef __cplusplus
}
diff --git a/epan/Makefile.am b/epan/Makefile.am
index db58327..31c01b5 100644
--- a/epan/Makefile.am
+++ b/epan/Makefile.am
@@ -282,7 +282,6 @@ LIBWIRESHARK_INCLUDES_PUBLIC = \
xdlc.h
LIBWIRESHARK_INCLUDES_PRIVATE = \
- epan-int.h \
to_str-int.h
subpkgincludedir = $(pkgincludedir)/epan
diff --git a/epan/epan-int.h b/epan/epan-int.h
deleted file mode 100644
index 54f1fb5..0000000
--- a/epan/epan-int.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/* epan-int.h
- *
- * Wireshark Protocol Analyzer Library
- *
- * Copyright (c) 2001 by Gerald Combs <gerald@wireshark.org>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#ifndef __EPAN_INT_H__
-#define __EPAN_INT_H__
-
-#include <epan/frame_data.h>
-#include <wsutil/nstime.h>
-
-struct epan_session {
- struct packet_provider *prov; /* packet provider for this session */
-
- const nstime_t *(*get_frame_ts)(struct packet_provider *prov, guint32 frame_num);
- const char *(*get_interface_name)(struct packet_provider *prov, guint32 interface_id);
- const char *(*get_interface_description)(struct packet_provider *prov, guint32 interface_id);
- const char *(*get_user_comment)(struct packet_provider *prov, const frame_data *fd);
-};
-
-#endif
diff --git a/epan/epan.c b/epan/epan.c
index 8d9d8db..1940f21 100644
--- a/epan/epan.c
+++ b/epan/epan.c
@@ -38,10 +38,13 @@
#include <epan/exceptions.h>
#include "epan.h"
-#include "epan-int.h"
+#include "epan/frame_data.h"
+
#include "dfilter/dfilter.h"
#include "epan_dissect.h"
+#include <wsutil/nstime.h>
+
#include "conversation.h"
#include "except.h"
#include "packet.h"
@@ -283,12 +286,19 @@ epan_cleanup(void)
wmem_cleanup();
}
+struct epan_session {
+ struct packet_provider_data *prov; /* packet provider data for this session */
+ struct packet_provider_funcs funcs; /* functions using that data */
+};
+
epan_t *
-epan_new(struct packet_provider *prov)
+epan_new(struct packet_provider_data *prov,
+ const struct packet_provider_funcs *funcs)
{
epan_t *session = g_slice_new0(epan_t);
session->prov = prov;
+ session->funcs = *funcs;
/* XXX, it should take session as param */
init_dissection();
@@ -299,8 +309,8 @@ epan_new(struct packet_provider *prov)
const char *
epan_get_user_comment(const epan_t *session, const frame_data *fd)
{
- if (session->get_user_comment)
- return session->get_user_comment(session->prov, fd);
+ if (session->funcs.get_user_comment)
+ return session->funcs.get_user_comment(session->prov, fd);
return NULL;
}
@@ -308,8 +318,8 @@ epan_get_user_comment(const epan_t *session, const frame_data *fd)
const char *
epan_get_interface_name(const epan_t *session, guint32 interface_id)
{
- if (session->get_interface_name)
- return session->get_interface_name(session->prov, interface_id);
+ if (session->funcs.get_interface_name)
+ return session->funcs.get_interface_name(session->prov, interface_id);
return NULL;
}
@@ -317,8 +327,8 @@ epan_get_interface_name(const epan_t *session, guint32 interface_id)
const char *
epan_get_interface_description(const epan_t *session, guint32 interface_id)
{
- if (session->get_interface_description)
- return session->get_interface_description(session->prov, interface_id);
+ if (session->funcs.get_interface_description)
+ return session->funcs.get_interface_description(session->prov, interface_id);
return NULL;
}
@@ -328,8 +338,8 @@ epan_get_frame_ts(const epan_t *session, guint32 frame_num)
{
const nstime_t *abs_ts = NULL;
- if (session->get_frame_ts)
- abs_ts = session->get_frame_ts(session->prov, frame_num);
+ if (session->funcs.get_frame_ts)
+ abs_ts = session->funcs.get_frame_ts(session->prov, frame_num);
if (!abs_ts)
ws_g_warning("!!! couldn't get frame ts for %u !!!\n", frame_num);
diff --git a/epan/epan.h b/epan/epan.h
index 306c583..5cafb78 100644
--- a/epan/epan.h
+++ b/epan/epan.h
@@ -44,7 +44,18 @@ struct epan_column_info;
* time stamps, comments, and other information outside the packet
* data itself.
*/
-struct packet_provider;
+struct packet_provider_data;
+
+/*
+ * Structure containing pointers to functions supplied by the user
+ * of libwireshark.
+ */
+struct packet_provider_funcs {
+ const nstime_t *(*get_frame_ts)(struct packet_provider_data *prov, guint32 frame_num);
+ const char *(*get_interface_name)(struct packet_provider_data *prov, guint32 interface_id);
+ const char *(*get_interface_description)(struct packet_provider_data *prov, guint32 interface_id);
+ const char *(*get_user_comment)(struct packet_provider_data *prov, const frame_data *fd);
+};
/**
@mainpage Wireshark EPAN the packet analyzing engine. Source code can be found in the epan directory
@@ -138,7 +149,8 @@ void epan_conversation_init(void);
*/
typedef struct epan_session epan_t;
-WS_DLL_PUBLIC epan_t *epan_new(struct packet_provider *prov);
+WS_DLL_PUBLIC epan_t *epan_new(struct packet_provider_data *prov,
+ const struct packet_provider_funcs *funcs);
WS_DLL_PUBLIC const char *epan_get_user_comment(const epan_t *session, const frame_data *fd);
diff --git a/file.c b/file.c
index 7fda336..d0080c4 100644
--- a/file.c
+++ b/file.c
@@ -26,7 +26,6 @@
#include <wiretap/merge.h>
#include <epan/exceptions.h>
-#include <epan/epan-int.h>
#include <epan/epan.h>
#include <epan/column.h>
#include <epan/packet.h>
@@ -223,7 +222,7 @@ static void compute_elapsed(capture_file *cf, GTimeVal *start_time)
}
static const nstime_t *
-ws_get_frame_ts(struct packet_provider *prov, guint32 frame_num)
+ws_get_frame_ts(struct packet_provider_data *prov, guint32 frame_num)
{
if (prov->prev_dis && prov->prev_dis->num == frame_num)
return &prov->prev_dis->abs_ts;
@@ -243,14 +242,14 @@ ws_get_frame_ts(struct packet_provider *prov, guint32 frame_num)
static epan_t *
ws_epan_new(capture_file *cf)
{
- epan_t *epan = epan_new(&cf->provider);
-
- epan->get_frame_ts = ws_get_frame_ts;
- epan->get_interface_name = cap_file_provider_get_interface_name;
- epan->get_interface_description = cap_file_provider_get_interface_description;
- epan->get_user_comment = cap_file_provider_get_user_comment;
-
- return epan;
+ static const struct packet_provider_funcs funcs = {
+ ws_get_frame_ts,
+ cap_file_provider_get_interface_name,
+ cap_file_provider_get_interface_description,
+ cap_file_provider_get_user_comment
+ };
+
+ return epan_new(&cf->provider, &funcs);
}
cf_status_t
diff --git a/file_packet_provider.c b/file_packet_provider.c
index e536298..c08d216 100644
--- a/file_packet_provider.c
+++ b/file_packet_provider.c
@@ -1,5 +1,5 @@
-/* file_packet_provider.c
- * Routines for a packet_provider for packets from a file.
+/* file_packet_provider_data.c
+ * Routines for a packet_provider_data for packets from a file.
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
@@ -24,7 +24,7 @@ frame_cmp(gconstpointer a, gconstpointer b, gpointer user_data _U_)
}
const char *
-cap_file_provider_get_interface_name(struct packet_provider *prov, guint32 interface_id)
+cap_file_provider_get_interface_name(struct packet_provider_data *prov, guint32 interface_id)
{
wtapng_iface_descriptions_t *idb_info;
wtap_block_t wtapng_if_descr = NULL;
@@ -47,7 +47,7 @@ cap_file_provider_get_interface_name(struct packet_provider *prov, guint32 inter
}
const char *
-cap_file_provider_get_interface_description(struct packet_provider *prov, guint32 interface_id)
+cap_file_provider_get_interface_description(struct packet_provider_data *prov, guint32 interface_id)
{
wtapng_iface_descriptions_t *idb_info;
wtap_block_t wtapng_if_descr = NULL;
@@ -68,7 +68,7 @@ cap_file_provider_get_interface_description(struct packet_provider *prov, guint3
}
const char *
-cap_file_provider_get_user_comment(struct packet_provider *prov, const frame_data *fd)
+cap_file_provider_get_user_comment(struct packet_provider_data *prov, const frame_data *fd)
{
if (prov->frames_user_comments)
return (const char *)g_tree_lookup(prov->frames_user_comments, fd);
@@ -78,7 +78,7 @@ cap_file_provider_get_user_comment(struct packet_provider *prov, const frame_dat
}
void
-cap_file_provider_set_user_comment(struct packet_provider *prov, frame_data *fd, const char *new_comment)
+cap_file_provider_set_user_comment(struct packet_provider_data *prov, frame_data *fd, const char *new_comment)
{
if (!prov->frames_user_comments)
prov->frames_user_comments = g_tree_new_full(frame_cmp, NULL, NULL, g_free);
diff --git a/rawshark.c b/rawshark.c
index e97ab24..eb382fd 100644
--- a/rawshark.c
+++ b/rawshark.c
@@ -44,7 +44,6 @@
#endif
#include <glib.h>
-#include <epan/epan-int.h>
#include <epan/epan.h>
#include <wsutil/cmdarg_err.h>
@@ -1464,7 +1463,7 @@ open_failure_message(const char *filename, int err, gboolean for_writing)
}
static const nstime_t *
-raw_get_frame_ts(struct packet_provider *prov, guint32 frame_num)
+raw_get_frame_ts(struct packet_provider_data *prov, guint32 frame_num)
{
if (prov->ref && prov->ref->num == frame_num)
return &prov->ref->abs_ts;
@@ -1481,14 +1480,14 @@ raw_get_frame_ts(struct packet_provider *prov, guint32 frame_num)
static epan_t *
raw_epan_new(capture_file *cf)
{
- epan_t *epan = epan_new(&cf->provider);
-
- epan->get_frame_ts = raw_get_frame_ts;
- epan->get_interface_name = cap_file_provider_get_interface_name;
- epan->get_interface_description = cap_file_provider_get_interface_description;
- epan->get_user_comment = NULL;
+ static const struct packet_provider_funcs funcs = {
+ raw_get_frame_ts,
+ cap_file_provider_get_interface_name,
+ cap_file_provider_get_interface_description,
+ NULL,
+ };
- return epan;
+ return epan_new(&cf->provider, &funcs);
}
cf_status_t
diff --git a/sharkd.c b/sharkd.c
index 5ceb7bf..d2be886 100644
--- a/sharkd.c
+++ b/sharkd.c
@@ -21,7 +21,6 @@
#include <glib.h>
#include <epan/exceptions.h>
-#include <epan/epan-int.h>
#include <epan/epan.h>
#include <wsutil/clopts_common.h>
@@ -221,7 +220,7 @@ clean_exit:
}
static const nstime_t *
-sharkd_get_frame_ts(struct packet_provider *prov, guint32 frame_num)
+sharkd_get_frame_ts(struct packet_provider_data *prov, guint32 frame_num)
{
if (prov->ref && prov->ref->num == frame_num)
return &prov->ref->abs_ts;
@@ -244,14 +243,14 @@ sharkd_get_frame_ts(struct packet_provider *prov, guint32 frame_num)
static epan_t *
sharkd_epan_new(capture_file *cf)
{
- epan_t *epan = epan_new(&cf->provider);
-
- epan->get_frame_ts = sharkd_get_frame_ts;
- epan->get_interface_name = cap_file_provider_get_interface_name;
- epan->get_interface_description = cap_file_provider_get_interface_description;
- epan->get_user_comment = cap_file_provider_get_user_comment;
-
- return epan;
+ static const struct packet_provider_funcs funcs = {
+ sharkd_get_frame_ts,
+ cap_file_provider_get_interface_name,
+ cap_file_provider_get_interface_description,
+ cap_file_provider_get_user_comment
+ };
+
+ return epan_new(&cf->provider, &funcs);
}
static gboolean
diff --git a/tfshark.c b/tfshark.c
index d6e696f..d8cdfcb 100644
--- a/tfshark.c
+++ b/tfshark.c
@@ -30,7 +30,6 @@
#include <glib.h>
#include <epan/exceptions.h>
-#include <epan/epan-int.h>
#include <epan/epan.h>
#include <wsutil/clopts_common.h>
@@ -1023,7 +1022,7 @@ clean_exit:
}
static const nstime_t *
-tfshark_get_frame_ts(struct packet_provider *prov, guint32 frame_num)
+tfshark_get_frame_ts(struct packet_provider_data *prov, guint32 frame_num)
{
if (prov->ref && prov->ref->num == frame_num)
return &prov->ref->abs_ts;
@@ -1044,7 +1043,7 @@ tfshark_get_frame_ts(struct packet_provider *prov, guint32 frame_num)
}
static const char *
-no_interface_name(struct packet_provider *prov _U_, guint32 interface_id _U_)
+no_interface_name(struct packet_provider_data *prov _U_, guint32 interface_id _U_)
{
return "";
}
@@ -1052,13 +1051,14 @@ no_interface_name(struct packet_provider *prov _U_, guint32 interface_id _U_)
static epan_t *
tfshark_epan_new(capture_file *cf)
{
- epan_t *epan = epan_new(&cf->provider);
-
- epan->get_frame_ts = tfshark_get_frame_ts;
- epan->get_interface_name = no_interface_name;
- epan->get_user_comment = NULL;
+ static const struct packet_provider_funcs funcs = {
+ tfshark_get_frame_ts,
+ no_interface_name,
+ NULL,
+ NULL,
+ };
- return epan;
+ return epan_new(&cf->provider, &funcs);
}
static gboolean
diff --git a/tools/oss-fuzzshark/fuzzshark.c b/tools/oss-fuzzshark/fuzzshark.c
index 56e816b..9c623ef 100644
--- a/tools/oss-fuzzshark/fuzzshark.c
+++ b/tools/oss-fuzzshark/fuzzshark.c
@@ -30,7 +30,6 @@
#include <glib.h>
-#include <epan/epan-int.h>
#include <epan/epan.h>
#include <wsutil/cmdarg_err.h>
@@ -111,7 +110,7 @@ failure_message_cont(const char *msg_format, va_list ap)
}
static const nstime_t *
-fuzzshark_get_frame_ts(struct packet_provider *prov _U_, guint32 frame_num _U_)
+fuzzshark_get_frame_ts(struct packet_provider_data *prov _U_, guint32 frame_num _U_)
{
static nstime_t empty;
@@ -121,14 +120,14 @@ fuzzshark_get_frame_ts(struct packet_provider *prov _U_, guint32 frame_num _U_)
static epan_t *
fuzzshark_epan_new(void)
{
- epan_t *epan = epan_new(NULL);
-
- epan->get_frame_ts = fuzzshark_get_frame_ts;
- epan->get_interface_name = NULL;
- epan->get_interface_description = NULL;
- epan->get_user_comment = NULL;
-
- return epan;
+ static const struct packet_provider_funcs funcs = {
+ fuzzshark_get_frame_ts,
+ NULL,
+ NULL,
+ NULL
+ };
+
+ return epan_new(NULL, &funcs);
}
static dissector_handle_t
diff --git a/tshark.c b/tshark.c
index 07a8289..099f49f 100644
--- a/tshark.c
+++ b/tshark.c
@@ -43,7 +43,6 @@
#include <glib.h>
#include <epan/exceptions.h>
-#include <epan/epan-int.h>
#include <epan/epan.h>
#include <wsutil/clopts_common.h>
@@ -2343,7 +2342,7 @@ pipe_input_set_handler(gint source, gpointer user_data, ws_process_id *child_pro
}
static const nstime_t *
-tshark_get_frame_ts(struct packet_provider *prov, guint32 frame_num)
+tshark_get_frame_ts(struct packet_provider_data *prov, guint32 frame_num)
{
if (prov->ref && prov->ref->num == frame_num)
return &prov->ref->abs_ts;
@@ -2366,14 +2365,14 @@ tshark_get_frame_ts(struct packet_provider *prov, guint32 frame_num)
static epan_t *
tshark_epan_new(capture_file *cf)
{
- epan_t *epan = epan_new(&cf->provider);
-
- epan->get_frame_ts = tshark_get_frame_ts;
- epan->get_interface_name = cap_file_provider_get_interface_name;
- epan->get_interface_description = cap_file_provider_get_interface_description;
- epan->get_user_comment = NULL;
+ static const struct packet_provider_funcs funcs = {
+ tshark_get_frame_ts,
+ cap_file_provider_get_interface_name,
+ cap_file_provider_get_interface_description,
+ NULL,
+ };
- return epan;
+ return epan_new(&cf->provider, &funcs);
}
#ifdef HAVE_LIBPCAP