diff --git a/capinfos.c b/capinfos.c index 5f227e6afe..bed9cfe2a8 100644 --- a/capinfos.c +++ b/capinfos.c @@ -177,41 +177,41 @@ typedef enum { } order_t; typedef struct _capture_info { - const char *filename; - guint16 file_type; - gboolean iscompressed; - int file_encap; - int file_tsprec; - gint64 filesize; - wtap_block_t shb; - guint64 packet_bytes; - gboolean times_known; - nstime_t start_time; - int start_time_tsprec; - nstime_t stop_time; - int stop_time_tsprec; - guint32 packet_count; - gboolean snap_set; /* If set in capture file header */ - guint32 snaplen; /* value from the capture file header */ - guint32 snaplen_min_inferred; /* If caplen < len for 1 or more rcds */ - guint32 snaplen_max_inferred; /* ... */ - gboolean drops_known; - guint32 drop_count; + const char *filename; + guint16 file_type; + wtap_compression_type compression_type; + int file_encap; + int file_tsprec; + gint64 filesize; + wtap_block_t shb; + guint64 packet_bytes; + gboolean times_known; + nstime_t start_time; + int start_time_tsprec; + nstime_t stop_time; + int stop_time_tsprec; + guint32 packet_count; + gboolean snap_set; /* If set in capture file header */ + guint32 snaplen; /* value from the capture file header */ + guint32 snaplen_min_inferred; /* If caplen < len for 1 or more rcds */ + guint32 snaplen_max_inferred; /* ... */ + gboolean drops_known; + guint32 drop_count; - nstime_t duration; - int duration_tsprec; - double packet_rate; - double packet_size; - double data_rate; /* in bytes */ - gboolean know_order; - order_t order; + nstime_t duration; + int duration_tsprec; + double packet_rate; + double packet_size; + double data_rate; /* in bytes/s */ + gboolean know_order; + order_t order; - int *encap_counts; /* array of per_packet encap counts; array has one entry per wtap_encap type */ + int *encap_counts; /* array of per_packet encap counts; array has one entry per wtap_encap type */ - guint num_interfaces; /* number of IDBs, and thus size of interface_packet_counts array */ - GArray *interface_packet_counts; /* array of per_packet interface_id counts; one entry per file IDB */ - guint32 pkt_interface_id_unknown; /* counts if packet interface_id didn't match a known one */ - GArray *idb_info_strings; /* array of IDB info strings */ + guint num_interfaces; /* number of IDBs, and thus size of interface_packet_counts array */ + GArray *interface_packet_counts; /* array of per_packet interface_id counts; one entry per file IDB */ + guint32 pkt_interface_id_unknown; /* counts if packet interface_id didn't match a known one */ + GArray *idb_info_strings; /* array of IDB info strings */ } capture_info; static char *decimal_point; @@ -585,7 +585,7 @@ print_stats(const gchar *filename, capture_info *cf_info) if (filename) printf ("File name: %s\n", filename); if (cap_file_type) printf ("File type: %s%s\n", file_type_string, - cf_info->iscompressed ? " (gzip compressed)" : ""); + cf_info->compression_type == WTAP_GZIP_COMPRESSED ? " (gzip compressed)" : ""); if (cap_file_encap) { printf ("File encapsulation: %s\n", file_encap_string); @@ -1241,7 +1241,7 @@ process_cap_file(wtap *wth, const char *filename) /* File Type */ cf_info.file_type = wtap_file_type_subtype(wth); - cf_info.iscompressed = wtap_iscompressed(wth); + cf_info.compression_type = wtap_get_compression_type(wth); /* File Encapsulation */ cf_info.file_encap = wtap_file_encap(wth); diff --git a/cfile.h b/cfile.h index cbe54b1562..3c9296ba43 100644 --- a/cfile.h +++ b/cfile.h @@ -63,67 +63,67 @@ struct packet_provider_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 */ - gboolean iscompressed; /* TRUE if the file is compressed */ - 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. */ + 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 N/B */ + 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 N/B */ /* packet data */ - wtap_rec rec; /* Record header */ - Buffer buf; /* Record data */ + wtap_rec rec; /* Record header */ + Buffer buf; /* Record data */ /* 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 */ - column_info cinfo; /* Column formatting information */ - frame_data *current_frame; /* Frame data for current frame */ - gint current_row; /* Row number for current frame */ - 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 */ - gulong computed_elapsed; /* Elapsed time to load the file (in msec). */ + guint32 first_displayed; /* Frame number of first frame displayed */ + guint32 last_displayed; /* Frame number of last frame displayed */ + column_info cinfo; /* Column formatting information */ + frame_data *current_frame; /* Frame data for current frame */ + gint current_row; /* Row number for current frame */ + 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 */ + 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); diff --git a/debian/libwiretap0.symbols b/debian/libwiretap0.symbols index 2751097de8..d7283fbd10 100644 --- a/debian/libwiretap0.symbols +++ b/debian/libwiretap0.symbols @@ -98,6 +98,7 @@ libwiretap.so.0 libwiretap0 #MINVER# wtap_get_all_file_extensions_list@Base 2.6.2 wtap_get_buf_ptr@Base 2.5.1 wtap_get_bytes_dumped@Base 1.9.1 + wtap_get_compression_type@Base 2.9.0 wtap_get_debug_if_descr@Base 1.99.9 wtap_get_file_extension_type_extensions@Base 1.12.0~rc1 wtap_get_file_extension_type_name@Base 1.12.0~rc1 @@ -110,7 +111,6 @@ libwiretap.so.0 libwiretap0 #MINVER# wtap_has_open_info@Base 1.12.0~rc1 wtap_init@Base 2.3.0 wtap_cleanup@Base 2.3.0 - wtap_iscompressed@Base 1.9.1 wtap_open_offline@Base 1.9.1 wtap_opttype_register_custom_block_type@Base 2.1.2 wtap_opttypes_initialize@Base 2.1.2 diff --git a/editcap.c b/editcap.c index ed11641071..18523a1c23 100644 --- a/editcap.c +++ b/editcap.c @@ -942,12 +942,10 @@ editcap_dump_open(const char *filename, const wtap_dump_params *params, if (strcmp(filename, "-") == 0) { /* Write to the standard output. */ - pdh = wtap_dump_open_stdout(out_file_type_subtype, - FALSE /* compressed */, + pdh = wtap_dump_open_stdout(out_file_type_subtype, WTAP_UNCOMPRESSED, params, write_err); } else { - pdh = wtap_dump_open(filename, out_file_type_subtype, - FALSE /* compressed */, + pdh = wtap_dump_open(filename, out_file_type_subtype, WTAP_UNCOMPRESSED, params, write_err); } return pdh; diff --git a/epan/dissectors/packet-snort.c b/epan/dissectors/packet-snort.c index d868defec4..a360aff48c 100644 --- a/epan/dissectors/packet-snort.c +++ b/epan/dissectors/packet-snort.c @@ -1168,7 +1168,7 @@ snort_dissector(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data params.snaplen = WTAP_MAX_PACKET_SIZE_STANDARD; current_session.pdh = wtap_dump_fdopen(current_session.in, WTAP_FILE_TYPE_SUBTYPE_PCAP, - FALSE, /* compressed */ + WTAP_UNCOMPRESSED, ¶ms, &open_err); if (!current_session.pdh) { diff --git a/epan/wslua/wslua_capture_info.c b/epan/wslua/wslua_capture_info.c index 996b313d1b..bf62a844ae 100644 --- a/epan/wslua/wslua_capture_info.c +++ b/epan/wslua/wslua_capture_info.c @@ -337,8 +337,8 @@ WSLUA_METAMETHOD CaptureInfoConst__tostring(lua_State* L) { lua_pushstring(L,"CaptureInfoConst pointer is NULL!"); } else { wtap_dumper *wdh = fi->wdh; - lua_pushfstring(L, "CaptureInfoConst: file_type_subtype=%d, snaplen=%d, encap=%d, compressed=%d", - wdh->file_type_subtype, wdh->snaplen, wdh->encap, wdh->compressed); + lua_pushfstring(L, "CaptureInfoConst: file_type_subtype=%d, snaplen=%d, encap=%d, compression_type=%d", + wdh->file_type_subtype, wdh->snaplen, wdh->encap, wdh->compression_type); } WSLUA_RETURN(1); /* String of debug information. */ diff --git a/epan/wslua/wslua_dumper.c b/epan/wslua/wslua_dumper.c index 2e738e4225..00779d3a6f 100644 --- a/epan/wslua/wslua_dumper.c +++ b/epan/wslua/wslua_dumper.c @@ -208,7 +208,7 @@ WSLUA_CONSTRUCTOR Dumper_new(lua_State* L) { wtap_dump_params params = WTAP_DUMP_PARAMS_INIT; params.encap = encap; - d = wtap_dump_open(filename, filetype, FALSE, ¶ms, &err); + d = wtap_dump_open(filename, filetype, WTAP_UNCOMPRESSED, ¶ms, &err); if (! d ) { /* WSLUA_ERROR("Error while opening file for writing"); */ @@ -372,7 +372,7 @@ WSLUA_METHOD Dumper_new_for_current(lua_State* L) { encap = lua_pinfo->rec->rec_header.packet_header.pkt_encap; params.encap = encap; - d = wtap_dump_open(filename, filetype, FALSE, ¶ms, &err); + d = wtap_dump_open(filename, filetype, WTAP_UNCOMPRESSED, ¶ms, &err); if (! d ) { switch (err) { diff --git a/epan/wslua/wslua_file.c b/epan/wslua/wslua_file.c index 4c43a95a2f..5beaafa9b2 100644 --- a/epan/wslua/wslua_file.c +++ b/epan/wslua/wslua_file.c @@ -477,7 +477,7 @@ static int File_get_compressed(lua_State* L) { if (file_is_reader(f)) { lua_pushboolean(L, file_iscompressed(f->file)); } else { - lua_pushboolean(L, f->wdh->compressed); + lua_pushboolean(L, f->wdh->compression_type != WTAP_UNCOMPRESSED); } return 1; } diff --git a/extcap/androiddump.c b/extcap/androiddump.c index e782908a27..4a3a8870a5 100644 --- a/extcap/androiddump.c +++ b/extcap/androiddump.c @@ -450,7 +450,7 @@ static struct extcap_dumper extcap_dumper_open(char *fifo, int encap) { params.encap = encap; params.snaplen = PACKET_LENGTH; - extcap_dumper.dumper.wtap = wtap_dump_open(fifo, WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC, FALSE, ¶ms, &err); + extcap_dumper.dumper.wtap = wtap_dump_open(fifo, WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC, WTAP_UNCOMPRESSED, ¶ms, &err); if (!extcap_dumper.dumper.wtap) { cfile_dump_open_failure_message("androiddump", fifo, err, WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC); exit(EXIT_CODE_CANNOT_SAVE_WIRETAP_DUMP); diff --git a/file.c b/file.c index 10a4507ed6..0b55344982 100644 --- a/file.c +++ b/file.c @@ -547,9 +547,9 @@ cf_read(capture_file *cf, gboolean reloading) else cf_callback_invoke(cf_cb_file_read_started, cf); - /* Record whether the file is compressed. + /* Record the file's compression type. XXX - do we know this at open time? */ - cf->iscompressed = wtap_iscompressed(cf->provider.wth); + cf->compression_type = wtap_get_compression_type(cf->provider.wth); /* The packet list window will be empty until the file is completly loaded */ packet_list_freeze(); @@ -4228,9 +4228,9 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile) cf_callback_invoke(cf_cb_file_rescan_started, cf); - /* Record whether the file is compressed. + /* Record the file's compression type. XXX - do we know this at open time? */ - cf->iscompressed = wtap_iscompressed(cf->provider.wth); + cf->compression_type = wtap_get_compression_type(cf->provider.wth); /* Find the size of the file. */ size = wtap_file_size(cf->provider.wth, NULL); @@ -4333,8 +4333,8 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile) cf_write_status_t cf_save_records(capture_file *cf, const char *fname, guint save_format, - gboolean compressed, gboolean discard_comments, - gboolean dont_reopen) + wtap_compression_type compression_type, + gboolean discard_comments, gboolean dont_reopen) { gchar *err_info; gchar *fname_new = NULL; @@ -4364,7 +4364,7 @@ cf_save_records(capture_file *cf, const char *fname, guint save_format, addr_lists = get_addrinfo_list(); - if (save_format == cf->cd_t && compressed == cf->iscompressed + if (save_format == cf->cd_t && compression_type == cf->compression_type && !discard_comments && !cf->unsaved_changes && (wtap_addrinfo_list_empty(addr_lists) || !wtap_dump_has_name_resolution(save_format))) { /* We're saving in the format it's already in, and we're not discarding @@ -4470,9 +4470,10 @@ cf_save_records(capture_file *cf, const char *fname, guint save_format, we *HAVE* to do that, otherwise we're overwriting the file from which we're reading the packets that we're writing!) */ fname_new = g_strdup_printf("%s~", fname); - pdh = wtap_dump_open(fname_new, save_format, compressed, ¶ms, &err); + pdh = wtap_dump_open(fname_new, save_format, compression_type, ¶ms, + &err); } else { - pdh = wtap_dump_open(fname, save_format, compressed, ¶ms, &err); + pdh = wtap_dump_open(fname, save_format, compression_type, ¶ms, &err); } /* XXX idb_inf is documented to be used until wtap_dump_close. */ g_free(params.idb_inf); @@ -4691,7 +4692,7 @@ fail: cf_write_status_t cf_export_specified_packets(capture_file *cf, const char *fname, packet_range_t *range, guint save_format, - gboolean compressed) + wtap_compression_type compression_type) { gchar *fname_new = NULL; int err; @@ -4726,9 +4727,10 @@ cf_export_specified_packets(capture_file *cf, const char *fname, we *HAVE* to do that, otherwise we're overwriting the file from which we're reading the packets that we're writing!) */ fname_new = g_strdup_printf("%s~", fname); - pdh = wtap_dump_open(fname_new, save_format, compressed, ¶ms, &err); + pdh = wtap_dump_open(fname_new, save_format, compression_type, ¶ms, + &err); } else { - pdh = wtap_dump_open(fname, save_format, compressed, ¶ms, &err); + pdh = wtap_dump_open(fname, save_format, compression_type, ¶ms, &err); } /* XXX idb_inf is documented to be used until wtap_dump_close. */ g_free(params.idb_inf); diff --git a/file.h b/file.h index 090528654b..2e0d78704b 100644 --- a/file.h +++ b/file.h @@ -234,7 +234,7 @@ gboolean cf_has_unsaved_data(capture_file *cf); * @param cf the capture file to save to * @param fname the filename to save to * @param save_format the format of the file to save (libpcap, ...) - * @param compressed whether to gzip compress the file + * @param compression_type type of compression to use when writing, if any * @param discard_comments TRUE if we should discard comments if the save * succeeds (because we saved in a format that doesn't support * comments) @@ -243,7 +243,8 @@ gboolean cf_has_unsaved_data(capture_file *cf); * @return one of cf_write_status_t */ cf_write_status_t cf_save_records(capture_file * cf, const char *fname, - guint save_format, gboolean compressed, + guint save_format, + wtap_compression_type compression_type, gboolean discard_comments, gboolean dont_reopen); @@ -258,14 +259,14 @@ cf_write_status_t cf_save_records(capture_file * cf, const char *fname, * @param fname the filename to write to * @param range the range of packets to write * @param save_format the format of the file to write (libpcap, ...) - * @param compressed whether to gzip compress the file + * @param compression_type type of compression to use when writing, if any * @return one of cf_write_status_t */ cf_write_status_t cf_export_specified_packets(capture_file *cf, const char *fname, packet_range_t *range, guint save_format, - gboolean compressed); + wtap_compression_type compression_type); /** * Get a displayable name of the capture file. diff --git a/randpkt_core/randpkt_core.c b/randpkt_core/randpkt_core.c index 7b1822b76f..69d1c822df 100644 --- a/randpkt_core/randpkt_core.c +++ b/randpkt_core/randpkt_core.c @@ -667,13 +667,11 @@ int randpkt_example_init(randpkt_example* example, char* produce_filename, int p if (strcmp(produce_filename, "-") == 0) { /* Write to the standard output. */ example->dump = wtap_dump_open_stdout(WTAP_FILE_TYPE_SUBTYPE_PCAP, - FALSE /* compressed */, - ¶ms, &err); + WTAP_UNCOMPRESSED, ¶ms, &err); example->filename = "the standard output"; } else { example->dump = wtap_dump_open(produce_filename, WTAP_FILE_TYPE_SUBTYPE_PCAP, - FALSE /* compressed */, - ¶ms, &err); + WTAP_UNCOMPRESSED, ¶ms, &err); example->filename = produce_filename; } if (!example->dump) { diff --git a/reordercap.c b/reordercap.c index 90c57f7ac1..93e2d1bb8d 100644 --- a/reordercap.c +++ b/reordercap.c @@ -287,9 +287,9 @@ main(int argc, char *argv[]) /* Open outfile (same filetype/encap as input file) */ if (strcmp(outfile, "-") == 0) { - pdh = wtap_dump_open_stdout(wtap_file_type_subtype(wth), FALSE, ¶ms, &err); + pdh = wtap_dump_open_stdout(wtap_file_type_subtype(wth), WTAP_UNCOMPRESSED, ¶ms, &err); } else { - pdh = wtap_dump_open(outfile, wtap_file_type_subtype(wth), FALSE, ¶ms, &err); + pdh = wtap_dump_open(outfile, wtap_file_type_subtype(wth), WTAP_UNCOMPRESSED, ¶ms, &err); } g_free(params.idb_inf); params.idb_inf = NULL; diff --git a/tshark.c b/tshark.c index f7055c5aee..9dee6a9933 100644 --- a/tshark.c +++ b/tshark.c @@ -3115,11 +3115,11 @@ process_cap_file(capture_file *cf, char *save_file, int out_file_type, tshark_debug("tshark: writing format type %d, to %s", out_file_type, save_file); if (strcmp(save_file, "-") == 0) { /* Write to the standard output. */ - pdh = wtap_dump_open_stdout(out_file_type, FALSE /* compressed */, - ¶ms, &err); + pdh = wtap_dump_open_stdout(out_file_type, WTAP_UNCOMPRESSED, ¶ms, + &err); } else { - pdh = wtap_dump_open(save_file, out_file_type, FALSE /* compressed */, - ¶ms, &err); + pdh = wtap_dump_open(save_file, out_file_type, WTAP_UNCOMPRESSED, ¶ms, + &err); } g_free(params.idb_inf); diff --git a/ui/qt/capture_file_dialog.cpp b/ui/qt/capture_file_dialog.cpp index 6e8569dacc..f6bf201977 100644 --- a/ui/qt/capture_file_dialog.cpp +++ b/ui/qt/capture_file_dialog.cpp @@ -247,8 +247,8 @@ int CaptureFileDialog::selectedFileType() { return file_type_; } -bool CaptureFileDialog::isCompressed() { - return compressed_; +wtap_compression_type CaptureFileDialog::compressionType() { + return compression_type_; } int CaptureFileDialog::open(QString &file_name, unsigned int &type) { @@ -271,7 +271,7 @@ check_savability_t CaptureFileDialog::saveAs(QString &file_name, bool must_suppo GString *fname = g_string_new(file_name.toUtf8().constData()); gboolean wsf_status; - wsf_status = win32_save_as_file((HWND)parentWidget()->effectiveWinId(), cap_file_, fname, &file_type_, &compressed_, must_support_all_comments); + wsf_status = win32_save_as_file((HWND)parentWidget()->effectiveWinId(), cap_file_, fname, &file_type_, &compression_type_, must_support_all_comments); file_name = fname->str; g_string_free(fname, TRUE); @@ -287,7 +287,7 @@ check_savability_t CaptureFileDialog::exportSelectedPackets(QString &file_name, GString *fname = g_string_new(file_name.toUtf8().constData()); gboolean wespf_status; - wespf_status = win32_export_specified_packets_file((HWND)parentWidget()->effectiveWinId(), cap_file_, fname, &file_type_, &compressed_, range); + wespf_status = win32_export_specified_packets_file((HWND)parentWidget()->effectiveWinId(), cap_file_, fname, &file_type_, &compression_type_, range); file_name = fname->str; g_string_free(fname, TRUE); @@ -493,9 +493,9 @@ void CaptureFileDialog::fixFilenameExtension() } // Fixup the new suffix based on compression availability. - if (!isCompressed() && new_suffix.endsWith(".gz")) { + if (compressionType() != WTAP_GZIP_COMPRESSED && new_suffix.endsWith(".gz")) { new_suffix.chop(3); - } else if (isCompressed() && valid_extensions.contains(new_suffix + ".gz")) { + } else if (compressionType() == WTAP_GZIP_COMPRESSED && valid_extensions.contains(new_suffix + ".gz")) { new_suffix += ".gz"; } @@ -559,8 +559,8 @@ int CaptureFileDialog::selectedFileType() { return type_hash_.value(selectedNameFilter(), -1); } -bool CaptureFileDialog::isCompressed() { - return compress_.isChecked(); +wtap_compression_type CaptureFileDialog::compressionType() { + return compress_.isChecked() ? WTAP_GZIP_COMPRESSED : WTAP_UNCOMPRESSED; } void CaptureFileDialog::addDisplayFilterEdit() { @@ -585,7 +585,8 @@ void CaptureFileDialog::addFormatTypeSelector(QVBoxLayout &v_box) { void CaptureFileDialog::addGzipControls(QVBoxLayout &v_box) { compress_.setText(tr("Compress with g&zip")); - if (cap_file_->iscompressed && wtap_dump_can_compress(default_ft_)) { + if (cap_file_->compression_type == WTAP_GZIP_COMPRESSED && + wtap_dump_can_compress(default_ft_)) { compress_.setChecked(true); } else { compress_.setChecked(false); diff --git a/ui/qt/capture_file_dialog.h b/ui/qt/capture_file_dialog.h index 3ef4f02e51..f9bd637b33 100644 --- a/ui/qt/capture_file_dialog.h +++ b/ui/qt/capture_file_dialog.h @@ -68,7 +68,7 @@ public: int mergeType(); int selectedFileType(); - bool isCompressed(); + wtap_compression_type compressionType(); private: capture_file *cap_file_; @@ -119,7 +119,7 @@ private: #else // Q_OS_WIN int file_type_; int merge_type_; - gboolean compressed_; + wtap_compression_type compression_type_; #endif // Q_OS_WIN signals: diff --git a/ui/qt/capture_file_properties_dialog.cpp b/ui/qt/capture_file_properties_dialog.cpp index 3b09256d34..a1fb3df5ca 100644 --- a/ui/qt/capture_file_properties_dialog.cpp +++ b/ui/qt/capture_file_properties_dialog.cpp @@ -177,7 +177,7 @@ QString CaptureFilePropertiesDialog::summaryToHtml() << table_row_end; QString format_str = wtap_file_type_subtype_string(summary.file_type); - if (summary.iscompressed) { + if (summary.compression_type == WTAP_GZIP_COMPRESSED) { format_str.append(tr(" (gzip compressed)")); } out << table_row_begin diff --git a/ui/qt/gsm_map_summary_dialog.cpp b/ui/qt/gsm_map_summary_dialog.cpp index e53630e7c7..ecc6be98c2 100644 --- a/ui/qt/gsm_map_summary_dialog.cpp +++ b/ui/qt/gsm_map_summary_dialog.cpp @@ -107,7 +107,7 @@ QString GsmMapSummaryDialog::summaryToHtml() << table_row_end; QString format_str = wtap_file_type_subtype_string(summary.file_type); - if (summary.iscompressed) { + if (summary.compression_type == WTAP_GZIP_COMPRESSED) { format_str.append(tr(" (gzip compressed)")); } out << table_row_begin diff --git a/ui/qt/import_text_dialog.cpp b/ui/qt/import_text_dialog.cpp index 46e158c167..e9b239cd2a 100644 --- a/ui/qt/import_text_dialog.cpp +++ b/ui/qt/import_text_dialog.cpp @@ -125,7 +125,7 @@ void ImportTextDialog::convertTextFile() { params.encap = import_info_.encapsulation; params.snaplen = import_info_.max_frame_length; /* Use a random name for the temporary import buffer */ - import_info_.wdh = wtap_dump_open_tempfile(&tmpname, "import", WTAP_FILE_TYPE_SUBTYPE_PCAP, FALSE, ¶ms, &err); + import_info_.wdh = wtap_dump_open_tempfile(&tmpname, "import", WTAP_FILE_TYPE_SUBTYPE_PCAP, WTAP_UNCOMPRESSED, ¶ms, &err); capfile_name_.append(tmpname ? tmpname : "temporary file"); qDebug() << capfile_name_ << ":" << import_info_.wdh << import_info_.encapsulation << import_info_.max_frame_length; if (import_info_.wdh == NULL) { diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp index 0ee26d005d..bd99da6f3c 100644 --- a/ui/qt/main_window.cpp +++ b/ui/qt/main_window.cpp @@ -1364,7 +1364,7 @@ bool MainWindow::saveCaptureFile(capture_file *cf, bool dont_reopen) { closes the current file and then opens and reloads the saved file, so make a copy and free it later. */ file_name = cf->filename; - status = cf_save_records(cf, qUtf8Printable(file_name), cf->cd_t, cf->iscompressed, + status = cf_save_records(cf, qUtf8Printable(file_name), cf->cd_t, cf->compression_type, discard_comments, dont_reopen); switch (status) { @@ -1400,7 +1400,7 @@ bool MainWindow::saveCaptureFile(capture_file *cf, bool dont_reopen) { bool MainWindow::saveAsCaptureFile(capture_file *cf, bool must_support_comments, bool dont_reopen) { QString file_name = ""; int file_type; - gboolean compressed; + wtap_compression_type compression_type; cf_write_status_t status; gchar *dirname; gboolean discard_comments = FALSE; @@ -1447,11 +1447,11 @@ bool MainWindow::saveAsCaptureFile(capture_file *cf, bool must_support_comments, return false; } file_type = save_as_dlg.selectedFileType(); - compressed = save_as_dlg.isCompressed(); + compression_type = save_as_dlg.compressionType(); #ifdef Q_OS_WIN // the Windows dialog does not fixup extensions, do it manually here. - fileAddExtension(file_name, file_type, compressed); + fileAddExtension(file_name, file_type, compression_type); #endif // Q_OS_WIN //#ifndef _WIN32 @@ -1464,7 +1464,7 @@ bool MainWindow::saveAsCaptureFile(capture_file *cf, bool must_support_comments, //#endif /* Attempt to save the file */ - status = cf_save_records(cf, qUtf8Printable(file_name), file_type, compressed, + status = cf_save_records(cf, qUtf8Printable(file_name), file_type, compression_type, discard_comments, dont_reopen); switch (status) { @@ -1500,7 +1500,7 @@ bool MainWindow::saveAsCaptureFile(capture_file *cf, bool must_support_comments, void MainWindow::exportSelectedPackets() { QString file_name = ""; int file_type; - gboolean compressed; + wtap_compression_type compression_type; packet_range_t range; cf_write_status_t status; gchar *dirname; @@ -1574,10 +1574,10 @@ void MainWindow::exportSelectedPackets() { } file_type = esp_dlg.selectedFileType(); - compressed = esp_dlg.isCompressed(); + compression_type = esp_dlg.compressionType(); #ifdef Q_OS_WIN // the Windows dialog does not fixup extensions, do it manually here. - fileAddExtension(file_name, file_type, compressed); + fileAddExtension(file_name, file_type, compression_type); #endif // Q_OS_WIN //#ifndef _WIN32 @@ -1590,7 +1590,7 @@ void MainWindow::exportSelectedPackets() { //#endif /* Attempt to save the file */ - status = cf_export_specified_packets(capture_file_.capFile(), qUtf8Printable(file_name), &range, file_type, compressed); + status = cf_export_specified_packets(capture_file_.capFile(), qUtf8Printable(file_name), &range, file_type, compression_type); switch (status) { case CF_WRITE_OK: @@ -1630,7 +1630,7 @@ void MainWindow::exportDissections(export_type_e export_type) { } #ifdef Q_OS_WIN -void MainWindow::fileAddExtension(QString &file_name, int file_type, bool compressed) { +void MainWindow::fileAddExtension(QString &file_name, int file_type, wtap_compression_type compression_type) { QString file_name_lower; GSList *extensions_list; gboolean add_extension; @@ -1678,7 +1678,7 @@ void MainWindow::fileAddExtension(QString &file_name, int file_type, bool compre if (add_extension) { if (wtap_default_file_extension(file_type) != NULL) { file_name += tr(".") + wtap_default_file_extension(file_type); - if (compressed) { + if (compression_type == WTAP_GZIP_COMPRESSED) { file_name += ".gz"; } } diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h index de1e8f911f..4112d1ba78 100644 --- a/ui/qt/main_window.h +++ b/ui/qt/main_window.h @@ -241,7 +241,7 @@ private: void exportDissections(export_type_e export_type); #ifdef Q_OS_WIN - void fileAddExtension(QString &file_name, int file_type, bool compressed); + void fileAddExtension(QString &file_name, int file_type, wtap_compression_type compression_type); #endif // Q_OS_WIN bool testCaptureFileClose(QString before_what, FileCloseContext context = Default); void captureStop(); diff --git a/ui/qt/mtp3_summary_dialog.cpp b/ui/qt/mtp3_summary_dialog.cpp index 81af57ef2d..412a0cb82f 100644 --- a/ui/qt/mtp3_summary_dialog.cpp +++ b/ui/qt/mtp3_summary_dialog.cpp @@ -111,7 +111,7 @@ QString Mtp3SummaryDialog::summaryToHtml() << table_row_end; QString format_str = wtap_file_type_subtype_string(summary.file_type); - if (summary.iscompressed) { + if (summary.compression_type == WTAP_GZIP_COMPRESSED) { format_str.append(tr(" (gzip compressed)")); } out << table_row_begin diff --git a/ui/summary.c b/ui/summary.c index e3d73f3f9e..3eb02fe755 100644 --- a/ui/summary.c +++ b/ui/summary.c @@ -155,7 +155,7 @@ summary_fill_in(capture_file *cf, summary_tally *st) st->filename = cf->filename; st->file_length = cf->f_datalen; st->file_type = cf->cd_t; - st->iscompressed = cf->iscompressed; + st->compression_type = cf->compression_type; st->is_tempfile = cf->is_tempfile; st->file_encap_type = cf->lnk_t; st->packet_encap_types = cf->linktypes; diff --git a/ui/summary.h b/ui/summary.h index ebf8e5cb8a..9c345944eb 100644 --- a/ui/summary.h +++ b/ui/summary.h @@ -33,42 +33,42 @@ typedef struct iface_summary_info_tag { #define HASH_STR_SIZE (65) /* Max hash size * 2 + '\0' */ typedef struct _summary_tally { - guint64 bytes; /**< total bytes */ - double start_time; /**< seconds, with msec resolution */ - double stop_time; /**< seconds, with msec resolution */ - double elapsed_time; /**< seconds, with msec resolution, - includes time before first packet - and after last packet */ - guint32 marked_count; /**< number of marked packets */ - guint32 marked_count_ts; /**< number of time-stamped marked packets */ - guint64 marked_bytes; /**< total bytes in the marked packets */ - double marked_start; /**< time in seconds, with msec resolution */ - double marked_stop; /**< time in seconds, with msec resolution */ - guint32 ignored_count; /**< number of ignored packets */ - guint32 packet_count; /**< total number of packets in trace */ - guint32 packet_count_ts; /**< total number of time-stamped packets in trace */ - guint32 filtered_count; /**< number of filtered packets */ - guint32 filtered_count_ts; /**< number of time-stamped filtered packets */ - guint64 filtered_bytes; /**< total bytes in the filtered packets */ - double filtered_start; /**< time in seconds, with msec resolution */ - double filtered_stop; /**< time in seconds, with msec resolution */ - const char *filename; /**< path of capture file */ - gint64 file_length; /**< file length in bytes */ - gchar file_sha256[HASH_STR_SIZE]; /**< SHA256 hash of capture file */ - gchar file_rmd160[HASH_STR_SIZE]; /**< RIPEMD160 hash of capture file */ - gchar file_sha1[HASH_STR_SIZE]; /**< SHA1 hash of capture file */ - int file_type; /**< wiretap file type */ - int iscompressed; /**< TRUE if file is compressed */ - int file_encap_type; /**< wiretap encapsulation type for file */ - GArray *packet_encap_types; /**< wiretap encapsulation types for packets */ - int snap; /**< Maximum captured packet length; 0 if not known */ - gboolean drops_known; /**< TRUE if number of packet drops is known */ - guint64 drops; /**< number of packet drops */ - const char *dfilter; /**< display filter */ - gboolean is_tempfile; + guint64 bytes; /**< total bytes */ + double start_time; /**< seconds, with msec resolution */ + double stop_time; /**< seconds, with msec resolution */ + double elapsed_time; /**< seconds, with msec resolution, + includes time before first packet + and after last packet */ + guint32 marked_count; /**< number of marked packets */ + guint32 marked_count_ts; /**< number of time-stamped marked packets */ + guint64 marked_bytes; /**< total bytes in the marked packets */ + double marked_start; /**< time in seconds, with msec resolution */ + double marked_stop; /**< time in seconds, with msec resolution */ + guint32 ignored_count; /**< number of ignored packets */ + guint32 packet_count; /**< total number of packets in trace */ + guint32 packet_count_ts; /**< total number of time-stamped packets in trace */ + guint32 filtered_count; /**< number of filtered packets */ + guint32 filtered_count_ts; /**< number of time-stamped filtered packets */ + guint64 filtered_bytes; /**< total bytes in the filtered packets */ + double filtered_start; /**< time in seconds, with msec resolution */ + double filtered_stop; /**< time in seconds, with msec resolution */ + const char *filename; /**< path of capture file */ + gint64 file_length; /**< file length in bytes */ + gchar file_sha256[HASH_STR_SIZE]; /**< SHA256 hash of capture file */ + gchar file_rmd160[HASH_STR_SIZE]; /**< RIPEMD160 hash of capture file */ + gchar file_sha1[HASH_STR_SIZE]; /**< SHA1 hash of capture file */ + int file_type; /**< wiretap file type */ + wtap_compression_type compression_type; /**< compression type of file, or uncompressed */ + int file_encap_type; /**< wiretap encapsulation type for file */ + GArray *packet_encap_types; /**< wiretap encapsulation types for packets */ + int snap; /**< Maximum captured packet length; 0 if not known */ + gboolean drops_known; /**< TRUE if number of packet drops is known */ + guint64 drops; /**< number of packet drops */ + const char *dfilter; /**< display filter */ + gboolean is_tempfile; /* capture related, use summary_fill_in_capture() to get values */ - GArray *ifaces; - gboolean legacy; + GArray *ifaces; + gboolean legacy; } summary_tally; extern void diff --git a/ui/tap_export_pdu.c b/ui/tap_export_pdu.c index 5e6590b72d..5b8165de70 100644 --- a/ui/tap_export_pdu.c +++ b/ui/tap_export_pdu.c @@ -148,10 +148,10 @@ exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, char *comment) }; if (fd == 1) { exp_pdu_tap_data->wdh = wtap_dump_open_stdout(WTAP_FILE_TYPE_SUBTYPE_PCAPNG, - FALSE, ¶ms, &err); + WTAP_UNCOMPRESSED, ¶ms, &err); } else { exp_pdu_tap_data->wdh = wtap_dump_fdopen(fd, WTAP_FILE_TYPE_SUBTYPE_PCAPNG, - FALSE, ¶ms, &err); + WTAP_UNCOMPRESSED, ¶ms, &err); } if (exp_pdu_tap_data->wdh == NULL) { g_assert(err != 0); diff --git a/ui/win32/file_dlg_win32.c b/ui/win32/file_dlg_win32.c index d316096b1a..8606ee5c5f 100644 --- a/ui/win32/file_dlg_win32.c +++ b/ui/win32/file_dlg_win32.c @@ -315,7 +315,8 @@ win32_check_save_as_with_comments(HWND parent, capture_file *cf, int file_type) gboolean win32_save_as_file(HWND h_wnd, capture_file *cf, GString *file_name, int *file_type, - gboolean *compressed, gboolean must_support_all_comments) + wtap_compression_type *compression_type, + gboolean must_support_all_comments) { guint32 required_comment_types; GArray *savable_file_types; @@ -324,7 +325,7 @@ win32_save_as_file(HWND h_wnd, capture_file *cf, GString *file_name, int *file_t int ofnsize = sizeof(OPENFILENAME); BOOL gsfn_ok; - if (!file_name || !file_type || !compressed) + if (!file_name || !file_type || !compression_type) return FALSE; if (file_name->len > 0) { @@ -375,7 +376,7 @@ win32_save_as_file(HWND h_wnd, capture_file *cf, GString *file_name, int *file_t g_string_printf(file_name, "%s", utf_16to8(file_name16)); /* What file format was specified? */ *file_type = g_array_index(savable_file_types, int, ofn->nFilterIndex - 1); - *compressed = g_compressed; + *compression_type = g_compressed ? WTAP_GZIP_COMPRESSED : WTAP_UNCOMPRESSED; } else { /* User cancelled or closed the dialog, or an error occurred. */ if (CommDlgExtendedError() != 0) { @@ -451,7 +452,7 @@ gboolean win32_export_specified_packets_file(HWND h_wnd, capture_file *cf, GString *file_name, int *file_type, - gboolean *compressed, + wtap_compression_type *compression_type, packet_range_t *range) { GArray *savable_file_types; OPENFILENAME *ofn; @@ -459,7 +460,7 @@ win32_export_specified_packets_file(HWND h_wnd, capture_file *cf, int ofnsize = sizeof(OPENFILENAME); BOOL gsfn_ok; - if (!file_name || !file_type || !compressed || !range) + if (!file_name || !file_type || !compression_type || !range) return FALSE; if (file_name->len > 0) { @@ -506,7 +507,7 @@ win32_export_specified_packets_file(HWND h_wnd, capture_file *cf, g_string_printf(file_name, "%s", utf_16to8(file_name16)); /* What file format was specified? */ *file_type = g_array_index(savable_file_types, int, ofn->nFilterIndex - 1); - *compressed = g_compressed; + *compression_type = g_compressed ? WTAP_GZIP_COMPRESSED : WTAP_UNCOMPRESSED; } else { /* User cancelled or closed the dialog, or an error occurred. */ if (CommDlgExtendedError() != 0) { diff --git a/ui/win32/file_dlg_win32.h b/ui/win32/file_dlg_win32.h index 63406eac61..e80c944de5 100644 --- a/ui/win32/file_dlg_win32.h +++ b/ui/win32/file_dlg_win32.h @@ -67,7 +67,7 @@ check_savability_t win32_check_save_as_with_comments(HWND parent, capture_file * * @param cf capture_file Structure for the capture to be saved * @param file_name File name. May be empty. * @param file_type Wiretap file type. - * @param compressed Compress the file with gzip. + * @param compression_type Compression type to use, or uncompressed. * @param must_support_comments TRUE if the file format list should * include only file formats that support comments * @@ -75,7 +75,7 @@ check_savability_t win32_check_save_as_with_comments(HWND parent, capture_file * */ gboolean win32_save_as_file(HWND h_wnd, capture_file *cf, GString *file_name, int *file_type, - gboolean *compressed, + wtap_compression_type *compression_type, gboolean must_support_comments); /** Open the "Export Specified Packets" dialog box. @@ -84,7 +84,7 @@ gboolean win32_save_as_file(HWND h_wnd, capture_file *cf, * @param cf capture_file Structure for the capture to be saved * @param file_name File name. May be empty. * @param file_type Wiretap file type. - * @param compressed Compress the file with gzip. + * @param compression_type Compression type to use, or uncompressed. * @param range Range of packets to export. * * @return TRUE if packets were discarded when saving, FALSE otherwise @@ -93,7 +93,7 @@ gboolean win32_export_specified_packets_file(HWND h_wnd, capture_file *cf, GString *file_name, int *file_type, - gboolean *compressed, + wtap_compression_type *compression_type, packet_range_t *range); diff --git a/wiretap/file_access.c b/wiretap/file_access.c index d0093600bb..e6a8d517c6 100644 --- a/wiretap/file_access.c +++ b/wiretap/file_access.c @@ -2222,17 +2222,19 @@ wtap_dump_supports_comment_types(int file_type_subtype, guint32 comment_types) return FALSE; } -static gboolean wtap_dump_open_check(int file_type_subtype, int encap, gboolean comressed, int *err); +static gboolean wtap_dump_open_check(int file_type_subtype, int encap, gboolean compressed, int *err); static wtap_dumper* wtap_dump_alloc_wdh(int file_type_subtype, int encap, int snaplen, - gboolean compressed, int *err); -static gboolean wtap_dump_open_finish(wtap_dumper *wdh, int file_type_subtype, gboolean compressed, int *err); + wtap_compression_type compression_type, + int *err); +static gboolean wtap_dump_open_finish(wtap_dumper *wdh, int file_type_subtype, + int *err); static WFILE_T wtap_dump_file_open(wtap_dumper *wdh, const char *filename); static WFILE_T wtap_dump_file_fdopen(wtap_dumper *wdh, int fd); static int wtap_dump_file_close(wtap_dumper *wdh); static wtap_dumper * -wtap_dump_init_dumper(int file_type_subtype, gboolean compressed, +wtap_dump_init_dumper(int file_type_subtype, wtap_compression_type compression_type, const wtap_dump_params *params, int *err) { wtap_dumper *wdh; @@ -2241,12 +2243,16 @@ wtap_dump_init_dumper(int file_type_subtype, gboolean compressed, GArray *interfaces = params->idb_inf ? params->idb_inf->interface_data : NULL; /* Check whether we can open a capture file with that file type - and that encapsulation. */ - if (!wtap_dump_open_check(file_type_subtype, params->encap, compressed, err)) + and that encapsulation, and, if the compression type isn't + "uncompressed", whether we can write a *compressed* file + of that file type. */ + if (!wtap_dump_open_check(file_type_subtype, params->encap, + (compression_type != WTAP_UNCOMPRESSED), err)) return NULL; /* Allocate a data structure for the output stream. */ - wdh = wtap_dump_alloc_wdh(file_type_subtype, params->encap, params->snaplen, compressed, err); + wdh = wtap_dump_alloc_wdh(file_type_subtype, params->encap, + params->snaplen, compression_type, err); if (wdh == NULL) return NULL; /* couldn't allocate it */ @@ -2309,13 +2315,15 @@ wtap_dump_init_dumper(int file_type_subtype, gboolean compressed, wtap_dumper * wtap_dump_open(const char *filename, int file_type_subtype, - gboolean compressed, const wtap_dump_params *params, int *err) + wtap_compression_type compression_type, const wtap_dump_params *params, + int *err) { wtap_dumper *wdh; WFILE_T fh; /* Allocate and initialize a data structure for the output stream. */ - wdh = wtap_dump_init_dumper(file_type_subtype, compressed, params, err); + wdh = wtap_dump_init_dumper(file_type_subtype, compression_type, params, + err); if (wdh == NULL) return NULL; @@ -2330,7 +2338,7 @@ wtap_dump_open(const char *filename, int file_type_subtype, } wdh->fh = fh; - if (!wtap_dump_open_finish(wdh, file_type_subtype, compressed, err)) { + if (!wtap_dump_open_finish(wdh, file_type_subtype, err)) { /* Get rid of the file we created; we couldn't finish opening it. */ wtap_dump_file_close(wdh); @@ -2343,7 +2351,7 @@ wtap_dump_open(const char *filename, int file_type_subtype, wtap_dumper * wtap_dump_open_tempfile(char **filenamep, const char *pfx, - int file_type_subtype, gboolean compressed, + int file_type_subtype, wtap_compression_type compression_type, const wtap_dump_params *params, int *err) { int fd; @@ -2355,7 +2363,8 @@ wtap_dump_open_tempfile(char **filenamep, const char *pfx, *filenamep = NULL; /* Allocate and initialize a data structure for the output stream. */ - wdh = wtap_dump_init_dumper(file_type_subtype, compressed, params, err); + wdh = wtap_dump_init_dumper(file_type_subtype, compression_type, params, + err); if (wdh == NULL) return NULL; @@ -2380,7 +2389,7 @@ wtap_dump_open_tempfile(char **filenamep, const char *pfx, } wdh->fh = fh; - if (!wtap_dump_open_finish(wdh, file_type_subtype, compressed, err)) { + if (!wtap_dump_open_finish(wdh, file_type_subtype, err)) { /* Get rid of the file we created; we couldn't finish opening it. */ wtap_dump_file_close(wdh); @@ -2392,14 +2401,15 @@ wtap_dump_open_tempfile(char **filenamep, const char *pfx, } wtap_dumper * -wtap_dump_fdopen(int fd, int file_type_subtype, gboolean compressed, +wtap_dump_fdopen(int fd, int file_type_subtype, wtap_compression_type compression_type, const wtap_dump_params *params, int *err) { wtap_dumper *wdh; WFILE_T fh; /* Allocate and initialize a data structure for the output stream. */ - wdh = wtap_dump_init_dumper(file_type_subtype, compressed, params, err); + wdh = wtap_dump_init_dumper(file_type_subtype, compression_type, params, + err); if (wdh == NULL) return NULL; @@ -2414,7 +2424,7 @@ wtap_dump_fdopen(int fd, int file_type_subtype, gboolean compressed, } wdh->fh = fh; - if (!wtap_dump_open_finish(wdh, file_type_subtype, compressed, err)) { + if (!wtap_dump_open_finish(wdh, file_type_subtype, err)) { wtap_dump_file_close(wdh); g_free(wdh); return NULL; @@ -2423,7 +2433,7 @@ wtap_dump_fdopen(int fd, int file_type_subtype, gboolean compressed, } wtap_dumper * -wtap_dump_open_stdout(int file_type_subtype, gboolean compressed, +wtap_dump_open_stdout(int file_type_subtype, wtap_compression_type compression_type, const wtap_dump_params *params, int *err) { int new_fd; @@ -2455,7 +2465,8 @@ wtap_dump_open_stdout(int file_type_subtype, gboolean compressed, } #endif - wdh = wtap_dump_fdopen(new_fd, file_type_subtype, compressed, params, err); + wdh = wtap_dump_fdopen(new_fd, file_type_subtype, compression_type, + params, err); if (wdh == NULL) { /* Failed; close the new FD */ ws_close(new_fd); @@ -2499,7 +2510,8 @@ wtap_dump_open_check(int file_type_subtype, int encap, gboolean compressed, int } static wtap_dumper * -wtap_dump_alloc_wdh(int file_type_subtype, int encap, int snaplen, gboolean compressed, int *err) +wtap_dump_alloc_wdh(int file_type_subtype, int encap, int snaplen, + wtap_compression_type compression_type, int *err) { wtap_dumper *wdh; @@ -2512,21 +2524,21 @@ wtap_dump_alloc_wdh(int file_type_subtype, int encap, int snaplen, gboolean comp wdh->file_type_subtype = file_type_subtype; wdh->snaplen = snaplen; wdh->encap = encap; - wdh->compressed = compressed; + wdh->compression_type = compression_type; wdh->wslua_data = NULL; wdh->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_block_t)); return wdh; } static gboolean -wtap_dump_open_finish(wtap_dumper *wdh, int file_type_subtype, gboolean compressed, int *err) +wtap_dump_open_finish(wtap_dumper *wdh, int file_type_subtype, int *err) { int fd; gboolean cant_seek; /* Can we do a seek on the file descriptor? If not, note that fact. */ - if(compressed) { + if (wdh->compression_type != WTAP_UNCOMPRESSED) { cant_seek = TRUE; } else { fd = ws_fileno((FILE *)wdh->fh); @@ -2572,7 +2584,7 @@ void wtap_dump_flush(wtap_dumper *wdh) { #ifdef HAVE_ZLIB - if(wdh->compressed) { + if (wdh->compression_type == WTAP_GZIP_COMPRESSED) { gzwfile_flush((GZWFILE_T)wdh->fh); } else #endif @@ -2647,7 +2659,7 @@ gboolean wtap_dump_get_needs_reload(wtap_dumper *wdh) { static WFILE_T wtap_dump_file_open(wtap_dumper *wdh, const char *filename) { - if(wdh->compressed) { + if (wdh->compression_type == WTAP_GZIP_COMPRESSED) { return gzwfile_open(filename); } else { return ws_fopen(filename, "wb"); @@ -2666,7 +2678,7 @@ wtap_dump_file_open(wtap_dumper *wdh _U_, const char *filename) static WFILE_T wtap_dump_file_fdopen(wtap_dumper *wdh, int fd) { - if(wdh->compressed) { + if (wdh->compression_type == WTAP_GZIP_COMPRESSED) { return gzwfile_fdopen(fd); } else { return ws_fdopen(fd, "wb"); @@ -2687,7 +2699,7 @@ wtap_dump_file_write(wtap_dumper *wdh, const void *buf, size_t bufsize, int *err size_t nwritten; #ifdef HAVE_ZLIB - if (wdh->compressed) { + if (wdh->compression_type == WTAP_GZIP_COMPRESSED) { nwritten = gzwfile_write((GZWFILE_T)wdh->fh, buf, (unsigned int) bufsize); /* * gzwfile_write() returns 0 on error. @@ -2721,7 +2733,7 @@ static int wtap_dump_file_close(wtap_dumper *wdh) { #ifdef HAVE_ZLIB - if(wdh->compressed) + if (wdh->compression_type == WTAP_GZIP_COMPRESSED) return gzwfile_close((GZWFILE_T)wdh->fh); else #endif @@ -2732,7 +2744,7 @@ gint64 wtap_dump_file_seek(wtap_dumper *wdh, gint64 offset, int whence, int *err) { #ifdef HAVE_ZLIB - if(wdh->compressed) { + if (wdh->compression_type != WTAP_UNCOMPRESSED) { *err = WTAP_ERR_CANT_SEEK_COMPRESSED; return -1; } else @@ -2753,7 +2765,7 @@ wtap_dump_file_tell(wtap_dumper *wdh, int *err) { gint64 rval; #ifdef HAVE_ZLIB - if(wdh->compressed) { + if (wdh->compression_type != WTAP_UNCOMPRESSED) { *err = WTAP_ERR_CANT_SEEK_COMPRESSED; return -1; } else diff --git a/wiretap/merge.c b/wiretap/merge.c index 0a5c69fb9a..0e1c50cf9f 100644 --- a/wiretap/merge.c +++ b/wiretap/merge.c @@ -1022,8 +1022,8 @@ merge_files(const gchar* out_filename, const int file_type, params.shb_hdrs = shb_hdrs; params.idb_inf = idb_inf; } - pdh = wtap_dump_open(out_filename, file_type, FALSE /* compressed */, - ¶ms, err); + pdh = wtap_dump_open(out_filename, file_type, WTAP_UNCOMPRESSED, ¶ms, + err); if (pdh == NULL) { merge_close_in_files(in_file_count, in_files); g_free(in_files); @@ -1126,7 +1126,7 @@ merge_files_to_tempfile(gchar **out_filenamep, const char *pfx, params.idb_inf = idb_inf; } pdh = wtap_dump_open_tempfile(out_filenamep, pfx, file_type, - FALSE /* compressed */, ¶ms, err); + WTAP_UNCOMPRESSED, ¶ms, err); if (pdh == NULL) { merge_close_in_files(in_file_count, in_files); g_free(in_files); @@ -1223,7 +1223,7 @@ merge_files_to_stdout(const int file_type, const char *const *in_filenames, params.shb_hdrs = shb_hdrs; params.idb_inf = idb_inf; } - pdh = wtap_dump_open_stdout(file_type, FALSE /* compressed */, ¶ms, err); + pdh = wtap_dump_open_stdout(file_type, WTAP_UNCOMPRESSED, ¶ms, err); if (pdh == NULL) { merge_close_in_files(in_file_count, in_files); g_free(in_files); diff --git a/wiretap/nettrace_3gpp_32_423.c b/wiretap/nettrace_3gpp_32_423.c index 7d19e0aed4..8ea97335a4 100644 --- a/wiretap/nettrace_3gpp_32_423.c +++ b/wiretap/nettrace_3gpp_32_423.c @@ -799,7 +799,8 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_ .idb_inf = idb_inf, }; wdh_exp_pdu = wtap_dump_fdopen(import_file_fd, WTAP_FILE_TYPE_SUBTYPE_PCAPNG, - FALSE, ¶ms, &exp_pdu_file_err); + WTAP_UNCOMPRESSED, ¶ms, + &exp_pdu_file_err); if (wdh_exp_pdu == NULL) { result = WTAP_OPEN_ERROR; goto end; diff --git a/wiretap/wtap-int.h b/wiretap/wtap-int.h index f62a8dffde..fcd4b41167 100644 --- a/wiretap/wtap-int.h +++ b/wiretap/wtap-int.h @@ -88,7 +88,7 @@ struct wtap_dumper { int file_type_subtype; int snaplen; int encap; - gboolean compressed; + wtap_compression_type compression_type; gboolean needs_reload; /* TRUE if the file requires re-loading after saving with wtap */ gint64 bytes_dumped; diff --git a/wiretap/wtap.c b/wiretap/wtap.c index 4f73628393..3b7c31891f 100644 --- a/wiretap/wtap.c +++ b/wiretap/wtap.c @@ -77,10 +77,13 @@ wtap_file_type_subtype(wtap *wth) return wth->file_type_subtype; } -gboolean -wtap_iscompressed(wtap *wth) +wtap_compression_type +wtap_get_compression_type(wtap *wth) { - return file_iscompressed((wth->fh == NULL) ? wth->random_fh : wth->fh); + gboolean is_compressed; + + is_compressed = file_iscompressed((wth->fh == NULL) ? wth->random_fh : wth->fh); + return is_compressed ? WTAP_GZIP_COMPRESSED : WTAP_UNCOMPRESSED; } guint diff --git a/wiretap/wtap.h b/wiretap/wtap.h index 374c1ad3ba..eb6685323d 100644 --- a/wiretap/wtap.h +++ b/wiretap/wtap.h @@ -1690,6 +1690,14 @@ void wtap_rec_init(wtap_rec *rec); WS_DLL_PUBLIC void wtap_rec_cleanup(wtap_rec *rec); +/* + * Types of compression for a file, including "none". + */ +typedef enum { + WTAP_UNCOMPRESSED, + WTAP_GZIP_COMPRESSED +} wtap_compression_type; + /*** get various information snippets about the current file ***/ /** Return an approximation of the amount of data we've read sequentially @@ -1699,7 +1707,7 @@ gint64 wtap_read_so_far(wtap *wth); WS_DLL_PUBLIC gint64 wtap_file_size(wtap *wth, int *err); WS_DLL_PUBLIC -gboolean wtap_iscompressed(wtap *wth); +wtap_compression_type wtap_get_compression_type(wtap *wth); WS_DLL_PUBLIC guint wtap_snapshot_length(wtap *wth); /* per file */ WS_DLL_PUBLIC @@ -1897,14 +1905,15 @@ void wtap_dump_params_cleanup(wtap_dump_params *params); * * @param filename The new file's name. * @param file_type_subtype The WTAP_FILE_TYPE_SUBTYPE_XXX file type. - * @param compressed True if file should be compressed. + * @param compression_type Type of compression to use when writing, if any * @param params The per-file information for this file. * @param[out] err Will be set to an error code on failure. * @return The newly created dumper object, or NULL on failure. */ WS_DLL_PUBLIC wtap_dumper* wtap_dump_open(const char *filename, int file_type_subtype, - gboolean compressed, const wtap_dump_params *params, int *err); + wtap_compression_type compression_type, const wtap_dump_params *params, + int *err); /** * @brief Creates a dumper for a temporary file. @@ -1913,14 +1922,14 @@ wtap_dumper* wtap_dump_open(const char *filename, int file_type_subtype, * 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_subtype The WTAP_FILE_TYPE_SUBTYPE_XXX file type. - * @param compressed True if file should be compressed. + * @param compression_type Type of compression to use when writing, if any * @param params The per-file information for this file. * @param[out] err Will be set to an error code on failure. * @return The newly created dumper object, or NULL on failure. */ WS_DLL_PUBLIC wtap_dumper* wtap_dump_open_tempfile(char **filenamep, const char *pfx, - int file_type_subtype, gboolean compressed, + int file_type_subtype, wtap_compression_type compression_type, const wtap_dump_params *params, int *err); /** @@ -1928,14 +1937,15 @@ wtap_dumper* wtap_dump_open_tempfile(char **filenamep, const char *pfx, * * @param fd The file descriptor for which the dumper should be created. * @param file_type_subtype The WTAP_FILE_TYPE_SUBTYPE_XXX file type. - * @param compressed True if file should be compressed. + * @param compression_type Type of compression to use when writing, if any * @param params The per-file information for this file. * @param[out] err Will be set to an error code on failure. * @return The newly created dumper object, or NULL on failure. */ WS_DLL_PUBLIC wtap_dumper* wtap_dump_fdopen(int fd, int file_type_subtype, - gboolean compressed, const wtap_dump_params *params, int *err); + wtap_compression_type compression_type, const wtap_dump_params *params, + int *err); /** * @brief Creates a dumper for the standard output. @@ -1943,14 +1953,15 @@ wtap_dumper* wtap_dump_fdopen(int fd, int file_type_subtype, * @param file_type_subtype The WTAP_FILE_TYPE_SUBTYPE_XXX file type. * @param encap The WTAP_ENCAP_XXX encapsulation type (WTAP_ENCAP_PER_PACKET for multi) * @param snaplen The maximum packet capture length. - * @param compressed True if file should be compressed. + * @param compression_type Type of compression to use when writing, if any * @param params The per-file information for this file. * @param[out] err Will be set to an error code on failure. * @return The newly created dumper object, or NULL on failure. */ WS_DLL_PUBLIC wtap_dumper* wtap_dump_open_stdout(int file_type_subtype, - gboolean compressed, const wtap_dump_params *params, int *err); + wtap_compression_type compression_type, const wtap_dump_params *params, + int *err); WS_DLL_PUBLIC gboolean wtap_dump(wtap_dumper *, const wtap_rec *, const guint8 *,