Skip to content

Commit

Permalink
Move the parts of a capture_file used by libwireshark to a new struct…
Browse files Browse the repository at this point in the history
…ure.

Embed one of those structures in a capture_file, and have a struct
epan_session point to that structure rather than to a capture_file.
Pass that structure to the routines that fetch data that libwireshark
uses when dissecting.

That separates the stuff that libwireshark expects from the stuff that
it doesn't look at.

Change-Id: Ia3cd28efb9622476437a2ce32204597fae720877
Reviewed-on: https://code.wireshark.org/review/24692
Reviewed-by: Guy Harris <guy@alum.mit.edu>
  • Loading branch information
guyharris committed Dec 4, 2017
1 parent 02944c4 commit 1834dca
Show file tree
Hide file tree
Showing 29 changed files with 450 additions and 417 deletions.
8 changes: 2 additions & 6 deletions cfile-int.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <epan/dfilter/dfilter.h>
#include <epan/frame_data.h>
#include <epan/frame_data_sequence.h>
#include <epan/frame_set.h>
#include <wiretap/wtap.h>

#ifdef __cplusplus
Expand Down Expand Up @@ -47,7 +48,6 @@ struct _capture_file {
guint32 drops; /* Dropped packets */
nstime_t elapsed_time; /* Elapsed time */
int snap; /* Maximum captured packet length; 0 if unknown */
wtap *wth; /* Wiretap session */
dfilter_t *rfcode; /* Compiled read filter program */
dfilter_t *dfcode; /* Compiled display filter program */
gchar *dfilter; /* Display filter string */
Expand All @@ -70,7 +70,7 @@ struct _capture_file {
struct wtap_pkthdr phdr; /* Packet header */
Buffer buf; /* Packet data */
/* frames */
frame_data_sequence *frames; /* Sequence of frames, if we're keeping that information */
frame_set frame_set_info; /* fjfff */
guint32 first_displayed; /* Frame number of first frame displayed */
guint32 last_displayed; /* Frame number of last frame displayed */
column_info cinfo; /* Column formatting information */
Expand All @@ -80,13 +80,9 @@ struct _capture_file {
epan_dissect_t *edt; /* Protocol dissection for currently selected packet */
field_info *finfo_selected; /* Field info for currently selected field */
gpointer window; /* Top-level window associated with file */
GTree *frames_user_comments; /* BST with user comments for frames (key = frame_data) */
gulong computed_elapsed; /* Elapsed time to load the file (in msec). */

guint32 cum_bytes;
const frame_data *ref;
frame_data *prev_dis;
frame_data *prev_cap;
};

#ifdef __cplusplus
Expand Down
44 changes: 0 additions & 44 deletions cfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,6 @@
#include "cfile.h"
#include "cfile-int.h"

const char *
cap_file_get_interface_name(capture_file *cf, guint32 interface_id)
{
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_NAME, &interface_name) == WTAP_OPTTYPE_SUCCESS)
return interface_name;
if (wtap_block_get_string_option_value(wtapng_if_descr, OPT_IDB_DESCR, &interface_name) == WTAP_OPTTYPE_SUCCESS)
return interface_name;
}
return "unknown";
}

