#include <getopt.h>
#endif
+#include <wiretap/secrets-types.h>
#include <wiretap/wtap.h>
#include "epan/etypes.h"
#endif
#ifdef _WIN32
-#include <wsutil/unicode-utils.h>
#include <process.h> /* getpid */
#include <winsock2.h>
#endif
# include "wsutil/strptime.h"
#endif
-#include <wsutil/crash_info.h>
-#include <wsutil/clopts_common.h>
-#include <wsutil/cmdarg_err.h>
+#include <ui/clopts_common.h>
+#include <ui/cmdarg_err.h>
#include <wsutil/filesystem.h>
#include <wsutil/file_util.h>
#include <wsutil/wsgcrypt.h>
#include <wsutil/report_message.h>
#include <wsutil/strnatcmp.h>
#include <wsutil/str_util.h>
+#include <cli_main.h>
#include <version_info.h>
#include <wsutil/pint.h>
#include <wsutil/strtoi.h>
static struct time_adjustment strict_time_adj = {NSTIME_INIT_ZERO, 0}; /* strict time adjustment */
static nstime_t previous_time = NSTIME_INIT_ZERO; /* previous time */
+static const struct {
+ const char *str;
+ guint32 id;
+} secrets_types[] = {
+ { "tls", SECRETS_TYPE_TLS },
+};
+
static int find_dct2000_real_data(guint8 *buf);
static void handle_chopping(chop_t chop, wtap_packet_header *out_phdr,
const wtap_packet_header *in_phdr, guint8 **buf,
fprintf(output, " -i <seconds per file> split the packet output to different files based on\n");
fprintf(output, " uniform time intervals with a maximum of\n");
fprintf(output, " <seconds per file> each.\n");
- fprintf(output, " -F <capture type> set the output file type; default is pcapng. An empty\n");
- fprintf(output, " \"-F\" option will list the file types.\n");
+#ifdef PCAP_NG_DEFAULT
+ fprintf(output, " -F <capture type> set the output file type; default is pcapng.\n");
+#else
+ fprintf(output, " -F <capture type> set the output file type; default is pcap.\n");
+#endif
+ fprintf(output, " An empty \"-F\" option will list the file types.\n");
fprintf(output, " -T <encap type> set the output file encapsulation type; default is the\n");
fprintf(output, " same as the input file. An empty \"-T\" option will\n");
fprintf(output, " list the encapsulation types.\n");
g_free(encaps);
}
+static void
+list_secrets_types(FILE *stream)
+{
+ for (guint i = 0; i < G_N_ELEMENTS(secrets_types); i++) {
+ fprintf(stream, " %s\n", secrets_types[i].str);
+ }
+}
+
+static guint32
+lookup_secrets_type(const char *type)
+{
+ for (guint i = 0; i < G_N_ELEMENTS(secrets_types); i++) {
+ if (!strcmp(secrets_types[i].str, type)) {
+ return secrets_types[i].id;
+ }
+ }
+ return 0;
+}
+
static int
framenum_compare(gconstpointer a, gconstpointer b, gpointer user_data _U_)
{
}
static wtap_dumper *
-editcap_dump_open(const char *filename, guint32 snaplen,
- GArray* shb_hdrs,
- wtapng_iface_descriptions_t *idb_inf,
- GArray* nrb_hdrs, int *write_err)
+editcap_dump_open(const char *filename, const wtap_dump_params *params,
+ int *write_err)
{
wtap_dumper *pdh;
if (strcmp(filename, "-") == 0) {
/* Write to the standard output. */
- pdh = wtap_dump_open_stdout_ng(out_file_type_subtype, out_frame_type,
- snaplen, FALSE /* compressed */,
- shb_hdrs, idb_inf, nrb_hdrs, write_err);
+ pdh = wtap_dump_open_stdout(out_file_type_subtype, WTAP_UNCOMPRESSED,
+ params, write_err);
} else {
- pdh = wtap_dump_open_ng(filename, out_file_type_subtype, out_frame_type,
- snaplen, FALSE /* compressed */,
- shb_hdrs, idb_inf, nrb_hdrs, write_err);
+ pdh = wtap_dump_open(filename, out_file_type_subtype, WTAP_UNCOMPRESSED,
+ params, write_err);
}
return pdh;
}
int
main(int argc, char *argv[])
{
- GString *comp_info_str;
- GString *runtime_info_str;
char *init_progfile_dir_error;
wtap *wth = NULL;
int i, j, read_err, write_err;
{"novlan", no_argument, NULL, 0x8100},
{"skip-radiotap-header", no_argument, NULL, 0x8101},
{"seed", required_argument, NULL, 0x8102},
+ {"inject-secrets", required_argument, NULL, 0x8103},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'V'},
{0, 0, 0, 0 }
gchar *fsuffix = NULL;
guint32 change_offset = 0;
guint max_packet_number = 0;
+ GArray *dsb_types = NULL;
+ GPtrArray *dsb_filenames = NULL;
const wtap_rec *rec;
wtap_rec temp_rec;
- wtapng_iface_descriptions_t *idb_inf = NULL;
- GArray *shb_hdrs = NULL;
- GArray *nrb_hdrs = NULL;
+ wtap_dump_params params = WTAP_DUMP_PARAMS_INIT;
char *shb_user_appl;
gboolean do_mutation;
guint32 caplen;
cmdarg_err_init(failure_warning_message, failure_message_cont);
#ifdef _WIN32
- arg_list_utf_16to8(argc, argv);
create_app_running_mutex();
#endif /* _WIN32 */
- /* Get the compile-time version information string */
- comp_info_str = get_compiled_version_info(NULL, NULL);
-
- /* Get the run-time version information string */
- runtime_info_str = get_runtime_version_info(NULL);
-
- /* Add it to the information to be reported on a crash. */
- ws_add_crash_info("Editcap (Wireshark) %s\n"
- "\n"
- "%s"
- "\n"
- "%s",
- get_ws_vcs_version_info(), comp_info_str->str, runtime_info_str->str);
- g_string_free(comp_info_str, TRUE);
- g_string_free(runtime_info_str, TRUE);
+ /* Initialize the version information. */
+ ws_init_version_info("Editcap (Wireshark)", NULL, NULL, NULL);
/*
* Get credential information for later use.
break;
}
+ case 0x8103: /* --inject-secrets */
+ {
+ guint32 secrets_type_id = 0;
+ const char *secrets_filename = NULL;
+ if (strcmp("help", optarg) == 0) {
+ list_secrets_types(stdout);
+ goto clean_exit;
+ }
+ gchar **splitted = g_strsplit(optarg, ",", 2);
+ if (splitted[0]) {
+ secrets_type_id = lookup_secrets_type(splitted[0]);
+ secrets_filename = splitted[1];
+ }
+
+ if (secrets_type_id == 0) {
+ fprintf(stderr, "editcap: \"%s\" isn't a valid secrets type\n", secrets_filename);
+ g_strfreev(splitted);
+ ret = INVALID_OPTION;
+ goto clean_exit;
+ }
+ if (!dsb_filenames) {
+ dsb_types = g_array_new(FALSE, FALSE, sizeof(guint32));
+ dsb_filenames = g_ptr_array_new_with_free_func(g_free);
+ }
+ g_array_append_val(dsb_types, secrets_type_id);
+ g_ptr_array_add(dsb_filenames, g_strdup(secrets_filename));
+ g_strfreev(splitted);
+ break;
+ }
+
case 'a':
{
guint frame_number;
break;
case 'h':
- printf("Editcap (Wireshark) %s\n"
- "Edit and/or translate the format of capture files.\n"
- "See https://www.wireshark.org for more information.\n",
- get_ws_vcs_version_info());
+ show_help_header("Edit and/or translate the format of capture files.");
print_usage(stdout);
goto clean_exit;
break;
break;
case 'V':
- comp_info_str = get_compiled_version_info(NULL, NULL);
- runtime_info_str = get_runtime_version_info(NULL);
- show_version("Editcap (Wireshark)", comp_info_str, runtime_info_str);
- g_string_free(comp_info_str, TRUE);
- g_string_free(runtime_info_str, TRUE);
+ show_version();
goto clean_exit;
break;
fprintf(stderr, "Optind = %i, argc = %i\n", optind, argc);
#endif
- if ((argc - optind) < 1) {
+ if ((argc - optind) < 2) {
print_usage(stderr);
ret = INVALID_OPTION;
goto clean_exit;
goto clean_exit;
}
- shb_hdrs = wtap_file_get_shb_for_new_file(wth);
- idb_inf = wtap_file_get_idb_info(wth);
- nrb_hdrs = wtap_file_get_nrb_for_new_file(wth);
+ wtap_dump_params_init(¶ms, wth);
+
+ if (dsb_filenames) {
+ for (guint k = 0; k < dsb_filenames->len; k++) {
+ guint32 secrets_type_id = g_array_index(dsb_types, guint32, k);
+ const char *secrets_filename = (const char *)g_ptr_array_index(dsb_filenames, k);
+ char *data;
+ gsize data_len;
+ wtap_block_t block;
+ wtapng_dsb_mandatory_t *dsb;
+ GError *err = NULL;
+
+ if (!g_file_get_contents(secrets_filename, &data, &data_len, &err)) {
+ fprintf(stderr, "editcap: \"%s\" could not be read: %s\n", secrets_filename, err->message);
+ g_clear_error(&err);
+ ret = INVALID_OPTION;
+ goto clean_exit;
+ }
+ if (data_len == 0) {
+ fprintf(stderr, "editcap: \"%s\" is an empty file, ignoring\n", secrets_filename);
+ g_free(data);
+ continue;
+ }
+ if (data_len >= G_MAXINT) {
+ fprintf(stderr, "editcap: \"%s\" is too large, ignoring\n", secrets_filename);
+ g_free(data);
+ continue;
+ }
+
+ block = wtap_block_create(WTAP_BLOCK_DSB);
+ dsb = (wtapng_dsb_mandatory_t *)wtap_block_get_mandatory_data(block);
+ dsb->secrets_type = secrets_type_id;
+ dsb->secrets_len = (guint)data_len;
+ dsb->secrets_data = data;
+ if (params.dsbs_initial == NULL) {
+ params.dsbs_initial = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
+ }
+ g_array_append_val(params.dsbs_initial, block);
+ }
+ }
/*
- * Now, process the rest, if any ... we only write if there is an extra
- * argument or so ...
+ * If an encapsulation type was specified, override the encapsulation
+ * type of the input file.
*/
+ if (out_frame_type != -2)
+ params.encap = out_frame_type;
- if ((argc - optind) >= 2) {
- if (out_frame_type == -2)
- out_frame_type = wtap_file_encap(wth);
+ /*
+ * If a snapshot length was specified, and it's less than the snapshot
+ * length of the input file, override the snapshot length of the input
+ * file.
+ */
+ if (snaplen != 0 && snaplen < wtap_snapshot_length(wth))
+ params.snaplen = snaplen;
- for (i = optind + 2; i < argc; i++)
- if (add_selection(argv[i], &max_packet_number) == FALSE)
- break;
+ /*
+ * Now process the arguments following the input and output file
+ * names, if any; they specify packets to include/exclude.
+ */
+ for (i = optind + 2; i < argc; i++)
+ if (add_selection(argv[i], &max_packet_number) == FALSE)
+ break;
- if (keep_em == FALSE)
- max_packet_number = G_MAXUINT;
+ if (keep_em == FALSE)
+ max_packet_number = G_MAXUINT;
- if (dup_detect || dup_detect_by_time) {
- for (i = 0; i < dup_window; i++) {
- memset(&fd_hash[i].digest, 0, 16);
- fd_hash[i].len = 0;
- nstime_set_unset(&fd_hash[i].frame_time);
- }
+ if (dup_detect || dup_detect_by_time) {
+ for (i = 0; i < dup_window; i++) {
+ memset(&fd_hash[i].digest, 0, 16);
+ fd_hash[i].len = 0;
+ nstime_set_unset(&fd_hash[i].frame_time);
}
+ }
- /* Read all of the packets in turn */
- while (wtap_read(wth, &read_err, &read_err_info, &data_offset)) {
- if (max_packet_number <= read_count)
- break;
-
- read_count++;
+ /* Read all of the packets in turn */
+ while (wtap_read(wth, &read_err, &read_err_info, &data_offset)) {
+ if (max_packet_number <= read_count)
+ break;
- rec = wtap_get_rec(wth);
+ read_count++;
- /* Extra actions for the first packet */
- if (read_count == 1) {
- if (split_packet_count != 0 || secs_per_block != 0) {
- if (!fileset_extract_prefix_suffix(argv[optind+1], &fprefix, &fsuffix)) {
- ret = CANT_EXTRACT_PREFIX;
- goto clean_exit;
- }
+ rec = wtap_get_rec(wth);
- filename = fileset_get_filename_by_pattern(block_cnt++, rec, fprefix, fsuffix);
- } else {
- filename = g_strdup(argv[optind+1]);
+ /* Extra actions for the first packet */
+ if (read_count == 1) {
+ if (split_packet_count != 0 || secs_per_block != 0) {
+ if (!fileset_extract_prefix_suffix(argv[optind+1], &fprefix, &fsuffix)) {
+ ret = CANT_EXTRACT_PREFIX;
+ goto clean_exit;
}
- g_assert(filename);
- /* If we don't have an application name add Editcap */
- if (wtap_block_get_string_option_value(g_array_index(shb_hdrs, wtap_block_t, 0), OPT_SHB_USERAPPL, &shb_user_appl) != WTAP_OPTTYPE_SUCCESS) {
- wtap_block_add_string_option_format(g_array_index(shb_hdrs, wtap_block_t, 0), OPT_SHB_USERAPPL, "Editcap " VERSION);
- }
+ filename = fileset_get_filename_by_pattern(block_cnt++, rec, fprefix, fsuffix);
+ } else {
+ filename = g_strdup(argv[optind+1]);
+ }
+ g_assert(filename);
- pdh = editcap_dump_open(filename,
- snaplen ? MIN(snaplen, wtap_snapshot_length(wth)) : wtap_snapshot_length(wth),
- shb_hdrs, idb_inf, nrb_hdrs, &write_err);
+ /* If we don't have an application name add one */
+ if (wtap_block_get_string_option_value(g_array_index(params.shb_hdrs, wtap_block_t, 0), OPT_SHB_USERAPPL, &shb_user_appl) != WTAP_OPTTYPE_SUCCESS) {
+ wtap_block_add_string_option_format(g_array_index(params.shb_hdrs, wtap_block_t, 0), OPT_SHB_USERAPPL, "%s", get_appname_and_version());
+ }
- if (pdh == NULL) {
- cfile_dump_open_failure_message("editcap", filename,
- write_err,
- out_file_type_subtype);
- ret = INVALID_FILE;
- goto clean_exit;
- }
- } /* first packet only handling */
+ pdh = editcap_dump_open(filename, ¶ms, &write_err);
+
+ if (pdh == NULL) {
+ cfile_dump_open_failure_message("editcap", filename,
+ write_err,
+ out_file_type_subtype);
+ ret = INVALID_FILE;
+ goto clean_exit;
+ }
+ } /* first packet only handling */
- buf = wtap_get_buf_ptr(wth);
+ buf = wtap_get_buf_ptr(wth);
- /*
- * Not all packets have time stamps. Only process the time
- * stamp if we have one.
- */
- if (rec->presence_flags & WTAP_HAS_TS) {
- if (nstime_is_unset(&block_start)) {
- block_start = rec->ts;
- }
- if (secs_per_block != 0) {
- while (((guint32)(rec->ts.secs - block_start.secs) > secs_per_block)
- || ((guint32)(rec->ts.secs - block_start.secs) == secs_per_block
- && rec->ts.nsecs >= block_start.nsecs )) { /* time for the next file */
-
- if (!wtap_dump_close(pdh, &write_err)) {
- cfile_close_failure_message(filename, write_err);
- ret = WRITE_ERROR;
- goto clean_exit;
- }
- block_start.secs = block_start.secs + secs_per_block; /* reset for next interval */
- g_free(filename);
- filename = fileset_get_filename_by_pattern(block_cnt++, rec, fprefix, fsuffix);
- g_assert(filename);
-
- if (verbose)
- fprintf(stderr, "Continuing writing in file %s\n", filename);
-
- pdh = editcap_dump_open(filename,
- snaplen ? MIN(snaplen, wtap_snapshot_length(wth)) : wtap_snapshot_length(wth),
- shb_hdrs, idb_inf, nrb_hdrs, &write_err);
-
- if (pdh == NULL) {
- cfile_dump_open_failure_message("editcap", filename,
- write_err,
- out_file_type_subtype);
- ret = INVALID_FILE;
- goto clean_exit;
- }
- }
- }
- } /* time stamp handling */
+ /*
+ * Not all packets have time stamps. Only process the time
+ * stamp if we have one.
+ */
+ if (rec->presence_flags & WTAP_HAS_TS) {
+ if (nstime_is_unset(&block_start)) {
+ block_start = rec->ts;
+ }
+ if (secs_per_block != 0) {
+ while (((guint32)(rec->ts.secs - block_start.secs) > secs_per_block)
+ || ((guint32)(rec->ts.secs - block_start.secs) == secs_per_block
+ && rec->ts.nsecs >= block_start.nsecs )) { /* time for the next file */
- if (split_packet_count != 0) {
- /* time for the next file? */
- if (written_count > 0 && (written_count % split_packet_count) == 0) {
if (!wtap_dump_close(pdh, &write_err)) {
cfile_close_failure_message(filename, write_err);
ret = WRITE_ERROR;
goto clean_exit;
}
-
+ block_start.secs = block_start.secs + secs_per_block; /* reset for next interval */
g_free(filename);
filename = fileset_get_filename_by_pattern(block_cnt++, rec, fprefix, fsuffix);
g_assert(filename);
if (verbose)
fprintf(stderr, "Continuing writing in file %s\n", filename);
- pdh = editcap_dump_open(filename,
- snaplen ? MIN(snaplen, wtap_snapshot_length(wth)) : wtap_snapshot_length(wth),
- shb_hdrs, idb_inf, nrb_hdrs, &write_err);
+ pdh = editcap_dump_open(filename, ¶ms, &write_err);
+
if (pdh == NULL) {
cfile_dump_open_failure_message("editcap", filename,
write_err,
goto clean_exit;
}
}
- } /* split packet handling */
+ }
+ } /* time stamp handling */
+
+ if (split_packet_count != 0) {
+ /* time for the next file? */
+ if (written_count > 0 && (written_count % split_packet_count) == 0) {
+ if (!wtap_dump_close(pdh, &write_err)) {
+ cfile_close_failure_message(filename, write_err);
+ ret = WRITE_ERROR;
+ goto clean_exit;
+ }
- if (check_startstop) {
- /*
- * Is the packet in the selected timeframe?
- * If the packet has no time stamp, the answer is "no".
- */
- if (rec->presence_flags & WTAP_HAS_TS)
- ts_okay = (rec->ts.secs >= starttime) && (rec->ts.secs < stoptime);
- else
- ts_okay = FALSE;
- } else {
- /*
- * No selected timeframe, so all packets are "in the
- * selected timeframe".
- */
- ts_okay = TRUE;
+ g_free(filename);
+ filename = fileset_get_filename_by_pattern(block_cnt++, rec, fprefix, fsuffix);
+ g_assert(filename);
+
+ if (verbose)
+ fprintf(stderr, "Continuing writing in file %s\n", filename);
+
+ pdh = editcap_dump_open(filename, ¶ms, &write_err);
+ if (pdh == NULL) {
+ cfile_dump_open_failure_message("editcap", filename,
+ write_err,
+ out_file_type_subtype);
+ ret = INVALID_FILE;
+ goto clean_exit;
+ }
}
+ } /* split packet handling */
+
+ if (check_startstop) {
+ /*
+ * Is the packet in the selected timeframe?
+ * If the packet has no time stamp, the answer is "no".
+ */
+ if (rec->presence_flags & WTAP_HAS_TS)
+ ts_okay = (rec->ts.secs >= starttime) && (rec->ts.secs < stoptime);
+ else
+ ts_okay = FALSE;
+ } else {
+ /*
+ * No selected timeframe, so all packets are "in the
+ * selected timeframe".
+ */
+ ts_okay = TRUE;
+ }
- if (ts_okay && ((!selected(count) && !keep_em)
- || (selected(count) && keep_em))) {
+ if (ts_okay && ((!selected(count) && !keep_em)
+ || (selected(count) && keep_em))) {
- if (verbose && !dup_detect && !dup_detect_by_time)
- fprintf(stderr, "Packet: %u\n", count);
+ if (verbose && !dup_detect && !dup_detect_by_time)
+ fprintf(stderr, "Packet: %u\n", count);
- /* We simply write it, perhaps after truncating it; we could
- * do other things, like modify it. */
+ /* We simply write it, perhaps after truncating it; we could
+ * do other things, like modify it. */
- rec = wtap_get_rec(wth);
+ rec = wtap_get_rec(wth);
- if (rec->presence_flags & WTAP_HAS_TS) {
- /* Do we adjust timestamps to ensure strict chronological
- * order? */
- if (do_strict_time_adjustment) {
- if (previous_time.secs || previous_time.nsecs) {
- if (!strict_time_adj.is_negative) {
- nstime_t current;
- nstime_t delta;
-
- current = rec->ts;
-
- nstime_delta(&delta, ¤t, &previous_time);
-
- if (delta.secs < 0 || delta.nsecs < 0) {
- /*
- * A negative delta indicates that the current packet
- * has an absolute timestamp less than the previous packet
- * that it is being compared to. This is NOT a normal
- * situation since trace files usually have packets in
- * chronological order (oldest to newest).
- * Copy and change rather than modify
- * returned rec.
- */
- /* fprintf(stderr, "++out of order, need to adjust this packet!\n"); */
- temp_rec = *rec;
- temp_rec.ts.secs = previous_time.secs + strict_time_adj.tv.secs;
- temp_rec.ts.nsecs = previous_time.nsecs;
- if (temp_rec.ts.nsecs + strict_time_adj.tv.nsecs >= ONE_BILLION) {
- /* carry */
- temp_rec.ts.secs++;
- temp_rec.ts.nsecs += strict_time_adj.tv.nsecs - ONE_BILLION;
- } else {
- temp_rec.ts.nsecs += strict_time_adj.tv.nsecs;
- }
- rec = &temp_rec;
- }
- } else {
+ if (rec->presence_flags & WTAP_HAS_TS) {
+ /* Do we adjust timestamps to ensure strict chronological
+ * order? */
+ if (do_strict_time_adjustment) {
+ if (previous_time.secs || previous_time.nsecs) {
+ if (!strict_time_adj.is_negative) {
+ nstime_t current;
+ nstime_t delta;
+
+ current = rec->ts;
+
+ nstime_delta(&delta, ¤t, &previous_time);
+
+ if (delta.secs < 0 || delta.nsecs < 0) {
/*
- * A negative strict time adjustment is requested.
- * Unconditionally set each timestamp to previous
- * packet's timestamp plus delta.
- * Copy and change rather than modify returned
- * rec.
+ * A negative delta indicates that the current packet
+ * has an absolute timestamp less than the previous packet
+ * that it is being compared to. This is NOT a normal
+ * situation since trace files usually have packets in
+ * chronological order (oldest to newest).
+ * Copy and change rather than modify
+ * returned rec.
*/
+ /* fprintf(stderr, "++out of order, need to adjust this packet!\n"); */
temp_rec = *rec;
temp_rec.ts.secs = previous_time.secs + strict_time_adj.tv.secs;
temp_rec.ts.nsecs = previous_time.nsecs;
}
rec = &temp_rec;
}
- }
- previous_time = rec->ts;
- }
-
- if (time_adj.tv.secs != 0) {
- /* Copy and change rather than modify returned rec */
- temp_rec = *rec;
- if (time_adj.is_negative)
- temp_rec.ts.secs -= time_adj.tv.secs;
- else
- temp_rec.ts.secs += time_adj.tv.secs;
- rec = &temp_rec;
- }
-
- if (time_adj.tv.nsecs != 0) {
- /* Copy and change rather than modify returned rec */
- temp_rec = *rec;
- if (time_adj.is_negative) { /* subtract */
- if (temp_rec.ts.nsecs < time_adj.tv.nsecs) { /* borrow */
- temp_rec.ts.secs--;
- temp_rec.ts.nsecs += ONE_BILLION;
- }
- temp_rec.ts.nsecs -= time_adj.tv.nsecs;
- } else { /* add */
- if (temp_rec.ts.nsecs + time_adj.tv.nsecs >= ONE_BILLION) {
+ } else {
+ /*
+ * A negative strict time adjustment is requested.
+ * Unconditionally set each timestamp to previous
+ * packet's timestamp plus delta.
+ * Copy and change rather than modify returned
+ * rec.
+ */
+ temp_rec = *rec;
+ temp_rec.ts.secs = previous_time.secs + strict_time_adj.tv.secs;
+ temp_rec.ts.nsecs = previous_time.nsecs;
+ if (temp_rec.ts.nsecs + strict_time_adj.tv.nsecs >= ONE_BILLION) {
/* carry */
temp_rec.ts.secs++;
- temp_rec.ts.nsecs += time_adj.tv.nsecs - ONE_BILLION;
+ temp_rec.ts.nsecs += strict_time_adj.tv.nsecs - ONE_BILLION;
} else {
- temp_rec.ts.nsecs += time_adj.tv.nsecs;
+ temp_rec.ts.nsecs += strict_time_adj.tv.nsecs;
}
+ rec = &temp_rec;
}
- rec = &temp_rec;
}
- } /* time stamp adjustment */
+ previous_time = rec->ts;
+ }
- if (rec->rec_type == REC_TYPE_PACKET) {
- if (snaplen != 0) {
- /* Limit capture length to snaplen */
- if (rec->rec_header.packet_header.caplen > snaplen) {
- /* Copy and change rather than modify returned wtap_rec */
- temp_rec = *rec;
- temp_rec.rec_header.packet_header.caplen = snaplen;
- rec = &temp_rec;
+ if (time_adj.tv.secs != 0) {
+ /* Copy and change rather than modify returned rec */
+ temp_rec = *rec;
+ if (time_adj.is_negative)
+ temp_rec.ts.secs -= time_adj.tv.secs;
+ else
+ temp_rec.ts.secs += time_adj.tv.secs;
+ rec = &temp_rec;
+ }
+
+ if (time_adj.tv.nsecs != 0) {
+ /* Copy and change rather than modify returned rec */
+ temp_rec = *rec;
+ if (time_adj.is_negative) { /* subtract */
+ if (temp_rec.ts.nsecs < time_adj.tv.nsecs) { /* borrow */
+ temp_rec.ts.secs--;
+ temp_rec.ts.nsecs += ONE_BILLION;
}
- /* If -L, also set reported length to snaplen */
- if (adjlen && rec->rec_header.packet_header.len > snaplen) {
- /* Copy and change rather than modify returned phdr */
- temp_rec = *rec;
- temp_rec.rec_header.packet_header.len = snaplen;
- rec = &temp_rec;
+ temp_rec.ts.nsecs -= time_adj.tv.nsecs;
+ } else { /* add */
+ if (temp_rec.ts.nsecs + time_adj.tv.nsecs >= ONE_BILLION) {
+ /* carry */
+ temp_rec.ts.secs++;
+ temp_rec.ts.nsecs += time_adj.tv.nsecs - ONE_BILLION;
+ } else {
+ temp_rec.ts.nsecs += time_adj.tv.nsecs;
}
}
-
- /*
- * CHOP
- * Copy and change rather than modify returned phdr.
- */
- temp_rec = *rec;
- handle_chopping(chop, &temp_rec.rec_header.packet_header,
- &rec->rec_header.packet_header, &buf,
- adjlen);
rec = &temp_rec;
+ }
+ } /* time stamp adjustment */
- /* remove vlan info */
- if (rem_vlan) {
- /* Copy and change rather than modify returned rec */
+ if (rec->rec_type == REC_TYPE_PACKET) {
+ if (snaplen != 0) {
+ /* Limit capture length to snaplen */
+ if (rec->rec_header.packet_header.caplen > snaplen) {
+ /* Copy and change rather than modify returned wtap_rec */
+ temp_rec = *rec;
+ temp_rec.rec_header.packet_header.caplen = snaplen;
+ rec = &temp_rec;
+ }
+ /* If -L, also set reported length to snaplen */
+ if (adjlen && rec->rec_header.packet_header.len > snaplen) {
+ /* Copy and change rather than modify returned phdr */
temp_rec = *rec;
- remove_vlan_info(&rec->rec_header.packet_header, buf,
- &temp_rec.rec_header.packet_header.caplen);
+ temp_rec.rec_header.packet_header.len = snaplen;
rec = &temp_rec;
}
+ }
- /* suppress duplicates by packet window */
- if (dup_detect) {
- if (is_duplicate(buf, rec->rec_header.packet_header.caplen)) {
+ /*
+ * CHOP
+ * Copy and change rather than modify returned phdr.
+ */
+ temp_rec = *rec;
+ handle_chopping(chop, &temp_rec.rec_header.packet_header,
+ &rec->rec_header.packet_header, &buf,
+ adjlen);
+ rec = &temp_rec;
+
+ /* remove vlan info */
+ if (rem_vlan) {
+ /* Copy and change rather than modify returned rec */
+ temp_rec = *rec;
+ remove_vlan_info(&rec->rec_header.packet_header, buf,
+ &temp_rec.rec_header.packet_header.caplen);
+ rec = &temp_rec;
+ }
+
+ /* suppress duplicates by packet window */
+ if (dup_detect) {
+ if (is_duplicate(buf, rec->rec_header.packet_header.caplen)) {
+ if (verbose) {
+ fprintf(stderr, "Skipped: %u, Len: %u, MD5 Hash: ",
+ count,
+ rec->rec_header.packet_header.caplen);
+ for (i = 0; i < 16; i++)
+ fprintf(stderr, "%02x",
+ (unsigned char)fd_hash[cur_dup_entry].digest[i]);
+ fprintf(stderr, "\n");
+ }
+ duplicate_count++;
+ count++;
+ continue;
+ } else {
+ if (verbose) {
+ fprintf(stderr, "Packet: %u, Len: %u, MD5 Hash: ",
+ count,
+ rec->rec_header.packet_header.caplen);
+ for (i = 0; i < 16; i++)
+ fprintf(stderr, "%02x",
+ (unsigned char)fd_hash[cur_dup_entry].digest[i]);
+ fprintf(stderr, "\n");
+ }
+ }
+ } /* suppression of duplicates */
+
+ if (rec->presence_flags & WTAP_HAS_TS) {
+ /* suppress duplicates by time window */
+ if (dup_detect_by_time) {
+ nstime_t current;
+
+ current.secs = rec->ts.secs;
+ current.nsecs = rec->ts.nsecs;
+
+ if (is_duplicate_rel_time(buf,
+ rec->rec_header.packet_header.caplen,
+ ¤t)) {
if (verbose) {
fprintf(stderr, "Skipped: %u, Len: %u, MD5 Hash: ",
count,
fprintf(stderr, "\n");
}
}
- } /* suppression of duplicates */
-
- if (rec->presence_flags & WTAP_HAS_TS) {
- /* suppress duplicates by time window */
- if (dup_detect_by_time) {
- nstime_t current;
+ }
+ } /* suppress duplicates by time window */
+ }
- current.secs = rec->ts.secs;
- current.nsecs = rec->ts.nsecs;
-
- if (is_duplicate_rel_time(buf,
- rec->rec_header.packet_header.caplen,
- ¤t)) {
- if (verbose) {
- fprintf(stderr, "Skipped: %u, Len: %u, MD5 Hash: ",
- count,
- rec->rec_header.packet_header.caplen);
- for (i = 0; i < 16; i++)
- fprintf(stderr, "%02x",
- (unsigned char)fd_hash[cur_dup_entry].digest[i]);
- fprintf(stderr, "\n");
- }
- duplicate_count++;
- count++;
- continue;
- } else {
- if (verbose) {
- fprintf(stderr, "Packet: %u, Len: %u, MD5 Hash: ",
- count,
- rec->rec_header.packet_header.caplen);
- for (i = 0; i < 16; i++)
- fprintf(stderr, "%02x",
- (unsigned char)fd_hash[cur_dup_entry].digest[i]);
- fprintf(stderr, "\n");
- }
- }
- }
- } /* suppress duplicates by time window */
+ /* Random error mutation */
+ do_mutation = FALSE;
+ caplen = 0;
+ if (err_prob > 0.0) {
+ switch (rec->rec_type) {
+
+ case REC_TYPE_PACKET:
+ caplen = rec->rec_header.packet_header.caplen;
+ do_mutation = TRUE;
+ break;
+
+ case REC_TYPE_FT_SPECIFIC_EVENT:
+ case REC_TYPE_FT_SPECIFIC_REPORT:
+ caplen = rec->rec_header.ft_specific_header.record_len;
+ do_mutation = TRUE;
+ break;
+
+ case REC_TYPE_SYSCALL:
+ caplen = rec->rec_header.syscall_header.event_filelen;
+ do_mutation = TRUE;
+ break;
}
- /* Random error mutation */
- do_mutation = FALSE;
- caplen = 0;
- if (err_prob > 0.0) {
- switch (rec->rec_type) {
-
- case REC_TYPE_PACKET:
- caplen = rec->rec_header.packet_header.caplen;
- do_mutation = TRUE;
- break;
-
- case REC_TYPE_SYSCALL:
- caplen = rec->rec_header.syscall_header.event_filelen;
- do_mutation = TRUE;
- break;
- }
-
- if (change_offset > caplen) {
- fprintf(stderr, "change offset %u is longer than caplen %u in packet %u\n",
- change_offset, caplen, count);
- do_mutation = FALSE;
- }
+ if (change_offset > caplen) {
+ fprintf(stderr, "change offset %u is longer than caplen %u in packet %u\n",
+ change_offset, caplen, count);
+ do_mutation = FALSE;
}
+ }
- if (do_mutation) {
- int real_data_start = 0;
+ if (do_mutation) {
+ int real_data_start = 0;
- /* Protect non-protocol data */
- switch (rec->rec_type) {
+ /* Protect non-protocol data */
+ switch (rec->rec_type) {
- case REC_TYPE_PACKET:
- if (wtap_file_type_subtype(wth) == WTAP_FILE_TYPE_SUBTYPE_CATAPULT_DCT2000)
- real_data_start = find_dct2000_real_data(buf);
- break;
- }
+ case REC_TYPE_PACKET:
+ if (wtap_file_type_subtype(wth) == WTAP_FILE_TYPE_SUBTYPE_CATAPULT_DCT2000)
+ real_data_start = find_dct2000_real_data(buf);
+ break;
+ }
- real_data_start += change_offset;
+ real_data_start += change_offset;
- for (i = real_data_start; i < (int) caplen; i++) {
- if (rand() <= err_prob * RAND_MAX) {
- err_type = rand() / (RAND_MAX / ERR_WT_TOTAL + 1);
+ for (i = real_data_start; i < (int) caplen; i++) {
+ if (rand() <= err_prob * RAND_MAX) {
+ err_type = rand() / (RAND_MAX / ERR_WT_TOTAL + 1);
- if (err_type < ERR_WT_BIT) {
- buf[i] ^= 1 << (rand() / (RAND_MAX / 8 + 1));
- err_type = ERR_WT_TOTAL;
- } else {
- err_type -= ERR_WT_BYTE;
- }
+ if (err_type < ERR_WT_BIT) {
+ buf[i] ^= 1 << (rand() / (RAND_MAX / 8 + 1));
+ err_type = ERR_WT_TOTAL;
+ } else {
+ err_type -= ERR_WT_BYTE;
+ }
- if (err_type < ERR_WT_BYTE) {
- buf[i] = rand() / (RAND_MAX / 255 + 1);
- err_type = ERR_WT_TOTAL;
- } else {
- err_type -= ERR_WT_BYTE;
- }
+ if (err_type < ERR_WT_BYTE) {
+ buf[i] = rand() / (RAND_MAX / 255 + 1);
+ err_type = ERR_WT_TOTAL;
+ } else {
+ err_type -= ERR_WT_BYTE;
+ }
- if (err_type < ERR_WT_ALNUM) {
- buf[i] = ALNUM_CHARS[rand() / (RAND_MAX / ALNUM_LEN + 1)];
- err_type = ERR_WT_TOTAL;
- } else {
- err_type -= ERR_WT_ALNUM;
- }
+ if (err_type < ERR_WT_ALNUM) {
+ buf[i] = ALNUM_CHARS[rand() / (RAND_MAX / ALNUM_LEN + 1)];
+ err_type = ERR_WT_TOTAL;
+ } else {
+ err_type -= ERR_WT_ALNUM;
+ }
- if (err_type < ERR_WT_FMT) {
- if ((unsigned int)i < caplen - 2)
- g_strlcpy((char*) &buf[i], "%s", 2);
- err_type = ERR_WT_TOTAL;
- } else {
- err_type -= ERR_WT_FMT;
- }
+ if (err_type < ERR_WT_FMT) {
+ if ((unsigned int)i < caplen - 2)
+ g_strlcpy((char*) &buf[i], "%s", 2);
+ err_type = ERR_WT_TOTAL;
+ } else {
+ err_type -= ERR_WT_FMT;
+ }
- if (err_type < ERR_WT_AA) {
- for (j = i; j < (int) caplen; j++)
- buf[j] = 0xAA;
- i = caplen;
- }
+ if (err_type < ERR_WT_AA) {
+ for (j = i; j < (int) caplen; j++)
+ buf[j] = 0xAA;
+ i = caplen;
}
}
- } /* random error mutation */
-
- /* Find a packet comment we may need to write */
- if (frames_user_comments) {
- const char *comment =
- (const char*)g_tree_lookup(frames_user_comments, GUINT_TO_POINTER(read_count));
- /* XXX: What about comment changed to no comment? */
- if (comment != NULL) {
- /* Copy and change rather than modify returned rec */
- temp_rec = *rec;
- temp_rec.opt_comment = g_strdup(comment);
- temp_rec.has_comment_changed = TRUE;
- rec = &temp_rec;
- } else {
- /* Copy and change rather than modify returned rec */
- temp_rec = *rec;
- temp_rec.has_comment_changed = FALSE;
- rec = &temp_rec;
- }
}
-
- /* Attempt to dump out current frame to the output file */
- if (!wtap_dump(pdh, rec, buf, &write_err, &write_err_info)) {
- cfile_write_failure_message("editcap", argv[optind],
- filename,
- write_err, write_err_info,
- read_count,
- out_file_type_subtype);
- ret = DUMP_ERROR;
- goto clean_exit;
+ } /* random error mutation */
+
+ /* Find a packet comment we may need to write */
+ if (frames_user_comments) {
+ const char *comment =
+ (const char*)g_tree_lookup(frames_user_comments, GUINT_TO_POINTER(read_count));
+ /* XXX: What about comment changed to no comment? */
+ if (comment != NULL) {
+ /* Copy and change rather than modify returned rec */
+ temp_rec = *rec;
+ temp_rec.opt_comment = g_strdup(comment);
+ temp_rec.has_comment_changed = TRUE;
+ rec = &temp_rec;
+ } else {
+ /* Copy and change rather than modify returned rec */
+ temp_rec = *rec;
+ temp_rec.has_comment_changed = FALSE;
+ rec = &temp_rec;
}
- written_count++;
}
- count++;
- }
-
- g_free(fprefix);
- g_free(fsuffix);
-
- if (read_err != 0) {
- /* Print a message noting that the read failed somewhere along the
- * line. */
- cfile_read_failure_message("editcap", argv[optind], read_err,
- read_err_info);
- }
- if (!pdh) {
- /* No valid packages found, open the outfile so we can write an
- * empty header */
- g_free (filename);
- filename = g_strdup(argv[optind+1]);
-
- pdh = editcap_dump_open(filename,
- snaplen ? MIN(snaplen, wtap_snapshot_length(wth)): wtap_snapshot_length(wth),
- shb_hdrs, idb_inf, nrb_hdrs, &write_err);
- if (pdh == NULL) {
- cfile_dump_open_failure_message("editcap", filename,
- write_err,
- out_file_type_subtype);
- ret = INVALID_FILE;
+ /* Attempt to dump out current frame to the output file */
+ if (!wtap_dump(pdh, rec, buf, &write_err, &write_err_info)) {
+ cfile_write_failure_message("editcap", argv[optind],
+ filename,
+ write_err, write_err_info,
+ read_count,
+ out_file_type_subtype);
+ ret = DUMP_ERROR;
goto clean_exit;
}
+ written_count++;
}
+ count++;
+ }
+
+ g_free(fprefix);
+ g_free(fsuffix);
+
+ if (read_err != 0) {
+ /* Print a message noting that the read failed somewhere along the
+ * line. */
+ cfile_read_failure_message("editcap", argv[optind], read_err,
+ read_err_info);
+ }
- if (!wtap_dump_close(pdh, &write_err)) {
- cfile_close_failure_message(filename, write_err);
- ret = WRITE_ERROR;
+ if (!pdh) {
+ /* No valid packages found, open the outfile so we can write an
+ * empty header */
+ g_free (filename);
+ filename = g_strdup(argv[optind+1]);
+
+ pdh = editcap_dump_open(filename, ¶ms, &write_err);
+ if (pdh == NULL) {
+ cfile_dump_open_failure_message("editcap", filename,
+ write_err,
+ out_file_type_subtype);
+ ret = INVALID_FILE;
goto clean_exit;
}
- g_free(filename);
+ }
- if (frames_user_comments) {
- g_tree_destroy(frames_user_comments);
- }
+ if (!wtap_dump_close(pdh, &write_err)) {
+ cfile_close_failure_message(filename, write_err);
+ ret = WRITE_ERROR;
+ goto clean_exit;
+ }
+ g_free(filename);
+
+ if (frames_user_comments) {
+ g_tree_destroy(frames_user_comments);
}
if (dup_detect) {
}
clean_exit:
- wtap_block_array_free(shb_hdrs);
- wtap_block_array_free(nrb_hdrs);
- g_free(idb_inf);
+ if (dsb_filenames) {
+ g_array_free(dsb_types, TRUE);
+ g_ptr_array_free(dsb_filenames, TRUE);
+ }
+ g_free(params.idb_inf);
+ wtap_dump_params_cleanup(¶ms);
if (wth != NULL)
wtap_close(wth);
wtap_cleanup();