Remove editor modelines and .editorconfig exceptions from root files

pespin/osmux-wip
David Perry 2022-02-20 19:39:37 +00:00 committed by A Wireshark GitLab Utility
parent 695ce22b0d
commit 70d432c357
19 changed files with 15965 additions and 16219 deletions

View File

@ -71,51 +71,3 @@ indent_size = 8
[*.{c,cpp,h}]
indent_style = space
indent_size = 4
[{capinfos,captype,mergecap,tfshark,tshark}.c]
indent_size = 2
[{dftest,randpkt,trigcap}.c]
indent_style = tab
indent_size = tab
[capture_stop_conditions.[ch]]
indent_size = 2
[cfile.[ch]]
indent_size = 2
[conditions.[ch]]
indent_size = 2
[file.[ch]]
indent_size = 2
[frame_tvbuff.[ch]]
indent_style = tab
indent_size = tab
[pcapio.[ch]]
indent_size = 8
[ringbuffer.[ch]]
indent_size = 2
[randpkt_core.[ch]]
indent_style = tab
indent_size = tab
[sharkd.c]
indent_size = 2
[sharkd_daemon.c]
indent_style = tab
indent_size = tab
[sharkd_session.c]
indent_style = tab
indent_size = tab
[version_info.[ch]]
indent_style = tab
indent_size = tab

2824
capinfos.c

File diff suppressed because it is too large Load Diff

229
captype.c
View File

@ -46,12 +46,12 @@
static void
print_usage(FILE *output)
{
fprintf(output, "\n");
fprintf(output, "Usage: captype [options] <infile> ...\n");
fprintf(output, "\n");
fprintf(output, "Miscellaneous:\n");
fprintf(output, " -h, --help display this help and exit\n");
fprintf(output, " -v, --version display version info and exit\n");
fprintf(output, "\n");
fprintf(output, "Usage: captype [options] <infile> ...\n");
fprintf(output, "\n");
fprintf(output, "Miscellaneous:\n");
fprintf(output, " -h, --help display this help and exit\n");
fprintf(output, " -v, --version display version info and exit\n");
}
/*
@ -60,9 +60,9 @@ print_usage(FILE *output)
static void
captype_cmdarg_err(const char *msg_format, va_list ap)
{
fprintf(stderr, "captype: ");
vfprintf(stderr, msg_format, ap);
fprintf(stderr, "\n");
fprintf(stderr, "captype: ");
vfprintf(stderr, msg_format, ap);
fprintf(stderr, "\n");
}
/*
@ -71,145 +71,132 @@ captype_cmdarg_err(const char *msg_format, va_list ap)
static void
captype_cmdarg_err_cont(const char *msg_format, va_list ap)
{
vfprintf(stderr, msg_format, ap);
fprintf(stderr, "\n");
vfprintf(stderr, msg_format, ap);
fprintf(stderr, "\n");
}
int
main(int argc, char *argv[])
{
char *init_progfile_dir_error;
static const struct report_message_routines captype_report_routines = {
failure_message,
failure_message,
open_failure_message,
read_failure_message,
write_failure_message,
cfile_open_failure_message,
cfile_dump_open_failure_message,
cfile_read_failure_message,
cfile_write_failure_message,
cfile_close_failure_message
};
wtap *wth;
int err;
gchar *err_info;
int i;
int opt;
int overall_error_status;
static const struct ws_option long_options[] = {
{"help", ws_no_argument, NULL, 'h'},
{"version", ws_no_argument, NULL, 'v'},
{0, 0, 0, 0 }
};
char *init_progfile_dir_error;
static const struct report_message_routines captype_report_routines = {
failure_message,
failure_message,
open_failure_message,
read_failure_message,
write_failure_message,
cfile_open_failure_message,
cfile_dump_open_failure_message,
cfile_read_failure_message,
cfile_write_failure_message,
cfile_close_failure_message
};
wtap *wth;
int err;
gchar *err_info;
int i;
int opt;
int overall_error_status;
static const struct ws_option long_options[] = {
{"help", ws_no_argument, NULL, 'h'},
{"version", ws_no_argument, NULL, 'v'},
{0, 0, 0, 0 }
};
/*
* Set the C-language locale to the native environment and set the
* code page to UTF-8 on Windows.
*/
/*
* Set the C-language locale to the native environment and set the
* code page to UTF-8 on Windows.
*/
#ifdef _WIN32
setlocale(LC_ALL, ".UTF-8");
setlocale(LC_ALL, ".UTF-8");
#else
setlocale(LC_ALL, "");
setlocale(LC_ALL, "");
#endif
cmdarg_err_init(captype_cmdarg_err, captype_cmdarg_err_cont);
cmdarg_err_init(captype_cmdarg_err, captype_cmdarg_err_cont);
/* Initialize log handler early so we can have proper logging during startup. */
ws_log_init("captype", vcmdarg_err);
/* Initialize log handler early so we can have proper logging during startup. */
ws_log_init("captype", vcmdarg_err);
/* Early logging command-line initialization. */
ws_log_parse_args(&argc, argv, vcmdarg_err, 1);
/* Early logging command-line initialization. */
ws_log_parse_args(&argc, argv, vcmdarg_err, 1);
/* Initialize the version information. */
ws_init_version_info("Captype (Wireshark)", NULL, NULL, NULL);
/* Initialize the version information. */
ws_init_version_info("Captype (Wireshark)", NULL, NULL, NULL);
#ifdef _WIN32
create_app_running_mutex();
create_app_running_mutex();
#endif /* _WIN32 */
/*
* Get credential information for later use.
*/
init_process_policies();
/*
* Get credential information for later use.
*/
init_process_policies();
/*
* Attempt to get the pathname of the directory containing the
* executable file.
*/
init_progfile_dir_error = init_progfile_dir(argv[0]);
if (init_progfile_dir_error != NULL) {
fprintf(stderr,
"captype: Can't get pathname of directory containing the captype program: %s.\n",
init_progfile_dir_error);
g_free(init_progfile_dir_error);
}
/*
* Attempt to get the pathname of the directory containing the
* executable file.
*/
init_progfile_dir_error = init_progfile_dir(argv[0]);
if (init_progfile_dir_error != NULL) {
fprintf(stderr,
"captype: Can't get pathname of directory containing the captype program: %s.\n",
init_progfile_dir_error);
g_free(init_progfile_dir_error);
}
init_report_message("captype", &captype_report_routines);
init_report_message("captype", &captype_report_routines);
wtap_init(TRUE);
wtap_init(TRUE);
/* Process the options */
while ((opt = ws_getopt_long(argc, argv, "hv", long_options, NULL)) !=-1) {
/* Process the options */
while ((opt = ws_getopt_long(argc, argv, "hv", long_options, NULL)) !=-1) {
switch (opt) {
switch (opt) {
case 'h':
show_help_header("Print the file types of capture files.");
print_usage(stdout);
exit(0);
break;
case 'h':
show_help_header("Print the file types of capture files.");
print_usage(stdout);
exit(0);
break;
case 'v':
show_version();
exit(0);
break;
case 'v':
show_version();
exit(0);
break;
case '?': /* Bad flag - print usage message */
case '?': /* Bad flag - print usage message */
print_usage(stderr);
exit(1);
break;
}
}
if (argc < 2) {
print_usage(stderr);
exit(1);
break;
}
}
if (argc < 2) {
print_usage(stderr);
return 1;
}
overall_error_status = 0;
for (i = 1; i < argc; i++) {
wth = wtap_open_offline(argv[i], WTAP_TYPE_AUTO, &err, &err_info, FALSE);
if(wth) {
printf("%s: %s\n", argv[i], wtap_file_type_subtype_name(wtap_file_type_subtype(wth)));
wtap_close(wth);
} else {
if (err == WTAP_ERR_FILE_UNKNOWN_FORMAT)
printf("%s: unknown\n", argv[i]);
else {
cfile_open_failure_message(argv[i], err, err_info);
overall_error_status = 2; /* remember that an error has occurred */
}
return 1;
}
}
overall_error_status = 0;
wtap_cleanup();
free_progdirs();
return overall_error_status;
for (i = 1; i < argc; i++) {
wth = wtap_open_offline(argv[i], WTAP_TYPE_AUTO, &err, &err_info, FALSE);
if(wth) {
printf("%s: %s\n", argv[i], wtap_file_type_subtype_name(wtap_file_type_subtype(wth)));
wtap_close(wth);
} else {
if (err == WTAP_ERR_FILE_UNKNOWN_FORMAT)
printf("%s: unknown\n", argv[i]);
else {
cfile_open_failure_message(argv[i], err, err_info);
overall_error_status = 2; /* remember that an error has occurred */
}
}
}
wtap_cleanup();
free_progdirs();
return overall_error_status;
}
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 2
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* vi: set shiftwidth=2 tabstop=8 expandtab:
* :indentSize=2:tabSize=8:noTabs=true:
*/