const char *
cap_file_get_interface_description(capture_file *cf, guint32 interface_id)
{
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)
{
Expand Down
3 changes: 0 additions & 3 deletions cfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ typedef struct _capture_file capture_file;

extern void cap_file_init(capture_file *cf);

extern const char *cap_file_get_interface_name(capture_file *cf, guint32 interface_id);
extern const char *cap_file_get_interface_description(capture_file *cf, guint32 interface_id);

#ifdef __cplusplus
}
#endif /* __cplusplus */
Expand Down
6 changes: 4 additions & 2 deletions epan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ set(LIBWIRESHARK_PUBLIC_HEADERS
expert.h
export_object.h
exported_pdu.h
plugin_if.h
filter_expressions.h
follow.h
frame_data.h
frame_data_sequence.h
frame_set.h
funnel.h
garrayfix.h
geoip_db.h
Expand All @@ -127,6 +127,7 @@ set(LIBWIRESHARK_PUBLIC_HEADERS
packet.h
packet_info.h
params.h
plugin_if.h
ppptypes.h
print.h
print_stream.h
Expand Down Expand Up @@ -203,11 +204,11 @@ set(LIBWIRESHARK_FILES
expert.c
export_object.c
exported_pdu.c
plugin_if.c
filter_expressions.c
follow.c
frame_data.c
frame_data_sequence.c
frame_set.c
funnel.c
geoip_db.c
golay.c
Expand All @@ -220,6 +221,7 @@ set(LIBWIRESHARK_FILES
oids.c
osi-utils.c
packet.c
plugin_if.c
print.c
print_stream.c
prefs.c
Expand Down
6 changes: 4 additions & 2 deletions epan/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ LIBWIRESHARK_SRC = \
expert.c \
export_object.c \
exported_pdu.c \
plugin_if.c \
filter_expressions.c \
follow.c \
frame_data.c \
frame_data_sequence.c \
frame_set.c \
funnel.c \
geoip_db.c \
golay.c \
Expand All @@ -84,6 +84,7 @@ LIBWIRESHARK_SRC = \
oids.c \
osi-utils.c \
packet.c \
plugin_if.c \
prefs.c \
print.c \
print_stream.c \
Expand Down Expand Up @@ -207,11 +208,11 @@ LIBWIRESHARK_INCLUDES_PUBLIC = \
expert.h \
export_object.h \
exported_pdu.h \
plugin_if.h \
filter_expressions.h \
follow.h \
frame_data.h \
frame_data_sequence.h \
frame_set.h \
funnel.h \
garrayfix.h \
geoip_db.h \
Expand All @@ -235,6 +236,7 @@ LIBWIRESHARK_INCLUDES_PUBLIC = \
packet.h \
packet_info.h \
params.h \
plugin_if.h \
ppptypes.h \
print.h \
print_stream.h \
Expand Down
21 changes: 6 additions & 15 deletions epan/epan-int.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,16 @@
#define __EPAN_INT_H__

#include <epan/frame_data.h>
#include <epan/frame_set.h>
#include <wsutil/nstime.h>

/*
* XXX - this isn't part of libwireshark; using it in the API indicates
* that perhaps it should be, in some fashion.
*
* Whether the structure definition of a capture_file should be part
* of libwireshark, or part of the code that uses libwireshark, is
* another matter.
*/
#include "cfile.h"

struct epan_session {
capture_file *cf;
frame_set *fs;

const nstime_t *(*get_frame_ts)(capture_file *cf, guint32 frame_num);
const char *(*get_interface_name)(capture_file *cf, guint32 interface_id);
const char *(*get_interface_description)(capture_file *cf, guint32 interface_id);
const char *(*get_user_comment)(capture_file *cf, const frame_data *fd);
const nstime_t *(*get_frame_ts)(frame_set *cf, guint32 frame_num);
const char *(*get_interface_name)(frame_set *fs, guint32 interface_id);
const char *(*get_interface_description)(frame_set *fs, guint32 interface_id);
const char *(*get_user_comment)(frame_set *fs, const frame_data *fd);
};

#endif
8 changes: 4 additions & 4 deletions epan/epan.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ 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->cf, fd);
return session->get_user_comment(session->fs, fd);

return NULL;
}
Expand All @@ -307,7 +307,7 @@ const char *
epan_get_interface_name(const epan_t *session, guint32 interface_id)
{
if (session->get_interface_name)
return session->get_interface_name(session->cf, interface_id);
return session->get_interface_name(session->fs, interface_id);

return NULL;
}
Expand All @@ -316,7 +316,7 @@ const char *
epan_get_interface_description(const epan_t *session, guint32 interface_id)
{
if (session->get_interface_description)
return session->get_interface_description(session->cf, interface_id);
return session->get_interface_description(session->fs, interface_id);

return NULL;
}
Expand All @@ -327,7 +327,7 @@ 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->cf, frame_num);
abs_ts = session->get_frame_ts(session->fs, frame_num);

if (!abs_ts)
ws_g_warning("!!! couldn't get frame ts for %u !!!\n", frame_num);
Expand Down
57 changes: 57 additions & 0 deletions epan/frame_set.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* frame_set.c
* fdfdkfslf;ajkdf
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0+
*/

#include <glib.h>

#include <epan/frame_set.h>

const char *
frame_set_get_interface_name(frame_set *fs, guint32 interface_id)
{
wtapng_iface_descriptions_t *idb_info;
wtap_block_t wtapng_if_descr = NULL;
char* interface_name;

idb_info = wtap_file_get_idb_info(fs->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_NAME, &interface_name) == WTAP_OPTTYPE_SUCCESS)
return interface_name;
if (wtap_block_get_string_option_value(wtapng_if_descr, OPT_IDB_DESCR, &interface_name) == WTAP_OPTTYPE_SUCCESS)
return interface_name;
}
return "unknown";
}

const char *
frame_set_get_interface_description(frame_set *fs, guint32 interface_id)
{
wtapng_iface_descriptions_t *idb_info;
wtap_block_t wtapng_if_descr = NULL;
char* interface_name;

idb_info = wtap_file_get_idb_info(fs->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;
}
32 changes: 32 additions & 0 deletions epan/frame_set.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* frame_set.h
* Definition of frame_set structure. It holds information about a
* fdfdkfslf;ajkdf
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0+
*/

#ifndef __EPAN_FRAME_SET_H__
#define __EPAN_FRAME_SET_H__

#include <epan/frame_data.h>
#include <epan/frame_data_sequence.h>

#include "ws_symbol_export.h"

typedef struct {
wtap *wth; /* Wiretap session */
const frame_data *ref;
frame_data *prev_dis;
frame_data *prev_cap;
frame_data_sequence *frames; /* Sequence of frames, if we're keeping that information */
GTree *frames_user_comments; /* BST with user comments for frames (key = frame_data) */
} frame_set;

WS_DLL_PUBLIC const char *frame_set_get_interface_name(frame_set *fs, guint32 interface_id);
WS_DLL_PUBLIC const char *frame_set_get_interface_description(frame_set *fs, guint32 interface_id);

#endif /* frame_set.h */
Loading

0 comments on commit 1834dca

Please sign in to comment.