wiretap: use appropriate extension for temporary files

With the change from Wireshark's default capture file format from
pcap to pcapng the suffix of the temporary file created in wiretap
was also changed from .pcap to .pcapng. This irrespective of the
actual file type requested. This change retrieves the registered
extension for the requested file type (in its uncompressed form)
and used that for the suffix. File types without a defined default
extension will get .tmp as suffix.

Change-Id: If809fef4325e483072c1fa4ee962125d991a197e
Signed-off-by: Jaap Keuter <jaap.keuter@xs4all.nl>
Reviewed-on: https://code.wireshark.org/review/31065
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Jaap Keuter 2018-12-16 21:54:49 +01:00 committed by Anders Broman
parent 5009f98c3a
commit 74bd75baa5
1 changed files with 11 additions and 1 deletions

View File

@ -2399,6 +2399,8 @@ wtap_dump_open_tempfile(char **filenamep, const char *pfx,
const wtap_dump_params *params, int *err)
{
int fd;
const char *ext;
char sfx[16];
char *tmpname;
wtap_dumper *wdh;
WFILE_T fh;
@ -2412,8 +2414,16 @@ wtap_dump_open_tempfile(char **filenamep, const char *pfx,
if (wdh == NULL)
return NULL;
/* Choose an appropriate suffix for the file */
ext = wtap_default_file_extension(file_type_subtype);
if (ext == NULL)
ext = "tmp";
sfx[0] = '.';
sfx[1] = '\0';
g_strlcat(sfx, ext, 16);
/* Choose a random name for the file */
fd = create_tempfile(&tmpname, pfx, ".pcapng");
fd = create_tempfile(&tmpname, pfx, sfx);
if (fd == -1) {
*err = errno;
g_free(wdh);