17
cfile.c
View File

@ -20,19 +20,6 @@
void
cap_file_init(capture_file *cf)
{
/* Initialize the capture file struct */
memset(cf, 0, sizeof(capture_file));
/* Initialize the capture file struct */
memset(cf, 0, sizeof(capture_file));
}
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
* Local Variables:
* c-basic-offset: 2
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* ex: set shiftwidth=2 tabstop=8 expandtab:
* :indentSize=2:tabSize=8:noTabs=true:
*/

169
cfile.h
View File

@ -25,107 +25,107 @@ extern "C" {
/* Current state of file. */
typedef enum {
FILE_CLOSED, /* No file open */
FILE_READ_IN_PROGRESS, /* Reading a file we've opened */
FILE_READ_ABORTED, /* Read aborted by user */
FILE_READ_DONE /* Read completed */
FILE_CLOSED, /* No file open */
FILE_READ_IN_PROGRESS, /* Reading a file we've opened */
FILE_READ_ABORTED, /* Read aborted by user */
FILE_READ_DONE /* Read completed */
} file_state;
/* Requested packets rescan action. */
typedef enum {
RESCAN_NONE = 0, /* No rescan requested */
RESCAN_SCAN, /* Request rescan without full redissection. */
RESCAN_REDISSECT /* Request full redissection. */
RESCAN_NONE = 0, /* No rescan requested */
RESCAN_SCAN, /* Request rescan without full redissection. */
RESCAN_REDISSECT /* Request full redissection. */
} rescan_type;
/* Character set for text search. */
typedef enum {
SCS_NARROW_AND_WIDE,
SCS_NARROW,
SCS_WIDE
/* add EBCDIC when it's implemented */
SCS_NARROW_AND_WIDE,
SCS_NARROW,
SCS_WIDE
/* add EBCDIC when it's implemented */
} search_charset_t;
typedef enum {
SD_FORWARD,
SD_BACKWARD
SD_FORWARD,
SD_BACKWARD
} search_direction;
/*
* Packet provider for programs using a capture file.
*/
struct packet_provider_data {
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_modified_blocks; /* BST with modified blocks for frames (key = frame_data) */
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_modified_blocks; /* BST with modified blocks for frames (key = frame_data) */
};
typedef struct _capture_file {
epan_t *epan;
file_state state; /* Current state of capture file */
gchar *filename; /* Name of capture file */
gchar *source; /* Temp file source, e.g. "Pipe from elsewhere" */
gboolean is_tempfile; /* Is capture file a temporary file? */
gboolean unsaved_changes; /* Does the capture file have changes that have not been saved? */
gboolean stop_flag; /* Stop current processing (loading, searching, etc.) */
epan_t *epan;
file_state state; /* Current state of capture file */
gchar *filename; /* Name of capture file */
gchar *source; /* Temp file source, e.g. "Pipe from elsewhere" */
gboolean is_tempfile; /* Is capture file a temporary file? */
gboolean unsaved_changes; /* Does the capture file have changes that have not been saved? */
gboolean stop_flag; /* Stop current processing (loading, searching, etc.) */
gint64 f_datalen; /* Size of capture file data (uncompressed) */
guint16 cd_t; /* File type of capture file */
unsigned int open_type; /* open_routine index+1 used, if selected, or WTAP_TYPE_AUTO */
wtap_compression_type compression_type; /* Compression type of the file, or uncompressed */
int lnk_t; /* File link-layer type; could be WTAP_ENCAP_PER_PACKET */
GArray *linktypes; /* Array of packet link-layer types */
guint32 count; /* Total number of frames */
guint64 packet_comment_count; /* Number of comments in frames (could be >1 per frame... */
guint32 displayed_count; /* Number of displayed frames */
guint32 marked_count; /* Number of marked frames */
guint32 ignored_count; /* Number of ignored frames */
guint32 ref_time_count; /* Number of time referenced frames */
gboolean drops_known; /* TRUE if we know how many packets were dropped */
guint32 drops; /* Dropped packets */
nstime_t elapsed_time; /* Elapsed time */
int snap; /* Maximum captured packet length; 0 if unknown */
dfilter_t *rfcode; /* Compiled read filter program */
dfilter_t *dfcode; /* Compiled display filter program */
gchar *dfilter; /* Display filter string */
gboolean redissecting; /* TRUE if currently redissecting (cf_redissect_packets) */
gboolean read_lock; /* TRUE if currently processing a file (cf_read) */
rescan_type redissection_queued; /* Queued redissection type. */
/* search */
gchar *sfilter; /* Filter, hex value, or string being searched */
gboolean hex; /* TRUE if "Hex value" search was last selected */
gboolean string; /* TRUE if "String" search was last selected */
gboolean summary_data; /* TRUE if "String" search in "Packet list" (Info column) was last selected */
gboolean decode_data; /* TRUE if "String" search in "Packet details" was last selected */
gboolean packet_data; /* TRUE if "String" search in "Packet data" was last selected */
guint32 search_pos; /* Byte position of last byte found in a hex search */
guint32 search_len; /* Length of bytes matching the search */
gboolean case_type; /* TRUE if case-insensitive text search */
GRegex *regex; /* Set if regular expression search */
search_charset_t scs_type; /* Character set for text search */
search_direction dir; /* Direction in which to do searches */
gboolean search_in_progress; /* TRUE if user just clicked OK in the Find dialog or hit <control>N/B */
/* packet 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 */
/* Data for currently selected frame */
column_info cinfo; /* Column formatting information */
frame_data *current_frame; /* Frame data */
gint current_row; /* Row number */
epan_dissect_t *edt; /* Protocol dissection */
field_info *finfo_selected; /* Field info */
wtap_rec rec; /* Record header */
Buffer buf; /* Record data */
gint64 f_datalen; /* Size of capture file data (uncompressed) */
guint16 cd_t; /* File type of capture file */
unsigned int open_type; /* open_routine index+1 used, if selected, or WTAP_TYPE_AUTO */
wtap_compression_type compression_type; /* Compression type of the file, or uncompressed */
int lnk_t; /* File link-layer type; could be WTAP_ENCAP_PER_PACKET */
GArray *linktypes; /* Array of packet link-layer types */
guint32 count; /* Total number of frames */
guint64 packet_comment_count; /* Number of comments in frames (could be >1 per frame... */
guint32 displayed_count; /* Number of displayed frames */
guint32 marked_count; /* Number of marked frames */
guint32 ignored_count; /* Number of ignored frames */
guint32 ref_time_count; /* Number of time referenced frames */
gboolean drops_known; /* TRUE if we know how many packets were dropped */
guint32 drops; /* Dropped packets */
nstime_t elapsed_time; /* Elapsed time */
int snap; /* Maximum captured packet length; 0 if unknown */
dfilter_t *rfcode; /* Compiled read filter program */
dfilter_t *dfcode; /* Compiled display filter program */
gchar *dfilter; /* Display filter string */
gboolean redissecting; /* TRUE if currently redissecting (cf_redissect_packets) */
gboolean read_lock; /* TRUE if currently processing a file (cf_read) */
rescan_type redissection_queued; /* Queued redissection type. */
/* search */
gchar *sfilter; /* Filter, hex value, or string being searched */
gboolean hex; /* TRUE if "Hex value" search was last selected */
gboolean string; /* TRUE if "String" search was last selected */
gboolean summary_data; /* TRUE if "String" search in "Packet list" (Info column) was last selected */
gboolean decode_data; /* TRUE if "String" search in "Packet details" was last selected */
gboolean packet_data; /* TRUE if "String" search in "Packet data" was last selected */
guint32 search_pos; /* Byte position of last byte found in a hex search */
guint32 search_len; /* Length of bytes matching the search */
gboolean case_type; /* TRUE if case-insensitive text search */
GRegex *regex; /* Set if regular expression search */
search_charset_t scs_type; /* Character set for text search */
search_direction dir; /* Direction in which to do searches */
gboolean search_in_progress; /* TRUE if user just clicked OK in the Find dialog or hit <control>N/B */
/* packet 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 */
/* Data for currently selected frame */
column_info cinfo; /* Column formatting information */
frame_data *current_frame; /* Frame data */
gint current_row; /* Row number */
epan_dissect_t *edt; /* Protocol dissection */
field_info *finfo_selected; /* Field info */
wtap_rec rec; /* Record header */
Buffer buf; /* Record data */
gpointer window; /* Top-level window associated with file */
gulong computed_elapsed; /* Elapsed time to load the file (in msec). */
gpointer window; /* Top-level window associated with file */
gulong computed_elapsed; /* Elapsed time to load the file (in msec). */
guint32 cum_bytes;
guint32 cum_bytes;
} capture_file;
extern void cap_file_init(capture_file *cf);
@ -140,16 +140,3 @@ void cap_file_provider_set_modified_block(struct packet_provider_data *prov, fra
#endif /* __cplusplus */
#endif /* cfile.h */
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
* Local Variables:
* c-basic-offset: 2
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* vi: set shiftwidth=2 tabstop=8 expandtab:
* :indentSize=2:tabSize=8:noTabs=true:
*/

197
dftest.c
View File

@ -43,115 +43,115 @@ static void dftest_cmdarg_err_cont(const char *fmt, va_list ap);
int
main(int argc, char **argv)
{
char *init_progfile_dir_error;
static const struct report_message_routines dftest_report_routines = {
failure_message,
failure_message,
open_failure_message,
read_failure_message,
write_failure_message,
cfile_open_failure_message,
cfile_dump_open_failure_message,
cfile_read_failure_message,
cfile_write_failure_message,
cfile_close_failure_message
};
char *text;
dfilter_t *df;
gchar *err_msg;
char *init_progfile_dir_error;
static const struct report_message_routines dftest_report_routines = {
failure_message,
failure_message,
open_failure_message,
read_failure_message,
write_failure_message,
cfile_open_failure_message,
cfile_dump_open_failure_message,
cfile_read_failure_message,
cfile_write_failure_message,
cfile_close_failure_message
};
char *text;
dfilter_t *df;
gchar *err_msg;
cmdarg_err_init(dftest_cmdarg_err, dftest_cmdarg_err_cont);
cmdarg_err_init(dftest_cmdarg_err, dftest_cmdarg_err_cont);
/* Initialize log handler early so we can have proper logging during startup. */
ws_log_init("dftest", vcmdarg_err);
/* Initialize log handler early so we can have proper logging during startup. */
ws_log_init("dftest", vcmdarg_err);
/* Early logging command-line initialization. */
ws_log_parse_args(&argc, argv, vcmdarg_err, 1);
/* Early logging command-line initialization. */
ws_log_parse_args(&argc, argv, vcmdarg_err, 1);
/*
* Get credential information for later use.
*/
init_process_policies();
/*
* Get credential information for later use.
*/
init_process_policies();
/*
* Attempt to get the pathname of the directory containing the
* executable file.
*/
init_progfile_dir_error = init_progfile_dir(argv[0]);
if (init_progfile_dir_error != NULL) {
fprintf(stderr, "dftest: Can't get pathname of directory containing the dftest program: %s.\n",
init_progfile_dir_error);
g_free(init_progfile_dir_error);
}
/*
* Attempt to get the pathname of the directory containing the
* executable file.
*/
init_progfile_dir_error = init_progfile_dir(argv[0]);
if (init_progfile_dir_error != NULL) {
fprintf(stderr, "dftest: Can't get pathname of directory containing the dftest program: %s.\n",
init_progfile_dir_error);
g_free(init_progfile_dir_error);
}
init_report_message("dftest", &dftest_report_routines);
init_report_message("dftest", &dftest_report_routines);
timestamp_set_type(TS_RELATIVE);
timestamp_set_seconds_type(TS_SECONDS_DEFAULT);
timestamp_set_type(TS_RELATIVE);
timestamp_set_seconds_type(TS_SECONDS_DEFAULT);
/*
* Libwiretap must be initialized before libwireshark is, so that
* dissection-time handlers for file-type-dependent blocks can
* register using the file type/subtype value for the file type.
*/
wtap_init(TRUE);
/*
* Libwiretap must be initialized before libwireshark is, so that
* dissection-time handlers for file-type-dependent blocks can
* register using the file type/subtype value for the file type.
*/
wtap_init(TRUE);
/* Register all dissectors; we must do this before checking for the
"-g" flag, as the "-g" flag dumps a list of fields registered
by the dissectors, and we must do it before we read the preferences,
in case any dissectors register preferences. */
if (!epan_init(NULL, NULL, FALSE))
return 2;
/* Register all dissectors; we must do this before checking for the
"-g" flag, as the "-g" flag dumps a list of fields registered
by the dissectors, and we must do it before we read the preferences,
in case any dissectors register preferences. */
if (!epan_init(NULL, NULL, FALSE))
return 2;
/*
* Set the C-language locale to the native environment and set the
* code page to UTF-8 on Windows.
*/
/*
* Set the C-language locale to the native environment and set the
* code page to UTF-8 on Windows.
*/
#ifdef _WIN32
setlocale(LC_ALL, ".UTF-8");
setlocale(LC_ALL, ".UTF-8");
#else
setlocale(LC_ALL, "");
setlocale(LC_ALL, "");
#endif
/* Load libwireshark settings from the current profile. */
epan_load_settings();
/* Load libwireshark settings from the current profile. */
epan_load_settings();
/* notify all registered modules that have had any of their preferences
changed either from one of the preferences file or from the command
line that its preferences have changed. */
prefs_apply_all();
/* notify all registered modules that have had any of their preferences
changed either from one of the preferences file or from the command
line that its preferences have changed. */
prefs_apply_all();
/* Check for filter on command line */
if (argc <= 1) {
fprintf(stderr, "Usage: dftest <filter>\n");
exit(1);
}
/* Check for filter on command line */
if (argc <= 1) {
fprintf(stderr, "Usage: dftest <filter>\n");
exit(1);
}
/* Get filter text */
text = get_args_as_string(argc, argv, 1);
/* Get filter text */
text = get_args_as_string(argc, argv, 1);
printf("Filter: %s\n", text);
printf("Filter: %s\n", text);
/* Compile it */
if (!dfilter_compile(text, &df, &err_msg)) {
fprintf(stderr, "dftest: %s\n", err_msg);
g_free(err_msg);
epan_cleanup();
g_free(text);
exit(2);
}
/* Compile it */
if (!dfilter_compile(text, &df, &err_msg)) {
fprintf(stderr, "dftest: %s\n", err_msg);
g_free(err_msg);
epan_cleanup();
g_free(text);
exit(2);
}
printf("\n");
printf("\n");
if (df == NULL)
printf("Filter is empty\n");
else
dfilter_dump(df);
if (df == NULL)
printf("Filter is empty\n");
else
dfilter_dump(df);
dfilter_free(df);
epan_cleanup();
g_free(text);
exit(0);
dfilter_free(df);
epan_cleanup();
g_free(text);
exit(0);
}
/*
@ -160,9 +160,9 @@ main(int argc, char **argv)
static void
dftest_cmdarg_err(const char *fmt, va_list ap)
{
fprintf(stderr, "dftest: ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
fprintf(stderr, "dftest: ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
}
/*
@ -171,19 +171,6 @@ dftest_cmdarg_err(const char *fmt, va_list ap)
static void
dftest_cmdarg_err_cont(const char *fmt, va_list ap)
{
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
}
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 8
* tab-width: 8
* indent-tabs-mode: t
* End:
*
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
* :indentSize=8:tabSize=8:noTabs=false:
*/

7995
file.c

File diff suppressed because it is too large Load Diff

13
file.h
View File

@ -735,16 +735,3 @@ gboolean cf_add_ip_name_from_string(capture_file *cf, const char *addr, const ch
#endif /* __cplusplus */
#endif /* file.h */
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* vi: set shiftwidth=4 tabstop=8 expandtab:
* :indentSize=4:tabSize=8:noTabs=true:
*/

View File

@ -21,36 +21,36 @@
#include "wiretap/wtap-int.h" /* for ->random_fh */
struct tvb_frame {
struct tvbuff tvb;
struct tvbuff tvb;
Buffer *buf; /* Packet data */
Buffer *buf; /* Packet data */
const struct packet_provider_data *prov; /* provider of packet information */
gint64 file_off; /**< File offset */
const struct packet_provider_data *prov; /* provider of packet information */
gint64 file_off; /**< File offset */
guint offset;
guint offset;
};
static gboolean
frame_read(struct tvb_frame *frame_tvb, wtap_rec *rec, Buffer *buf)
{
int err;
gchar *err_info;
gboolean ok = TRUE;
int err;
gchar *err_info;
gboolean ok = TRUE;
/* XXX, what if phdr->caplen isn't equal to
* frame_tvb->tvb.length + frame_tvb->offset?
*/
if (!wtap_seek_read(frame_tvb->prov->wth, frame_tvb->file_off, rec, buf, &err, &err_info)) {
/* XXX - report error! */
switch (err) {
case WTAP_ERR_BAD_FILE:
g_free(err_info);
ok = FALSE;
break;
}
}
return ok;
/* XXX, what if phdr->caplen isn't equal to
* frame_tvb->tvb.length + frame_tvb->offset?
*/
if (!wtap_seek_read(frame_tvb->prov->wth, frame_tvb->file_off, rec, buf, &err, &err_info)) {
/* XXX - report error! */
switch (err) {
case WTAP_ERR_BAD_FILE:
g_free(err_info);
ok = FALSE;
break;
}
}
return ok;
}
static GPtrArray *buffer_cache = NULL;
@ -58,287 +58,274 @@ static GPtrArray *buffer_cache = NULL;
static void
frame_cache(struct tvb_frame *frame_tvb)
{
wtap_rec rec; /* Record metadata */
wtap_rec rec; /* Record metadata */
wtap_rec_init(&rec);
wtap_rec_init(&rec);
if (frame_tvb->buf == NULL) {
if (G_UNLIKELY(!buffer_cache)) buffer_cache = g_ptr_array_sized_new(1024);
if (frame_tvb->buf == NULL) {
if (G_UNLIKELY(!buffer_cache)) buffer_cache = g_ptr_array_sized_new(1024);
if (buffer_cache->len > 0) {
frame_tvb->buf = (struct Buffer *) g_ptr_array_remove_index(buffer_cache, buffer_cache->len - 1);
} else {
frame_tvb->buf = g_new(struct Buffer, 1);
}
if (buffer_cache->len > 0) {
frame_tvb->buf = (struct Buffer *) g_ptr_array_remove_index(buffer_cache, buffer_cache->len - 1);
} else {
frame_tvb->buf = g_new(struct Buffer, 1);
}
ws_buffer_init(frame_tvb->buf, frame_tvb->tvb.length + frame_tvb->offset);
ws_buffer_init(frame_tvb->buf, frame_tvb->tvb.length + frame_tvb->offset);
if (!frame_read(frame_tvb, &rec, frame_tvb->buf))
{ /* TODO: THROW(???); */ }
}
if (!frame_read(frame_tvb, &rec, frame_tvb->buf))
{ /* TODO: THROW(???); */ }
}
frame_tvb->tvb.real_data = ws_buffer_start_ptr(frame_tvb->buf) + frame_tvb->offset;
frame_tvb->tvb.real_data = ws_buffer_start_ptr(frame_tvb->buf) + frame_tvb->offset;
wtap_rec_cleanup(&rec);
wtap_rec_cleanup(&rec);
}
static void
frame_free(tvbuff_t *tvb)
{
struct tvb_frame *frame_tvb = (struct tvb_frame *) tvb;
struct tvb_frame *frame_tvb = (struct tvb_frame *) tvb;
if (frame_tvb->buf) {
ws_buffer_free(frame_tvb->buf);
g_ptr_array_add(buffer_cache, frame_tvb->buf);
}
if (frame_tvb->buf) {
ws_buffer_free(frame_tvb->buf);
g_ptr_array_add(buffer_cache, frame_tvb->buf);
}
}
static const guint8 *
frame_get_ptr(tvbuff_t *tvb, guint abs_offset, guint abs_length _U_)
{
struct tvb_frame *frame_tvb = (struct tvb_frame *) tvb;
struct tvb_frame *frame_tvb = (struct tvb_frame *) tvb;
frame_cache(frame_tvb);
frame_cache(frame_tvb);
return tvb->real_data + abs_offset;
return tvb->real_data + abs_offset;
}
static void *
frame_memcpy(tvbuff_t *tvb, void *target, guint abs_offset, guint abs_length)
{
struct tvb_frame *frame_tvb = (struct tvb_frame *) tvb;
struct tvb_frame *frame_tvb = (struct tvb_frame *) tvb;
frame_cache(frame_tvb);
frame_cache(frame_tvb);
return memcpy(target, tvb->real_data + abs_offset, abs_length);
return memcpy(target, tvb->real_data + abs_offset, abs_length);
}
static gint
frame_find_guint8(tvbuff_t *tvb, guint abs_offset, guint limit, guint8 needle)
{
struct tvb_frame *frame_tvb = (struct tvb_frame *) tvb;
const guint8 *result;
struct tvb_frame *frame_tvb = (struct tvb_frame *) tvb;
const guint8 *result;
frame_cache(frame_tvb);
frame_cache(frame_tvb);
result = (const guint8 *)memchr(tvb->real_data + abs_offset, needle, limit);
if (result)
return (gint) (result - tvb->real_data);
else
return -1;
result = (const guint8 *)memchr(tvb->real_data + abs_offset, needle, limit);
if (result)
return (gint) (result - tvb->real_data);
else
return -1;
}
static gint
frame_pbrk_guint8(tvbuff_t *tvb, guint abs_offset, guint limit, const ws_mempbrk_pattern* pattern, guchar *found_needle)
{
struct tvb_frame *frame_tvb = (struct tvb_frame *) tvb;
struct tvb_frame *frame_tvb = (struct tvb_frame *) tvb;
frame_cache(frame_tvb);
frame_cache(frame_tvb);
return tvb_ws_mempbrk_pattern_guint8(tvb, abs_offset, limit, pattern, found_needle);
return tvb_ws_mempbrk_pattern_guint8(tvb, abs_offset, limit, pattern, found_needle);
}
static guint
frame_offset(const tvbuff_t *tvb _U_, const guint counter)
{
/* XXX: frame_tvb->offset */
return counter;
/* XXX: frame_tvb->offset */
return counter;
}
static tvbuff_t *frame_clone(tvbuff_t *tvb, guint abs_offset, guint abs_length);
static const struct tvb_ops tvb_frame_ops = {
sizeof(struct tvb_frame), /* size */
sizeof(struct tvb_frame), /* size */
frame_free, /* free */
frame_offset, /* offset */
frame_get_ptr, /* get_ptr */
frame_memcpy, /* memcpy */
frame_find_guint8, /* find_guint8 */
frame_pbrk_guint8, /* pbrk_guint8 */
frame_clone, /* clone */
frame_free, /* free */
frame_offset, /* offset */
frame_get_ptr, /* get_ptr */
frame_memcpy, /* memcpy */
frame_find_guint8, /* find_guint8 */
frame_pbrk_guint8, /* pbrk_guint8 */
frame_clone, /* clone */
};
/* based on tvb_new_real_data() */
tvbuff_t *
frame_tvbuff_new(const struct packet_provider_data *prov, const frame_data *fd,
const guint8 *buf)
const guint8 *buf)
{
struct tvb_frame *frame_tvb;
tvbuff_t *tvb;
struct tvb_frame *frame_tvb;
tvbuff_t *tvb;
tvb = tvb_new(&tvb_frame_ops);
tvb = tvb_new(&tvb_frame_ops);
/*
* XXX - currently, the length arguments in
* tvbuff structure are signed, but the captured
* and reported length values are unsigned; this means
* that length values > 2^31 - 1 will appear as
* negative lengths
*
* Captured length values that large will already
* have been filtered out by the Wiretap modules
* (the file will be reported as corrupted), to
* avoid trying to allocate large chunks of data.
*
* Reported length values will not have been
* filtered out, and should not be filtered out,
* as those lengths are not necessarily invalid.
*
* For now, we clip the reported length at G_MAXINT
*
* (XXX, is this still a problem?) There was an exception when we call
* tvb_new_real_data() now there's no one
*/
/*
* XXX - currently, the length arguments in
* tvbuff structure are signed, but the captured
* and reported length values are unsigned; this means
* that length values > 2^31 - 1 will appear as
* negative lengths
*
* Captured length values that large will already
* have been filtered out by the Wiretap modules
* (the file will be reported as corrupted), to
* avoid trying to allocate large chunks of data.
*
* Reported length values will not have been
* filtered out, and should not be filtered out,
* as those lengths are not necessarily invalid.
*
* For now, we clip the reported length at G_MAXINT
*
* (XXX, is this still a problem?) There was an exception when we call
* tvb_new_real_data() now there's no one
*/
tvb->real_data = buf;
tvb->length = fd->cap_len;
tvb->reported_length = fd->pkt_len > G_MAXINT ? G_MAXINT : fd->pkt_len;
tvb->contained_length = tvb->reported_length;
tvb->initialized = TRUE;
tvb->real_data = buf;
tvb->length = fd->cap_len;
tvb->reported_length = fd->pkt_len > G_MAXINT ? G_MAXINT : fd->pkt_len;
tvb->contained_length = tvb->reported_length;
tvb->initialized = TRUE;
/*
* This is the top-level real tvbuff for this data source,
* so its data source tvbuff is itself.
*/
tvb->ds_tvb = tvb;
/*
* This is the top-level real tvbuff for this data source,
* so its data source tvbuff is itself.
*/
tvb->ds_tvb = tvb;
frame_tvb = (struct tvb_frame *) tvb;
frame_tvb = (struct tvb_frame *) tvb;
/* XXX, wtap_can_seek() */
if (prov->wth && prov->wth->random_fh) {
frame_tvb->prov = prov;
frame_tvb->file_off = fd->file_off;
frame_tvb->offset = 0;
} else
frame_tvb->prov = NULL;
/* XXX, wtap_can_seek() */
if (prov->wth && prov->wth->random_fh) {
frame_tvb->prov = prov;
frame_tvb->file_off = fd->file_off;
frame_tvb->offset = 0;
} else
frame_tvb->prov = NULL;
frame_tvb->buf = NULL;
frame_tvb->buf = NULL;
return tvb;
return tvb;
}
tvbuff_t *
frame_tvbuff_new_buffer(const struct packet_provider_data *prov,
const frame_data *fd, Buffer *buf)
const frame_data *fd, Buffer *buf)
{
return frame_tvbuff_new(prov, fd, ws_buffer_start_ptr(buf));
return frame_tvbuff_new(prov, fd, ws_buffer_start_ptr(buf));
}
static tvbuff_t *
frame_clone(tvbuff_t *tvb, guint abs_offset, guint abs_length)
{
struct tvb_frame *frame_tvb = (struct tvb_frame *) tvb;
struct tvb_frame *frame_tvb = (struct tvb_frame *) tvb;
tvbuff_t *cloned_tvb;
struct tvb_frame *cloned_frame_tvb;
tvbuff_t *cloned_tvb;
struct tvb_frame *cloned_frame_tvb;
/* file not seekable */
if (!frame_tvb->prov)
return NULL;
/* file not seekable */
if (!frame_tvb->prov)
return NULL;
abs_offset += frame_tvb->offset;
abs_offset += frame_tvb->offset;
cloned_tvb = tvb_new(&tvb_frame_ops);
cloned_tvb = tvb_new(&tvb_frame_ops);
/* data will be read when needed */
cloned_tvb->real_data = NULL;
cloned_tvb->length = abs_length;
cloned_tvb->reported_length = abs_length; /* XXX? */
cloned_tvb->contained_length = cloned_tvb->reported_length;
cloned_tvb->initialized = TRUE;
/* data will be read when needed */
cloned_tvb->real_data = NULL;
cloned_tvb->length = abs_length;
cloned_tvb->reported_length = abs_length; /* XXX? */
cloned_tvb->contained_length = cloned_tvb->reported_length;
cloned_tvb->initialized = TRUE;
/*
* This is the top-level real tvbuff for this data source,
* so its data source tvbuff is itself.
*/
cloned_tvb->ds_tvb = cloned_tvb;
/*
* This is the top-level real tvbuff for this data source,
* so its data source tvbuff is itself.
*/
cloned_tvb->ds_tvb = cloned_tvb;
cloned_frame_tvb = (struct tvb_frame *) cloned_tvb;
cloned_frame_tvb->prov = frame_tvb->prov;
cloned_frame_tvb->file_off = frame_tvb->file_off;
cloned_frame_tvb->offset = abs_offset;
cloned_frame_tvb->buf = NULL;
cloned_frame_tvb = (struct tvb_frame *) cloned_tvb;
cloned_frame_tvb->prov = frame_tvb->prov;
cloned_frame_tvb->file_off = frame_tvb->file_off;
cloned_frame_tvb->offset = abs_offset;
cloned_frame_tvb->buf = NULL;
return cloned_tvb;
return cloned_tvb;
}
/* based on tvb_new_real_data() */
tvbuff_t *
file_tvbuff_new(const struct packet_provider_data *prov, const frame_data *fd,
const guint8 *buf)
const guint8 *buf)
{
struct tvb_frame *frame_tvb;
tvbuff_t *tvb;
struct tvb_frame *frame_tvb;
tvbuff_t *tvb;
tvb = tvb_new(&tvb_frame_ops);
tvb = tvb_new(&tvb_frame_ops);
/*
* XXX - currently, the length arguments in
* tvbuff structure are signed, but the captured
* and reported length values are unsigned; this means
* that length values > 2^31 - 1 will appear as
* negative lengths
*
* Captured length values that large will already
* have been filtered out by the Wiretap modules
* (the file will be reported as corrupted), to
* avoid trying to allocate large chunks of data.
*
* Reported length values will not have been
* filtered out, and should not be filtered out,
* as those lengths are not necessarily invalid.
*
* For now, we clip the reported length at G_MAXINT
*
* (XXX, is this still a problem?) There was an exception when we call
* tvb_new_real_data() now there's no one
*/
/*
* XXX - currently, the length arguments in
* tvbuff structure are signed, but the captured
* and reported length values are unsigned; this means
* that length values > 2^31 - 1 will appear as
* negative lengths
*
* Captured length values that large will already
* have been filtered out by the Wiretap modules
* (the file will be reported as corrupted), to
* avoid trying to allocate large chunks of data.
*
* Reported length values will not have been
* filtered out, and should not be filtered out,
* as those lengths are not necessarily invalid.
*
* For now, we clip the reported length at G_MAXINT
*
* (XXX, is this still a problem?) There was an exception when we call
* tvb_new_real_data() now there's no one
*/
tvb->real_data = buf;
tvb->length = fd->cap_len;
tvb->reported_length = fd->pkt_len > G_MAXINT ? G_MAXINT : fd->pkt_len;
tvb->contained_length = tvb->reported_length;
tvb->initialized = TRUE;
tvb->real_data = buf;
tvb->length = fd->cap_len;
tvb->reported_length = fd->pkt_len > G_MAXINT ? G_MAXINT : fd->pkt_len;
tvb->contained_length = tvb->reported_length;
tvb->initialized = TRUE;
/*
* This is the top-level real tvbuff for this data source,
* so its data source tvbuff is itself.
*/
tvb->ds_tvb = tvb;
/*
* This is the top-level real tvbuff for this data source,
* so its data source tvbuff is itself.
*/
tvb->ds_tvb = tvb;
frame_tvb = (struct tvb_frame *) tvb;
frame_tvb = (struct tvb_frame *) tvb;
/* XXX, wtap_can_seek() */
if (prov->wth && prov->wth->random_fh) {
frame_tvb->prov = prov;
frame_tvb->file_off = fd->file_off;
frame_tvb->offset = 0;
} else
frame_tvb->prov = NULL;
/* XXX, wtap_can_seek() */
if (prov->wth && prov->wth->random_fh) {
frame_tvb->prov = prov;
frame_tvb->file_off = fd->file_off;
frame_tvb->offset = 0;
} else
frame_tvb->prov = NULL;
frame_tvb->buf = NULL;
frame_tvb->buf = NULL;
return tvb;
return tvb;
}
tvbuff_t *
file_tvbuff_new_buffer(const struct packet_provider_data *prov,
const frame_data *fd, Buffer *buf)
const frame_data *fd, Buffer *buf)
{
return frame_tvbuff_new(prov, fd, ws_buffer_start_ptr(buf));
return frame_tvbuff_new(prov, fd, ws_buffer_start_ptr(buf));
}
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 8
* tab-width: 8
* indent-tabs-mode: t
* End:
*
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
* :indentSize=8:tabSize=8:noTabs=false:
*/

