2021-11-26 03:31:05 +00:00
|
|
|
/** @file
|
2004-10-27 23:28:37 +00:00
|
|
|
* Definitions for routines for merging files.
|
2004-06-18 10:01:59 +00:00
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2004-06-18 10:01:59 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2018-02-07 11:26:45 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2004-06-18 10:01:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __MERGE_H__
|
|
|
|
#define __MERGE_H__
|
|
|
|
|
2013-07-16 02:35:33 +00:00
|
|
|
#include "wiretap/wtap.h"
|
|
|
|
|
2004-06-18 10:01:59 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2004-10-29 00:36:52 +00:00
|
|
|
typedef enum {
|
2018-02-05 20:55:00 +00:00
|
|
|
RECORD_PRESENT,
|
|
|
|
RECORD_NOT_PRESENT,
|
2015-08-14 14:44:11 +00:00
|
|
|
AT_EOF,
|
|
|
|
GOT_ERROR
|
2004-10-29 00:36:52 +00:00
|
|
|
} in_file_state_e;
|
|
|
|
|
2004-06-18 10:01:59 +00:00
|
|
|
/**
|
|
|
|
* Structures to manage our input files.
|
|
|
|
*/
|
|
|
|
typedef struct merge_in_file_s {
|
2015-08-14 14:44:11 +00:00
|
|
|
const char *filename;
|
|
|
|
wtap *wth;
|
2019-04-05 01:56:27 +00:00
|
|
|
wtap_rec rec;
|
|
|
|
Buffer frame_buffer;
|
2015-08-14 14:44:11 +00:00
|
|
|
in_file_state_e state;
|
|
|
|
guint32 packet_num; /* current packet number */
|
|
|
|
gint64 size; /* file size */
|
2015-08-16 16:37:11 +00:00
|
|
|
GArray *idb_index_map; /* used for mapping the old phdr interface_id values to new during merge */
|
wiretap: Preserve NRBs with editcap, mergecap, and tshark
Use a pointer to the growing array of NRBs from the source
file, as with DSBs, so as to handle reading NRBs in the middle
of a file in one-pass mode.
Write NRBs when reading a file with editcap, or in tshark when
not dissecting packets and writing our own NRB. Continue not
to write the NRB if we're supplying our own list of address info
instead.
If we have already read the entire source file in (such as in
two-pass tshark), move all the NRBs to the beginning of the file
before packets, as done with DSBs.
When merging files with mergecap, write both sets of NRBs. (There
is no attempt to merge the NRBs by looking for common entries.)
Check for name resolution data in the middle of dumping a file,
not just at the end, and check for DSBs at the end of a file,
after all the packets. This means that Wireshark no longer writes
the NRB at the very end of the file after all the packets (which
is worse for future one-pass reads), and DSBs after all packets
are preserved.
Ping #15502
2023-01-26 05:42:10 +00:00
|
|
|
guint nrbs_seen; /* number of elements processed so far from wth->nrbs */
|
2018-11-17 12:56:12 +00:00
|
|
|
guint dsbs_seen; /* number of elements processed so far from wth->dsbs */
|
2004-06-18 10:01:59 +00:00
|
|
|
} merge_in_file_t;
|
|
|
|
|
2015-08-16 16:37:11 +00:00
|
|
|
/** Return values from merge_files(). */
|
|
|
|
typedef enum {
|
|
|
|
MERGE_OK,
|
|
|
|
MERGE_USER_ABORTED,
|
|
|
|
/* below here are true errors */
|
|
|
|
MERGE_ERR_CANT_OPEN_INFILE,
|
|
|
|
MERGE_ERR_CANT_OPEN_OUTFILE,
|
|
|
|
MERGE_ERR_CANT_READ_INFILE,
|
|
|
|
MERGE_ERR_BAD_PHDR_INTERFACE_ID,
|
|
|
|
MERGE_ERR_CANT_WRITE_OUTFILE,
|
2017-02-04 15:26:34 +00:00
|
|
|
MERGE_ERR_CANT_CLOSE_OUTFILE,
|
|
|
|
MERGE_ERR_INVALID_OPTION
|
2015-08-16 16:37:11 +00:00
|
|
|
} merge_result;
|
|
|
|
|
|
|
|
|
|
|
|
/** Merge events, used as an arg in the callback function - indicates when the callback was invoked. */
|
|
|
|
typedef enum {
|
|
|
|
MERGE_EVENT_INPUT_FILES_OPENED,
|
|
|
|
MERGE_EVENT_FRAME_TYPE_SELECTED,
|
|
|
|
MERGE_EVENT_READY_TO_MERGE,
|
2018-02-05 20:55:00 +00:00
|
|
|
MERGE_EVENT_RECORD_WAS_READ,
|
2015-08-16 16:37:11 +00:00
|
|
|
MERGE_EVENT_DONE
|
|
|
|
} merge_event;
|
|
|
|
|
|
|
|
|
|
|
|
/** Merge mode for IDB info. */
|
|
|
|
typedef enum {
|
|
|
|
IDB_MERGE_MODE_NONE = 0, /**< no merging of IDBs is done, all IDBs are copied into merged file */
|
|
|
|
IDB_MERGE_MODE_ALL_SAME,/**< duplicate IDBs merged only if all the files have the same set of IDBs */
|
|
|
|
IDB_MERGE_MODE_ANY_SAME, /**< any and all duplicate IDBs are merged into one IDB, even within a file */
|
|
|
|
IDB_MERGE_MODE_MAX
|
|
|
|
} idb_merge_mode;
|
|
|
|
|
|
|
|
|
|
|
|
/** Returns the idb_merge_mode for the given string name.
|
|
|
|
*
|
|
|
|
* @param name The name of the mode.
|
|
|
|
* @return The idb_merge_mode, or IDB_MERGE_MODE_MAX on failure.
|
|
|
|
*/
|
|
|
|
WS_DLL_PUBLIC idb_merge_mode
|
|
|
|
merge_string_to_idb_merge_mode(const char *name);
|
|
|
|
|
|
|
|
|
|
|
|
/** Returns the string name for the given number.
|
|
|
|
*
|
|
|
|
* @param mode The number of the mode, representing the idb_merge_mode enum value.
|
|
|
|
* @return The string name, or "UNKNOWN" on failure.
|
|
|
|
*/
|
|
|
|
WS_DLL_PUBLIC const char*
|
|
|
|
merge_idb_merge_mode_to_string(const int mode);
|
|
|
|
|
|
|
|
|
|
|
|
/** @struct merge_progress_callback_t
|
|
|
|
*
|
|
|
|
* @brief Callback information for merging.
|
|
|
|
*
|
|
|
|
* @details The merge_files() routine can invoke a callback during its execution,
|
|
|
|
* to enable verbose printing or progress bar updating, for example. This struct
|
|
|
|
* provides merge_files() with the callback routine to invoke, and optionally
|
|
|
|
* private data to pass through to the callback each time it is invoked.
|
|
|
|
* For the callback_func routine's arguments: the event is when the callback
|
|
|
|
* was invoked, the num is an int specific to the event, in_files is an array
|
|
|
|
* of the created merge info, in_file_count is the size of the array, data is
|
|
|
|
* whatever was passed in the data member of this struct. The callback_func
|
|
|
|
* routine's return value should be TRUE if merging should be aborted.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
gboolean (*callback_func)(merge_event event, int num,
|
|
|
|
const merge_in_file_t in_files[], const guint in_file_count,
|
|
|
|
void *data);
|
|
|
|
void *data; /**< private data to use for passing through to the callback function */
|
|
|
|
} merge_progress_callback_t;
|
|
|
|
|
|
|
|
|
2016-12-04 01:57:34 +00:00
|
|
|
/** Merge the given input files to a file with the given filename
|
2015-08-16 16:37:11 +00:00
|
|
|
*
|
2016-12-04 01:57:34 +00:00
|
|
|
* @param out_filename The output filename
|
2015-08-16 16:37:11 +00:00
|
|
|
* @param file_type The WTAP_FILE_TYPE_SUBTYPE_XXX output file type
|
|
|
|
* @param in_filenames An array of input filenames to merge from
|
|
|
|
* @param in_file_count The number of entries in in_filenames
|
|
|
|
* @param do_append Whether to append by file order instead of chronological order
|
|
|
|
* @param mode The IDB_MERGE_MODE_XXX merge mode for interface data
|
|
|
|
* @param snaplen The snaplen to limit it to, or 0 to leave as it is in the files
|
|
|
|
* @param app_name The application name performing the merge, used in SHB info
|
|
|
|
* @param cb The callback information to use during execution
|
|
|
|
* @param[out] err Set to the internal WTAP_ERR_XXX error code if it failed
|
2017-04-20 20:25:21 +00:00
|
|
|
* with MERGE_ERR_CANT_OPEN_INFILE, MERGE_ERR_CANT_OPEN_OUTFILE,
|
|
|
|
* MERGE_ERR_CANT_READ_INFILE, MERGE_ERR_CANT_WRITE_OUTFILE, or
|
|
|
|
* MERGE_ERR_CANT_CLOSE_OUTFILE
|
|
|
|
* @param[out] err_info Additional information for some WTAP_ERR_XXX codes
|
|
|
|
* @param[out] err_fileno Set to the input file number which failed, if it
|
|
|
|
* failed
|
|
|
|
* @param[out] err_framenum Set to the input frame number if it failed
|
2015-08-16 16:37:11 +00:00
|
|
|
* @return the frame type
|
|
|
|
*/
|
|
|
|
WS_DLL_PUBLIC merge_result
|
2016-12-04 01:57:34 +00:00
|
|
|
merge_files(const gchar* out_filename, const int file_type,
|
2015-08-16 16:37:11 +00:00
|
|
|
const char *const *in_filenames, const guint in_file_count,
|
|
|
|
const gboolean do_append, const idb_merge_mode mode,
|
|
|
|
guint snaplen, const gchar *app_name, merge_progress_callback_t* cb,
|
2017-04-20 20:25:21 +00:00
|
|
|
int *err, gchar **err_info, guint *err_fileno,
|
|
|
|
guint32 *err_framenum);
|
2015-08-16 16:37:11 +00:00
|
|
|
|
2016-12-04 01:57:34 +00:00
|
|
|
/** Merge the given input files to a temporary file
|
|
|
|
*
|
2022-02-09 14:32:28 +00:00
|
|
|
* @param tmpdir Points to the directory in which to write the temporary file
|
2016-12-04 01:57:34 +00:00
|
|
|
* @param out_filenamep Points to a pointer that's set to point to the
|
|
|
|
* pathname of the temporary file; it's allocated with g_malloc()
|
|
|
|
* @param pfx A string to be used as the prefix for the temporary file name
|
|
|
|
* @param file_type The WTAP_FILE_TYPE_SUBTYPE_XXX output file type
|
|
|
|
* @param in_filenames An array of input filenames to merge from
|
|
|
|
* @param in_file_count The number of entries in in_filenames
|
|
|
|
* @param do_append Whether to append by file order instead of chronological order
|
|
|
|
* @param mode The IDB_MERGE_MODE_XXX merge mode for interface data
|
|
|
|
* @param snaplen The snaplen to limit it to, or 0 to leave as it is in the files
|
|
|
|
* @param app_name The application name performing the merge, used in SHB info
|
|
|
|
* @param cb The callback information to use during execution
|
|
|
|
* @param[out] err Set to the internal WTAP_ERR_XXX error code if it failed
|
2017-04-20 20:25:21 +00:00
|
|
|
* with MERGE_ERR_CANT_OPEN_INFILE, MERGE_ERR_CANT_OPEN_OUTFILE,
|
|
|
|
* MERGE_ERR_CANT_READ_INFILE, MERGE_ERR_CANT_WRITE_OUTFILE, or
|
|
|
|
* MERGE_ERR_CANT_CLOSE_OUTFILE
|
|
|
|
* @param[out] err_info Additional information for some WTAP_ERR_XXX codes
|
|
|
|
* @param[out] err_fileno Set to the input file number which failed, if it
|
|
|
|
* failed
|
|
|
|
* @param[out] err_framenum Set to the input frame number if it failed
|
2016-12-04 01:57:34 +00:00
|
|
|
* @return the frame type
|
|
|
|
*/
|
|
|
|
WS_DLL_PUBLIC merge_result
|
2022-02-09 14:32:28 +00:00
|
|
|
merge_files_to_tempfile(const char *tmpdir, gchar **out_filenamep, const char *pfx,
|
2016-12-04 01:57:34 +00:00
|
|
|
const int file_type, const char *const *in_filenames,
|
|
|
|
const guint in_file_count, const gboolean do_append,
|
|
|
|
const idb_merge_mode mode, guint snaplen,
|
|
|
|
const gchar *app_name, merge_progress_callback_t* cb,
|
2017-04-20 20:25:21 +00:00
|
|
|
int *err, gchar **err_info, guint *err_fileno,
|
|
|
|
guint32 *err_framenum);
|
2016-12-04 01:57:34 +00:00
|
|
|
|
|
|
|
/** Merge the given input files to the standard output
|
|
|
|
*
|
|
|
|
* @param file_type The WTAP_FILE_TYPE_SUBTYPE_XXX output file type
|
|
|
|
* @param in_filenames An array of input filenames to merge from
|
|
|
|
* @param in_file_count The number of entries in in_filenames
|
|
|
|
* @param do_append Whether to append by file order instead of chronological order
|
|
|
|
* @param mode The IDB_MERGE_MODE_XXX merge mode for interface data
|
|
|
|
* @param snaplen The snaplen to limit it to, or 0 to leave as it is in the files
|
|
|
|
* @param app_name The application name performing the merge, used in SHB info
|
|
|
|
* @param cb The callback information to use during execution
|
|
|
|
* @param[out] err Set to the internal WTAP_ERR_XXX error code if it failed
|
2017-04-20 20:25:21 +00:00
|
|
|
* with MERGE_ERR_CANT_OPEN_INFILE, MERGE_ERR_CANT_OPEN_OUTFILE,
|
|
|
|
* MERGE_ERR_CANT_READ_INFILE, MERGE_ERR_CANT_WRITE_OUTFILE, or
|
|
|
|
* MERGE_ERR_CANT_CLOSE_OUTFILE
|
|
|
|
* @param[out] err_info Additional information for some WTAP_ERR_XXX codes
|
|
|
|
* @param[out] err_fileno Set to the input file number which failed, if it
|
|
|
|
* failed
|
|
|
|
* @param[out] err_framenum Set to the input frame number if it failed
|
2016-12-04 01:57:34 +00:00
|
|
|
* @return the frame type
|
|
|
|
*/
|
|
|
|
WS_DLL_PUBLIC merge_result
|
|
|
|
merge_files_to_stdout(const int file_type, const char *const *in_filenames,
|
|
|
|
const guint in_file_count, const gboolean do_append,
|
|
|
|
const idb_merge_mode mode, guint snaplen,
|
|
|
|
const gchar *app_name, merge_progress_callback_t* cb,
|
2017-04-20 20:25:21 +00:00
|
|
|
int *err, gchar **err_info, guint *err_fileno,
|
|
|
|
guint32 *err_framenum);
|
2016-12-04 01:57:34 +00:00
|
|
|
|
2004-06-18 10:01:59 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
|
|
#endif /* __MERGE_H__ */
|
|
|
|
|