Don't have _ng versions of the dumper open routines.

Have the routines always take a parameters pointer; pass either null or
a pointer to an initialized-to-nothing structure in cases where we were
calling the non-_ng versions.

Change-Id: I23b779d87f3fbd29306ebe1df568852be113d3b2
Reviewed-on: https://code.wireshark.org/review/30590
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2018-11-12 15:43:10 -08:00
parent f070ad2c1e
commit 3faa45d4ec
15 changed files with 70 additions and 104 deletions

View File

@ -61,7 +61,6 @@ libwiretap.so.0 libwiretap0 #MINVER#
wtap_dump_can_write@Base 1.9.1
wtap_dump_close@Base 1.9.1
wtap_dump_fdopen@Base 1.9.1
wtap_dump_fdopen_ng@Base 1.9.1
wtap_dump_file_encap_type@Base 1.9.1
wtap_dump_file_seek@Base 1.12.0~rc1
wtap_dump_file_tell@Base 1.12.0~rc1
@ -70,11 +69,8 @@ libwiretap.so.0 libwiretap0 #MINVER#
wtap_dump_get_needs_reload@Base 2.5.0
wtap_dump_has_name_resolution@Base 1.9.1
wtap_dump_open@Base 1.9.1
wtap_dump_open_ng@Base 1.9.1
wtap_dump_open_stdout@Base 2.0.0
wtap_dump_open_stdout_ng@Base 2.0.0
wtap_dump_open_tempfile@Base 2.0.0
wtap_dump_open_tempfile_ng@Base 2.0.0
wtap_dump_params_cleanup@Base 2.9.0
wtap_dump_params_init@Base 2.9.0
wtap_dump_set_addrinfo_list@Base 1.9.1

View File

@ -943,13 +943,13 @@ editcap_dump_open(const char *filename, guint32 snaplen,
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 */,
ng_params, write_err);
pdh = wtap_dump_open_stdout(out_file_type_subtype, out_frame_type,
snaplen, FALSE /* compressed */,
ng_params, write_err);
} else {
pdh = wtap_dump_open_ng(filename, out_file_type_subtype, out_frame_type,
snaplen, FALSE /* compressed */,
ng_params, write_err);
pdh = wtap_dump_open(filename, out_file_type_subtype, out_frame_type,
snaplen, FALSE /* compressed */,
ng_params, write_err);
}
return pdh;
}

View File