View File

@ -37,16 +37,3 @@ extern tvbuff_t *file_tvbuff_new_buffer(const struct packet_provider_data *prov,
#endif /* __cplusplus */
#endif /* __FRAME_TVBUFF_H__ */
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 8
* tab-width: 8
* indent-tabs-mode: t
* End:
*
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
* :indentSize=8:tabSize=8:noTabs=false:
*/

View File

@ -52,23 +52,23 @@
static void
print_usage(FILE *output)
{
fprintf(output, "\n");
fprintf(output, "Usage: mergecap [options] -w <outfile>|- <infile> [<infile> ...]\n");
fprintf(output, "\n");
fprintf(output, "Output:\n");
fprintf(output, " -a concatenate rather than merge files.\n");
fprintf(output, " default is to merge based on frame timestamps.\n");
fprintf(output, " -s <snaplen> truncate packets to <snaplen> bytes of data.\n");
fprintf(output, " -w <outfile>|- set the output filename to <outfile> or '-' for stdout.\n");
fprintf(output, " -F <capture type> set the output file type; default is pcapng.\n");
fprintf(output, " an empty \"-F\" option will list the file types.\n");
fprintf(output, " -I <IDB merge mode> set the merge mode for Interface Description Blocks; default is 'all'.\n");
fprintf(output, " an empty \"-I\" option will list the merge modes.\n");
fprintf(output, "\n");
fprintf(output, "Miscellaneous:\n");
fprintf(output, " -h display this help and exit.\n");
fprintf(output, " -v verbose output.\n");
fprintf(output, " -V print version information and exit.\n");
fprintf(output, "\n");
fprintf(output, "Usage: mergecap [options] -w <outfile>|- <infile> [<infile> ...]\n");
fprintf(output, "\n");
fprintf(output, "Output:\n");
fprintf(output, " -a concatenate rather than merge files.\n");
fprintf(output, " default is to merge based on frame timestamps.\n");
fprintf(output, " -s <snaplen> truncate packets to <snaplen> bytes of data.\n");
fprintf(output, " -w <outfile>|- set the output filename to <outfile> or '-' for stdout.\n");
fprintf(output, " -F <capture type> set the output file type; default is pcapng.\n");
fprintf(output, " an empty \"-F\" option will list the file types.\n");
fprintf(output, " -I <IDB merge mode> set the merge mode for Interface Description Blocks; default is 'all'.\n");
fprintf(output, " an empty \"-I\" option will list the merge modes.\n");
fprintf(output, "\n");
fprintf(output, "Miscellaneous:\n");
fprintf(output, " -h display this help and exit.\n");
fprintf(output, " -v verbose output.\n");
fprintf(output, " -V print version information and exit.\n");
}
/*
@ -77,9 +77,9 @@ print_usage(FILE *output)
static void
mergecap_cmdarg_err(const char *fmt, va_list ap)
{
fprintf(stderr, "mergecap: ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
fprintf(stderr, "mergecap: ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
}
/*
@ -88,352 +88,339 @@ mergecap_cmdarg_err(const char *fmt, va_list ap)
static void
mergecap_cmdarg_err_cont(const char *fmt, va_list ap)
{
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");