@ -1144,6 +1144,7 @@ snort_dissector(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data
else {
/* We expect alerts from Snort. Pass frame into snort on first pass. */
if (!pinfo->fd->flags.visited && current_session.working) {
wtapng_dump_params params;
int write_err = 0;
gchar *err_info;
wtap_rec rec;
@ -1163,11 +1164,13 @@ snort_dissector(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data
* versions of Snort" wouldn't handle multiple encapsulation
* types.
*/
wtap_dump_params_init(&params, NULL);
current_session.pdh = wtap_dump_fdopen(current_session.in,
WTAP_FILE_TYPE_SUBTYPE_PCAP,
pinfo->rec->rec_header.packet_header.pkt_encap,
WTAP_MAX_PACKET_SIZE_STANDARD,
FALSE, /* compressed */
&params,
&open_err);
if (!current_session.pdh) {
current_session.working = FALSE;

View File

@ -205,8 +205,10 @@ WSLUA_CONSTRUCTOR Dumper_new(lua_State* L) {
int encap = (int)luaL_optinteger(L,WSLUA_OPTARG_Dumper_new_ENCAP,WTAP_ENCAP_ETHERNET);
int err = 0;
const char* filename = cross_plat_fname(fname);
wtapng_dump_params params;
d = wtap_dump_open(filename, filetype, encap, 0, FALSE, &err);
wtap_dump_params_init(&params, NULL);
d = wtap_dump_open(filename, filetype, encap, 0, FALSE, &params, &err);
if (! d ) {
/* WSLUA_ERROR("Error while opening file for writing"); */
@ -357,6 +359,7 @@ WSLUA_METHOD Dumper_new_for_current(lua_State* L) {
int encap;
int err = 0;
const char* filename = cross_plat_fname(fname);
wtapng_dump_params params;
if (! lua_pinfo ) {
WSLUA_ERROR(Dumper_new_for_current,"Cannot be used outside a tap or a dissector");
@ -369,7 +372,8 @@ WSLUA_METHOD Dumper_new_for_current(lua_State* L) {
encap = lua_pinfo->rec->rec_header.packet_header.pkt_encap;
d = wtap_dump_open(filename, filetype, encap, 0, FALSE, &err);
wtap_dump_params_init(&params, NULL);
d = wtap_dump_open(filename, filetype, encap, 0, FALSE, &params, &err);
if (! d ) {
switch (err) {

View File

@ -443,11 +443,13 @@ static struct extcap_dumper extcap_dumper_open(char *fifo, int encap) {
g_warning("Write to %s failed: %s", g_strerror(errno));
}
#else
wtapng_dump_params params;
int err = 0;
wtap_init(FALSE);
extcap_dumper.dumper.wtap = wtap_dump_open(fifo, WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC, encap, PACKET_LENGTH, FALSE, &err);
wtap_dump_params_init(&params, NULL);
extcap_dumper.dumper.wtap = wtap_dump_open(fifo, WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC, encap, PACKET_LENGTH, FALSE, &params, &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);

16
file.c
View File

@ -4466,11 +4466,11 @@ 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_ng(fname_new, save_format, encap, cf->snap,
compressed, &ng_params, &err);
pdh = wtap_dump_open(fname_new, save_format, encap, cf->snap,
compressed, &ng_params, &err);
} else {
pdh = wtap_dump_open_ng(fname, save_format, encap, cf->snap,
compressed, &ng_params, &err);
pdh = wtap_dump_open(fname, save_format, encap, cf->snap,
compressed, &ng_params, &err);
}
/* XXX idb_inf is documented to be used until wtap_dump_close. */
g_free(ng_params.idb_inf);
@ -4720,11 +4720,11 @@ 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_ng(fname_new, save_format, encap, cf->snap,
compressed, &ng_params, &err);
pdh = wtap_dump_open(fname_new, save_format, encap, cf->snap,
compressed, &ng_params, &err);
} else {
pdh = wtap_dump_open_ng(fname, save_format, encap, cf->snap,
compressed, &ng_params, &err);
pdh = wtap_dump_open(fname, save_format, encap, cf->snap,
compressed, &ng_params, &err);
}
/* XXX idb_inf is documented to be used until wtap_dump_close. */
g_free(ng_params.idb_inf);

View File

@ -654,20 +654,24 @@ gboolean randpkt_example_close(randpkt_example* example)
int randpkt_example_init(randpkt_example* example, char* produce_filename, int produce_max_bytes)
{
wtapng_dump_params params;
int err;
if (pkt_rand == NULL) {
pkt_rand = g_rand_new();
}
wtap_dump_params_init(&params, NULL);
if (strcmp(produce_filename, "-") == 0) {
/* Write to the standard output. */
example->dump = wtap_dump_open_stdout(WTAP_FILE_TYPE_SUBTYPE_PCAP,
example->sample_wtap_encap, produce_max_bytes, FALSE /* compressed */, &err);
example->sample_wtap_encap, produce_max_bytes, FALSE /* compressed */,
&params, &err);
example->filename = "the standard output";
} else {
example->dump = wtap_dump_open(produce_filename, WTAP_FILE_TYPE_SUBTYPE_PCAP,
example->sample_wtap_encap, produce_max_bytes, FALSE /* compressed */, &err);
example->sample_wtap_encap, produce_max_bytes, FALSE /* compressed */,
&params, &err);
example->filename = produce_filename;
}
if (!example->dump) {

View File

@ -287,11 +287,11 @@ main(int argc, char *argv[])
/* Open outfile (same filetype/encap as input file) */
if (strcmp(outfile, "-") == 0) {
pdh = wtap_dump_open_stdout_ng(wtap_file_type_subtype(wth), wtap_file_encap(wth),
wtap_snapshot_length(wth), FALSE, &ng_params, &err);
pdh = wtap_dump_open_stdout(wtap_file_type_subtype(wth), wtap_file_encap(wth),
wtap_snapshot_length(wth), FALSE, &ng_params, &err);
} else {
pdh = wtap_dump_open_ng(outfile, wtap_file_type_subtype(wth), wtap_file_encap(wth),
wtap_snapshot_length(wth), FALSE, &ng_params, &err);
pdh = wtap_dump_open(outfile, wtap_file_type_subtype(wth), wtap_file_encap(wth),
wtap_snapshot_length(wth), FALSE, &ng_params, &err);
}
g_free(ng_params.idb_inf);
ng_params.idb_inf = NULL;

View File

@ -3136,20 +3136,20 @@ process_cap_file(capture_file *cf, char *save_file, int out_file_type,
if (strcmp(save_file, "-") == 0) {
/* Write to the standard output. */
pdh = wtap_dump_open_stdout(out_file_type, linktype,
snapshot_length, FALSE /* compressed */, &err);
snapshot_length, FALSE /* compressed */, NULL, &err);
} else {
pdh = wtap_dump_open(save_file, out_file_type, linktype,
snapshot_length, FALSE /* compressed */, &err);
snapshot_length, FALSE /* compressed */, NULL, &err);
}
}
else {
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_ng(out_file_type, linktype,
pdh = wtap_dump_open_stdout(out_file_type, linktype,
snapshot_length, FALSE /* compressed */, &ng_params, &err);
} else {
pdh = wtap_dump_open_ng(save_file, out_file_type, linktype,
pdh = wtap_dump_open(save_file, out_file_type, linktype,
snapshot_length, FALSE /* compressed */, &ng_params, &err);
}
}

View File

@ -118,10 +118,12 @@ QString &ImportTextDialog::capfileName() {
void ImportTextDialog::convertTextFile() {
char *tmpname;
int err;
wtapng_dump_params params;
capfile_name_.clear();
wtap_dump_params_init(&params, NULL);
/* Use a random name for the temporary import buffer */
import_info_.wdh = wtap_dump_open_tempfile(&tmpname, "import", WTAP_FILE_TYPE_SUBTYPE_PCAP, import_info_.encapsulation, import_info_.max_frame_length, FALSE, &err);
import_info_.wdh = wtap_dump_open_tempfile(&tmpname, "import", WTAP_FILE_TYPE_SUBTYPE_PCAP, import_info_.encapsulation, import_info_.max_frame_length, FALSE, &params, &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) {

View File

@ -145,11 +145,11 @@ exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, char *comment)
.idb_inf = exp_pdu_tap_data->idb_inf,
};
if (fd == 1) {
exp_pdu_tap_data->wdh = wtap_dump_open_stdout_ng(WTAP_FILE_TYPE_SUBTYPE_PCAPNG,
exp_pdu_tap_data->wdh = wtap_dump_open_stdout(WTAP_FILE_TYPE_SUBTYPE_PCAPNG,
WTAP_ENCAP_WIRESHARK_UPPER_PDU, WTAP_MAX_PACKET_SIZE_STANDARD, FALSE,
&ng_params, &err);
} else {
exp_pdu_tap_data->wdh = wtap_dump_fdopen_ng(fd, WTAP_FILE_TYPE_SUBTYPE_PCAPNG,
exp_pdu_tap_data->wdh = wtap_dump_fdopen(fd, WTAP_FILE_TYPE_SUBTYPE_PCAPNG,
WTAP_ENCAP_WIRESHARK_UPPER_PDU, WTAP_MAX_PACKET_SIZE_STANDARD, FALSE,
&ng_params, &err);
}

View File

@ -2306,14 +2306,7 @@ wtap_dump_init_dumper(int file_type_subtype, int encap, int snaplen, gboolean co
wtap_dumper *
wtap_dump_open(const char *filename, int file_type_subtype, int encap,
int snaplen, gboolean compressed, int *err)
{
return wtap_dump_open_ng(filename, file_type_subtype, encap,snaplen, compressed, NULL, err);
}
wtap_dumper *
wtap_dump_open_ng(const char *filename, int file_type_subtype, int encap,
int snaplen, gboolean compressed, const wtapng_dump_params *ng_blocks, int *err)
int snaplen, gboolean compressed, const wtapng_dump_params *ng_blocks, int *err)
{
wtap_dumper *wdh;
WFILE_T fh;
@ -2348,17 +2341,9 @@ wtap_dump_open_ng(const char *filename, int file_type_subtype, int encap,
wtap_dumper *
wtap_dump_open_tempfile(char **filenamep, const char *pfx,
int file_type_subtype, int encap,
int snaplen, gboolean compressed, int *err)
{
return wtap_dump_open_tempfile_ng(filenamep, pfx, file_type_subtype, encap,snaplen, compressed, NULL, err);
}
wtap_dumper *
wtap_dump_open_tempfile_ng(char **filenamep, const char *pfx,
int file_type_subtype, int encap,
int snaplen, gboolean compressed,
const wtapng_dump_params *ng_blocks,
int *err)
int snaplen, gboolean compressed,
const wtapng_dump_params *ng_blocks,
int *err)
{
int fd;
char *tmpname;
@ -2407,14 +2392,7 @@ wtap_dump_open_tempfile_ng(char **filenamep, const char *pfx,
wtap_dumper *
wtap_dump_fdopen(int fd, int file_type_subtype, int encap, int snaplen,
gboolean compressed, int *err)
{
return wtap_dump_fdopen_ng(fd, file_type_subtype, encap, snaplen, compressed, NULL, err);
}
wtap_dumper *
wtap_dump_fdopen_ng(int fd, int file_type_subtype, int encap, int snaplen,
gboolean compressed, const wtapng_dump_params *ng_blocks, int *err)
gboolean compressed, const wtapng_dump_params *ng_blocks, int *err)
{
wtap_dumper *wdh;
WFILE_T fh;
@ -2445,14 +2423,7 @@ wtap_dump_fdopen_ng(int fd, int file_type_subtype, int encap, int snaplen,
wtap_dumper *
wtap_dump_open_stdout(int file_type_subtype, int encap, int snaplen,
gboolean compressed, int *err)
{
return wtap_dump_open_stdout_ng(file_type_subtype, encap, snaplen, compressed, NULL, err);
}
wtap_dumper *
wtap_dump_open_stdout_ng(int file_type_subtype, int encap, int snaplen,
gboolean compressed, const wtapng_dump_params *ng_blocks, int *err)
gboolean compressed, const wtapng_dump_params *ng_blocks, int *err)
{
int new_fd;
wtap_dumper *wdh;
@ -2483,7 +2454,7 @@ wtap_dump_open_stdout_ng(int file_type_subtype, int encap, int snaplen,
}
#endif
wdh = wtap_dump_fdopen_ng(new_fd, file_type_subtype, encap, snaplen, compressed, ng_blocks, err);
wdh = wtap_dump_fdopen(new_fd, file_type_subtype, encap, snaplen, compressed, ng_blocks, err);
if (wdh == NULL) {
/* Failed; close the new FD */
ws_close(new_fd);

View File

@ -1020,12 +1020,12 @@ merge_files(const gchar* out_filename, const int file_type,
.shb_hdrs = shb_hdrs,
.idb_inf = idb_inf,
};
pdh = wtap_dump_open_ng(out_filename, file_type, frame_type, snaplen,
FALSE /* compressed */, &ng_params, err);
pdh = wtap_dump_open(out_filename, file_type, frame_type, snaplen,
FALSE /* compressed */, &ng_params, err);
}
else {
pdh = wtap_dump_open(out_filename, file_type, frame_type, snaplen,
FALSE /* compressed */, err);
FALSE /* compressed */, NULL, err);
}
if (pdh == NULL) {
@ -1127,14 +1127,15 @@ merge_files_to_tempfile(gchar **out_filenamep, const char *pfx,
.shb_hdrs = shb_hdrs,
.idb_inf = idb_inf,
};
pdh = wtap_dump_open_tempfile_ng(out_filenamep, pfx, file_type,
frame_type, snaplen,
FALSE /* compressed */,
&ng_params, err);
pdh = wtap_dump_open_tempfile(out_filenamep, pfx, file_type,
frame_type, snaplen,
FALSE /* compressed */,
&ng_params, err);
}
else {
pdh = wtap_dump_open_tempfile(out_filenamep, pfx, file_type, frame_type,
snaplen, FALSE /* compressed */, err);
snaplen, FALSE /* compressed */,
NULL, err);
}
if (pdh == NULL) {
@ -1231,12 +1232,12 @@ merge_files_to_stdout(const int file_type, const char *const *in_filenames,
.shb_hdrs = shb_hdrs,
.idb_inf = idb_inf,
};
pdh = wtap_dump_open_stdout_ng(file_type, frame_type, snaplen,
FALSE /* compressed */, &ng_params, err);
pdh = wtap_dump_open_stdout(file_type, frame_type, snaplen,
FALSE /* compressed */, &ng_params, err);
}
else {
pdh = wtap_dump_open_stdout(file_type, frame_type, snaplen,
FALSE /* compressed */, err);
FALSE /* compressed */, NULL, err);
}
if (pdh == NULL) {

View File

@ -787,8 +787,8 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_
.shb_hdrs = shb_hdrs,
.idb_inf = idb_inf,
};
wdh_exp_pdu = wtap_dump_fdopen_ng(import_file_fd, WTAP_FILE_TYPE_SUBTYPE_PCAPNG, WTAP_ENCAP_WIRESHARK_UPPER_PDU,
WTAP_MAX_PACKET_SIZE_STANDARD, FALSE, &ng_params, &exp_pdu_file_err);
wdh_exp_pdu = wtap_dump_fdopen(import_file_fd, WTAP_FILE_TYPE_SUBTYPE_PCAPNG, WTAP_ENCAP_WIRESHARK_UPPER_PDU,
WTAP_MAX_PACKET_SIZE_STANDARD, FALSE, &ng_params, &exp_pdu_file_err);
if (wdh_exp_pdu == NULL) {
result = WTAP_OPEN_ERROR;
goto end;

View File

@ -1891,10 +1891,6 @@ void wtap_dump_params_init(wtapng_dump_params *params, wtap *wth);
WS_DLL_PUBLIC
void wtap_dump_params_cleanup(wtapng_dump_params *params);
WS_DLL_PUBLIC
wtap_dumper* wtap_dump_open(const char *filename, int file_type_subtype, int encap,
int snaplen, gboolean compressed, int *err);
/**
* @brief Opens a new capture file for writing.
*
@ -1908,14 +1904,9 @@ wtap_dumper* wtap_dump_open(const char *filename, int file_type_subtype, int enc
* @return The newly created dumper object, or NULL on failure.
*/
WS_DLL_PUBLIC
wtap_dumper* wtap_dump_open_ng(const char *filename, int file_type_subtype, int encap,
wtap_dumper* wtap_dump_open(const char *filename, int file_type_subtype, int encap,
int snaplen, gboolean compressed, const wtapng_dump_params *ng_blocks, int *err);
WS_DLL_PUBLIC
wtap_dumper* wtap_dump_open_tempfile(char **filenamep, const char *pfx,
int file_type_subtype, int encap, int snaplen, gboolean compressed,
int *err);
/**
* @brief Creates a dumper for a temporary file.
*
@ -1931,14 +1922,10 @@ wtap_dumper* wtap_dump_open_tempfile(char **filenamep, const char *pfx,
* @return The newly created dumper object, or NULL on failure.
*/
WS_DLL_PUBLIC
wtap_dumper* wtap_dump_open_tempfile_ng(char **filenamep, const char *pfx,
wtap_dumper* wtap_dump_open_tempfile(char **filenamep, const char *pfx,
int file_type_subtype, int encap, int snaplen, gboolean compressed,
const wtapng_dump_params *ng_blocks, int *err);
WS_DLL_PUBLIC
wtap_dumper* wtap_dump_fdopen(int fd, int file_type_subtype, int encap, int snaplen,
gboolean compressed, int *err);
/**
* @brief Creates a dumper for an existing file descriptor.
*
@ -1952,13 +1939,9 @@ wtap_dumper* wtap_dump_fdopen(int fd, int file_type_subtype, int encap, int snap
* @return The newly created dumper object, or NULL on failure.
*/
WS_DLL_PUBLIC
wtap_dumper* wtap_dump_fdopen_ng(int fd, int file_type_subtype, int encap, int snaplen,
wtap_dumper* wtap_dump_fdopen(int fd, int file_type_subtype, int encap, int snaplen,
gboolean compressed, const wtapng_dump_params *ng_blocks, int *err);
WS_DLL_PUBLIC
wtap_dumper* wtap_dump_open_stdout(int file_type_subtype, int encap, int snaplen,
gboolean compressed, int *err);
/**
* @brief Creates a dumper for the standard output.
*
@ -1971,7 +1954,7 @@ wtap_dumper* wtap_dump_open_stdout(int file_type_subtype, int encap, int snaplen
* @return The newly created dumper object, or NULL on failure.
*/
WS_DLL_PUBLIC
wtap_dumper* wtap_dump_open_stdout_ng(int file_type_subtype, int encap, int snaplen,
wtap_dumper* wtap_dump_open_stdout(int file_type_subtype, int encap, int snaplen,
gboolean compressed, const wtapng_dump_params *ng_blocks, int *err);
WS_DLL_PUBLIC