2003-08-23 08:34:12 +00:00
|
|
|
/* file_access.c
|
1998-11-12 06:01:27 +00:00
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
1998-11-12 06:01:27 +00:00
|
|
|
*
|
|
|
|
* Wiretap Library
|
2001-11-13 23:55:44 +00:00
|
|
|
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
|
2002-06-27 22:46:48 +00:00
|
|
|
*
|
1998-11-12 06:01:27 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-06-27 22:46:48 +00:00
|
|
|
*
|
1998-11-12 06:01:27 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2002-06-27 22:46:48 +00:00
|
|
|
*
|
1998-11-12 06:01:27 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
1998-11-12 06:01:27 +00:00
|
|
|
*/
|
2001-12-04 22:28:19 +00:00
|
|
|
|
1999-07-13 02:53:26 +00:00
|
|
|
#include "config.h"
|
2000-01-10 17:33:17 +00:00
|
|
|
|
1998-11-12 00:06:47 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
1998-11-12 23:29:34 +00:00
|
|
|
#include <stdlib.h>
|
2000-08-11 13:37:21 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_FCNTL_H
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
|
2001-10-28 01:51:46 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
1999-08-15 06:59:13 +00:00
|
|
|
#include <errno.h>
|
2000-01-10 17:33:17 +00:00
|
|
|
|
2008-05-22 15:46:27 +00:00
|
|
|
#include <wsutil/file_util.h>
|
2000-01-10 17:33:17 +00:00
|
|
|
|
2000-05-19 23:07:04 +00:00
|
|
|
#include "wtap-int.h"
|
2000-01-13 07:09:20 +00:00
|
|
|
#include "file_wrappers.h"
|
1999-03-01 18:57:07 +00:00
|
|
|
#include "buffer.h"
|
1998-11-12 06:01:27 +00:00
|
|
|
#include "lanalyzer.h"
|
|
|
|
#include "ngsniffer.h"
|
Check in Olivier Abad's patch to add dissectors for LAP-B and X.25, and
wiretap support for RADCOM Ltd.'s WAN/LAN analyzers (see
http://www.radcom-inc.com/
). Note: as I remember, IEEE 802.2/ISO 8022 LLC has somewhat of an SDLC
flavor to it, just as I think LAP, LAPB, LAPD, and so on do, so we may
be able to combine some of the LLC dissection and the LAPB dissection
into common code that could, conceivably be used for other SDLC-flavored
protocols.
Make "S" a mnemonic for "Summary" in the "Tools" menu.
Move the routine, used for the "Tools/Summary" display, that turns a
wiretap file type into a descriptive string for it into the wiretap
library itself, expand on some of its descriptions, and add an entry for
files from a RADCOM analyzer.
Have "Tools/Summary" display the snapshot length for the capture.
svn path=/trunk/; revision=416
1999-08-02 02:04:38 +00:00
|
|
|
#include "radcom.h"
|
2009-06-15 18:56:46 +00:00
|
|
|
#include "ascendtext.h"
|
1999-10-18 01:51:34 +00:00
|
|
|
#include "nettl.h"
|
1998-11-15 05:29:17 +00:00
|
|
|
#include "libpcap.h"
|
|
|
|
#include "snoop.h"
|
1999-01-02 06:10:55 +00:00
|
|
|
#include "iptrace.h"
|
2005-11-25 20:30:42 +00:00
|
|
|
#include "iseries.h"
|
1999-01-17 09:33:15 +00:00
|
|
|
#include "netmon.h"
|
1999-02-20 06:49:27 +00:00
|
|
|
#include "netxray.h"
|
1999-10-31 17:46:11 +00:00
|
|
|
#include "toshiba.h"
|
2004-02-11 20:05:16 +00:00
|
|
|
#include "eyesdn.h"
|
1999-12-12 22:40:10 +00:00
|
|
|
#include "i4btrace.h"
|
2000-08-08 22:16:42 +00:00
|
|
|
#include "csids.h"
|
2000-09-19 17:22:11 +00:00
|
|
|
#include "pppdump.h"
|
2012-07-09 23:07:28 +00:00
|
|
|
#include "peekclassic.h"
|
|
|
|
#include "peektagged.h"
|
2001-10-18 20:29:56 +00:00
|
|
|
#include "vms.h"
|
2001-10-19 20:18:48 +00:00
|
|
|
#include "dbs-etherwatch.h"
|
2001-12-04 22:28:19 +00:00
|
|
|
#include "visual.h"
|
2002-07-31 19:27:57 +00:00
|
|
|
#include "cosine.h"
|
2003-07-29 19:42:01 +00:00
|
|
|
#include "5views.h"
|
2003-08-26 07:10:39 +00:00
|
|
|
#include "erf.h"
|
2003-10-30 03:11:03 +00:00
|
|
|
#include "hcidump.h"
|
2003-10-31 00:43:21 +00:00
|
|
|
#include "network_instruments.h"
|
2005-06-10 16:01:16 +00:00
|
|
|
#include "k12.h"
|
2006-05-08 19:56:36 +00:00
|
|
|
#include "ber.h"
|
2006-04-14 12:41:06 +00:00
|
|
|
#include "catapult_dct2000.h"
|
2012-03-02 06:02:28 +00:00
|
|
|
#include "mp2t.h"
|
2007-03-22 10:44:33 +00:00
|
|
|
#include "mpeg.h"
|
2007-08-17 08:03:32 +00:00
|
|
|
#include "netscreen.h"
|
2007-11-24 03:33:18 +00:00
|
|
|
#include "commview.h"
|
2008-01-13 20:05:07 +00:00
|
|
|
#include "pcapng.h"
|
2011-10-26 02:18:55 +00:00
|
|
|
#include "aethra.h"
|
2008-02-03 21:11:53 +00:00
|
|
|
#include "btsnoop.h"
|
2008-11-27 16:40:45 +00:00
|
|
|
#include "tnef.h"
|
2009-01-07 07:21:31 +00:00
|
|
|
#include "dct3trace.h"
|
2009-02-16 07:24:04 +00:00
|
|
|
#include "packetlogger.h"
|
2009-05-24 22:49:36 +00:00
|
|
|
#include "daintree-sna.h"
|
2009-06-01 17:23:38 +00:00
|
|
|
#include "netscaler.h"
|
2011-06-09 21:21:06 +00:00
|
|
|
#include "mime_file.h"
|
2010-10-20 00:36:53 +00:00
|
|
|
#include "ipfix.h"
|
2012-04-20 12:08:31 +00:00
|
|
|
#include "vwr.h"
|
2013-03-30 09:56:57 +00:00
|
|
|
#include "camins.h"
|
2013-07-28 23:41:18 +00:00
|
|
|
#include "stanag4607.h"
|
2012-02-21 16:51:23 +00:00
|
|
|
#include "pcap-encap.h"
|
2007-05-04 21:10:55 +00:00
|
|
|
|
2013-08-27 20:46:47 +00:00
|
|
|
/*
|
|
|
|
* Add an extension, and all compressed versions thereof, to a GSList
|
|
|
|
* of extensions.
|
|
|
|
*/
|
|
|
|
static GSList *add_extensions(GSList *extensions, const gchar *extension,
|
|
|
|
GSList *compressed_file_extensions)
|
|
|
|
{
|
|
|
|
GSList *compressed_file_extension;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add the specified extension.
|
|
|
|
*/
|
|
|
|
extensions = g_slist_append(extensions, g_strdup(extension));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now add the extensions for compressed-file versions of
|
|
|
|
* that extension.
|
|
|
|
*/
|
|
|
|
for (compressed_file_extension = compressed_file_extensions;
|
|
|
|
compressed_file_extension != NULL;
|
|
|
|
compressed_file_extension = g_slist_next(compressed_file_extension)) {
|
|
|
|
extensions = g_slist_append(extensions,
|
|
|
|
g_strdup_printf("%s.%s", extension,
|
|
|
|
(gchar *)compressed_file_extension->data));
|
|
|
|
}
|
|
|
|
|
|
|
|
return extensions;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* File types that can be identified by file extensions.
|
|
|
|
*/
|
|
|
|
static const struct file_extension_info file_type_extensions_base[] = {
|
|
|
|
{ "Wireshark/tcpdump/... - pcap", "pcap;cap;dmp" },
|
|
|
|
{ "Wireshark/... - pcapng", "pcapng;ntar" },
|
|
|
|
{ "Network Monitor, Surveyor, NetScaler", "cap" },
|
|
|
|
{ "InfoVista 5View capture", "5vw" },
|
|
|
|
{ "Sniffer (DOS)", "cap;enc;trc;fdc;syc" },
|
|
|
|
{ "NetXRay, Sniffer (Windows)", "cap;caz" },
|
|
|
|
{ "Endace ERF capture", "erf" },
|
|
|
|
{ "EyeSDN USB S0/E1 ISDN trace format", "trc" },
|
|
|
|
{ "HP-UX nettl trace", "trc0;trc1" },
|
|
|
|
{ "Network Instruments Observer", "bfr" },
|
|
|
|
{ "Novell LANalyzer", "tr1" },
|
|
|
|
{ "Tektronix K12xx 32-bit .rf5 format", "rf5" },
|
|
|
|
{ "WildPackets *Peek", "pkt;tpc;apc;wpz" },
|
|
|
|
{ "Catapult DCT2000 trace (.out format)", "out" },
|
|
|
|
{ "MPEG files", "mpg;mp3" },
|
|
|
|
{ "CommView", "ncf" },
|
|
|
|
{ "Symbian OS btsnoop", "log" },
|
|
|
|
{ "Transport-Neutral Encapsulation Format", "tnef" },
|
|
|
|
{ "XML files (including Gammu DCT3 traces)", "xml" },
|
|
|
|
{ "OS X PacketLogger", "pklg" },
|
|
|
|
{ "Daintree SNA", "dcf" },
|
|
|
|
{ "JPEG/JFIF files", "jpg;jpeg;jfif" },
|
|
|
|
{ "IPFIX File Format", "pfx;ipfix" },
|
|
|
|
{ "Aethra .aps file", "aps" },
|
|
|
|
{ "MPEG2 transport stream", "mp2t;ts;mpg" },
|
|
|
|
{ "Ixia IxVeriWave .vwr Raw 802.11 Capture", "vwr" },
|
|
|
|
{ "CAM Inspector file", "camins" },
|
|
|
|
};
|
|
|
|
|
|
|
|
#define N_FILE_TYPE_EXTENSIONS (sizeof file_type_extensions_base / sizeof file_type_extensions_base[0])
|
|
|
|
|
|
|
|
static const struct file_extension_info* file_type_extensions = NULL;
|
|
|
|
|
|
|
|
static GArray* file_type_extensions_arr = NULL;
|
|
|
|
|
|
|
|
/* initialize the extensions array if it has not been initialized yet */
|
|
|
|
static void init_file_type_extensions(void) {
|
|
|
|
|
|
|
|
if (file_type_extensions_arr) return;
|
|
|
|
|
|
|
|
file_type_extensions_arr = g_array_new(FALSE,TRUE,sizeof(struct file_extension_info));
|
|
|
|
|
|
|
|
g_array_append_vals(file_type_extensions_arr,file_type_extensions_base,N_FILE_TYPE_EXTENSIONS);
|
|
|
|
|
|
|
|
file_type_extensions = (struct file_extension_info*)(void *)file_type_extensions_arr->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wtap_register_file_type_extension(const struct file_extension_info *ei) {
|
|
|
|
init_file_type_extensions();
|
|
|
|
|
|
|
|
g_array_append_val(file_type_extensions_arr,*ei);
|
|
|
|
|
|
|
|
file_type_extensions = (const struct file_extension_info*)(void *)file_type_extensions_arr->data;
|
|
|
|
}
|
|
|
|
|
2013-11-08 01:08:42 +00:00
|
|
|
int wtap_get_num_file_type_extensions(void)
|
|
|
|
{
|
|
|
|
return file_type_extensions_arr->len;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *wtap_get_file_extension_type_name(int extension_type)
|
|
|
|
{
|
|
|
|
return file_type_extensions[extension_type].name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GSList *add_extensions_for_file_extensions_type(int extension_type,
|
|
|
|
GSList *extensions, GSList *compressed_file_extensions)
|
|
|
|
{
|
|
|
|
gchar **extensions_set, **extensionp, *extension;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Split the extension-list string into a set of extensions.
|
|
|
|
*/
|
|
|
|
extensions_set = g_strsplit(file_type_extensions[extension_type].extensions,
|
|
|
|
";", 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add each of those extensions to the list.
|
|
|
|
*/
|
|
|
|
for (extensionp = extensions_set; *extensionp != NULL; extensionp++) {
|
|
|
|
extension = *extensionp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add the extension, and all compressed variants
|
|
|
|
* of it.
|
|
|
|
*/
|
|
|
|
extensions = add_extensions(extensions, extension,
|
|
|
|
compressed_file_extensions);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev(extensions_set);
|
|
|
|
return extensions;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return a list of file extensions that are used by the specified file
|
|
|
|
extension type.
|
|
|
|
|
|
|
|
All strings in the list are allocated with g_malloc() and must be freed
|
|
|
|
with g_free(). */
|
|
|
|
GSList *wtap_get_file_extension_type_extensions(guint extension_type)
|
|
|
|
{
|
|
|
|
GSList *compressed_file_extensions;
|
|
|
|
GSList *extensions;
|
|
|
|
|
|
|
|
if (extension_type >= file_type_extensions_arr->len)
|
|
|
|
return NULL; /* not a valid extension type */
|
|
|
|
|
|
|
|
extensions = NULL; /* empty list, to start with */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the list of compressed-file extensions.
|
|
|
|
*/
|
|
|
|
compressed_file_extensions = wtap_get_compressed_file_extensions();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add all this file extension type's extensions, with compressed
|
|
|
|
* variants.
|
|
|
|
*/
|
|
|
|
extensions = add_extensions_for_file_extensions_type(extension_type,
|
|
|
|
extensions, compressed_file_extensions);
|
|
|
|
|
|
|
|
g_slist_free(compressed_file_extensions);
|
|
|
|
return extensions;
|
|
|
|
}
|
|
|
|
|
2013-08-27 20:46:47 +00:00
|
|
|
/* Return a list of all extensions that are used by all file types,
|
|
|
|
including compressed extensions, e.g. not just "pcap" but also
|
|
|
|
"pcap.gz" if we can read gzipped files.
|
|
|
|
|
|
|
|
All strings in the list are allocated with g_malloc() and must be freed
|
|
|
|
with g_free(). */
|
|
|
|
GSList *wtap_get_all_file_extensions_list(void)
|
|
|
|
{
|
|
|
|
GSList *compressed_file_extensions;
|
|
|
|
GSList *extensions;
|
|
|
|
unsigned int i;
|
|
|
|
|
2013-08-27 22:10:35 +00:00
|
|
|
init_file_type_extensions();
|
|
|
|
|
2013-08-27 20:46:47 +00:00
|
|
|
extensions = NULL; /* empty list, to start with */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the list of compressed-file extensions.
|
|
|
|
*/
|
|
|
|
compressed_file_extensions = wtap_get_compressed_file_extensions();
|
|
|
|
|
|
|
|
for (i = 0; i < file_type_extensions_arr->len; i++) {
|
|
|
|
/*
|
2013-11-08 01:08:42 +00:00
|
|
|
* Add all this file extension type's extensions, with
|
|
|
|
* compressed variants.
|
2013-08-27 20:46:47 +00:00
|
|
|
*/
|
2013-11-08 01:08:42 +00:00
|
|
|
extensions = add_extensions_for_file_extensions_type(i,
|
|
|
|
extensions, compressed_file_extensions);
|
2013-08-27 20:46:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free(compressed_file_extensions);
|
|
|
|
return extensions;
|
|
|
|
}
|
|
|
|
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
/* The open_file_* routines should return:
|
|
|
|
*
|
|
|
|
* -1 on an I/O error;
|
|
|
|
*
|
|
|
|
* 1 if the file they're reading is one of the types it handles;
|
|
|
|
*
|
|
|
|
* 0 if the file they're reading isn't the type they're checking for.
|
|
|
|
*
|
|
|
|
* If the routine handles this type of file, it should set the "file_type"
|
|
|
|
* field in the "struct wtap" to the type of the file.
|
|
|
|
*
|
2013-03-25 22:04:15 +00:00
|
|
|
* Note that the routine does not have to free the private data pointer on
|
|
|
|
* error. The caller takes care of that by calling wtap_close on error.
|
|
|
|
* (See https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8518)
|
|
|
|
*
|
|
|
|
* However, the caller does have to free the private data pointer when
|
|
|
|
* returning 0, since the next file type will be called and will likely
|
|
|
|
* just overwrite the pointer.
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
*/
|
|
|
|
|
2007-05-04 21:10:55 +00:00
|
|
|
|
2013-12-30 06:43:19 +00:00
|
|
|
/* Files that have magic bytes in fixed locations. These
|
|
|
|
* are easy to identify. Only an open routine is needed.
|
|
|
|
*/
|
|
|
|
static const wtap_open_routine_t magic_number_open_routines_base[] = {
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
libpcap_open,
|
2012-04-26 03:21:29 +00:00
|
|
|
pcapng_open,
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
ngsniffer_open,
|
|
|
|
snoop_open,
|
|
|
|
iptrace_open,
|
|
|
|
netmon_open,
|
|
|
|
netxray_open,
|
1999-09-11 04:50:44 +00:00
|
|
|
radcom_open,
|
1999-10-31 17:46:11 +00:00
|
|
|
nettl_open,
|
2001-12-04 22:28:19 +00:00
|
|
|
visual_open,
|
2003-07-29 19:42:01 +00:00
|
|
|
_5views_open,
|
2003-10-31 00:43:21 +00:00
|
|
|
network_instruments_open,
|
2012-07-09 23:07:28 +00:00
|
|
|
peektagged_open,
|
2005-03-01 19:59:54 +00:00
|
|
|
dbs_etherwatch_open,
|
2005-06-10 16:01:16 +00:00
|
|
|
k12_open,
|
2006-04-14 12:41:06 +00:00
|
|
|
catapult_dct2000_open,
|
2011-10-26 02:18:55 +00:00
|
|
|
aethra_open,
|
2008-02-03 21:11:53 +00:00
|
|
|
btsnoop_open,
|
2012-04-26 03:21:29 +00:00
|
|
|
eyesdn_open,
|
2008-11-27 16:40:45 +00:00
|
|
|
tnef_open,
|
2013-12-30 06:43:19 +00:00
|
|
|
};
|
|
|
|
#define N_MAGIC_FILE_TYPES (sizeof magic_number_open_routines_base / sizeof magic_number_open_routines_base[0])
|
|
|
|
|
|
|
|
static wtap_open_routine_t* magic_number_open_routines = NULL;
|
|
|
|
|
|
|
|
static GArray* magic_number_open_routines_arr = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the magic-number open routines array if it has not been
|
|
|
|
* initialized yet.
|
|
|
|
*/
|
|
|
|
static void init_magic_number_open_routines(void) {
|
|
|
|
|
|
|
|
if (magic_number_open_routines_arr) return;
|
|
|
|
|
|
|
|
magic_number_open_routines_arr = g_array_new(FALSE,TRUE,sizeof(wtap_open_routine_t));
|
|
|
|
|
|
|
|
g_array_append_vals(magic_number_open_routines_arr,magic_number_open_routines_base,N_MAGIC_FILE_TYPES);
|
|
|
|
|
|
|
|
magic_number_open_routines = (wtap_open_routine_t*)(void *)magic_number_open_routines_arr->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wtap_register_magic_number_open_routine(wtap_open_routine_t open_routine) {
|
|
|
|
init_magic_number_open_routines();
|
|
|
|
|
|
|
|
g_array_append_val(magic_number_open_routines_arr,open_routine);
|
|
|
|
|
|
|
|
magic_number_open_routines = (wtap_open_routine_t*)(void *)magic_number_open_routines_arr->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Files that don't have magic bytes at a fixed location,
|
|
|
|
* but that instead require a heuristic of some sort to
|
|
|
|
* identify them. This includes ASCII trace files.
|
|
|
|
*
|
|
|
|
* Entries for the ASCII trace files that would be, for example,
|
|
|
|
* saved copies of a Telnet session to some box are put after
|
|
|
|
* most of the other entries, as we don't want to treat a capture
|
|
|
|
* of such a session as a trace file from such a session
|
|
|
|
* merely because it has the right text in it. They still
|
|
|
|
* appear before the *really* weak entries, such as the VWR entry.
|
|
|
|
*/
|
|
|
|
static const struct heuristic_open_info heuristic_open_info_base[] = {
|
|
|
|
{ lanalyzer_open, "tr1", },
|
|
|
|
/*
|
|
|
|
* PacketLogger must come before MPEG, because its files
|
|
|
|
* are sometimes grabbed by mpeg_open.
|
1999-10-31 17:46:11 +00:00
|
|
|
*/
|
2013-12-30 06:43:19 +00:00
|
|
|
{ packetlogger_open, "pklg" },
|
|
|
|
/* Some MPEG files have magic numbers, others just have heuristics. */
|
|
|
|
{ mpeg_open, "mpg;mp3" },
|
|
|
|
{ dct3trace_open, "xml" },
|
|
|
|
{ daintree_sna_open, "dcf" },
|
|
|
|
{ mime_file_open, NULL },
|
|
|
|
{ stanag4607_open, NULL },
|
|
|
|
{ ber_open, NULL },
|
2007-08-17 08:03:32 +00:00
|
|
|
|
|
|
|
/* I put NetScreen *before* erf, because there were some
|
|
|
|
* false positives with my test-files (Sake Blok, July 2007)
|
2013-08-22 03:43:39 +00:00
|
|
|
*
|
|
|
|
* I put VWR *after* ERF, because there were some cases where
|
|
|
|
* ERF files were misidentified as vwr files (Stephen
|
|
|
|
* Donnelly, August 2013; see bug 9054)
|
2013-12-13 02:38:11 +00:00
|
|
|
*
|
2013-12-13 03:12:42 +00:00
|
|
|
* I put VWR *after* Peek Classic, CommView, iSeries text,
|
2013-12-13 03:13:40 +00:00
|
|
|
* Toshiba text, K12 text, VMS tcpiptrace text, and NetScaler,
|
|
|
|
* because there were some cases where files of those types were
|
2013-12-13 03:12:42 +00:00
|
|
|
* misidentified as vwr files (Guy Harris, December 2013)
|
2007-08-17 08:03:32 +00:00
|
|
|
*/
|
2013-12-30 06:43:19 +00:00
|
|
|
{ netscreen_open, "txt" },
|
|
|
|
{ erf_open, "erf" },
|
|
|
|
{ ipfix_open, "pfx;ipfix" },
|
|
|
|
{ k12text_open, "txt" },
|
|
|
|
{ peekclassic_open, "pkt;tpc;apc;wpz" },
|
|
|
|
{ pppdump_open, NULL },
|
|
|
|
{ iseries_open, "txt" },
|
|
|
|
{ i4btrace_open, NULL },
|
|
|
|
{ mp2t_open, "ts;mpg" },
|
|
|
|
{ csids_open, NULL },
|
|
|
|
{ vms_open, "txt" },
|
|
|
|
{ cosine_open, "txt" },
|
|
|
|
{ hcidump_open, NULL },
|
|
|
|
{ commview_open, "ncf" },
|
|
|
|
{ nstrace_open, "txt" },
|
|
|
|
|
|
|
|
/* ASCII trace files from Telnet sessions. */
|
|
|
|
{ ascend_open, "txt" },
|
|
|
|
{ toshiba_open, "txt" },
|
|
|
|
|
|
|
|
/* Extremely weak heuristics - put them at the end. */
|
|
|
|
{ vwr_open, "vwr" },
|
|
|
|
{ camins_open, "camins" },
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
};
|
2013-12-30 06:43:19 +00:00
|
|
|
#define N_HEURISTIC_FILE_TYPES (sizeof heuristic_open_info_base / sizeof heuristic_open_info_base[0])
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
|
2013-12-30 06:43:19 +00:00
|
|
|
static const struct heuristic_open_info* heuristic_open_info = NULL;
|
2007-05-04 21:10:55 +00:00
|
|
|
|
2013-12-30 06:43:19 +00:00
|
|
|
static GArray* heuristic_open_info_arr = NULL;
|
2007-05-04 21:10:55 +00:00
|
|
|
|
2013-12-30 06:43:19 +00:00
|
|
|
/*
|
|
|
|
* Initialize the heuristics array if it has not been initialized yet.
|
|
|
|
*/
|
|
|
|
static void init_heuristic_open_info(void) {
|
2008-05-22 15:46:27 +00:00
|
|
|
|
2013-12-30 06:43:19 +00:00
|
|
|
if (heuristic_open_info_arr) return;
|
2007-05-04 21:10:55 +00:00
|
|
|
|
2013-12-30 06:43:19 +00:00
|
|
|
heuristic_open_info_arr = g_array_new(FALSE,TRUE,sizeof(struct heuristic_open_info));
|
2008-05-22 15:46:27 +00:00
|
|
|
|
2013-12-30 06:43:19 +00:00
|
|
|
g_array_append_vals(heuristic_open_info_arr,heuristic_open_info_base,N_HEURISTIC_FILE_TYPES);
|
2008-05-22 15:46:27 +00:00
|
|
|
|
2013-12-30 06:43:19 +00:00
|
|
|
heuristic_open_info = (const struct heuristic_open_info*)(void *)heuristic_open_info_arr->data;
|
2007-05-04 21:10:55 +00:00
|
|
|
}
|
|
|
|
|
2013-12-30 06:43:19 +00:00
|
|
|
void wtap_register_heuristic_open_info(const struct heuristic_open_info *hi) {
|
|
|
|
init_heuristic_open_info();
|
2007-05-04 21:10:55 +00:00
|
|
|
|
2013-12-30 06:43:19 +00:00
|
|
|
g_array_append_val(heuristic_open_info_arr,*hi);
|
2008-05-22 15:46:27 +00:00
|
|
|
|
2013-12-30 06:43:19 +00:00
|
|
|
heuristic_open_info = (const struct heuristic_open_info*)(void *)heuristic_open_info_arr->data;
|
2007-05-04 21:10:55 +00:00
|
|
|
}
|
2000-07-31 04:19:54 +00:00
|
|
|
|
2000-07-31 04:48:54 +00:00
|
|
|
/*
|
|
|
|
* Visual C++ on Win32 systems doesn't define these. (Old UNIX systems don't
|
|
|
|
* define them either.)
|
|
|
|
*
|
|
|
|
* Visual C++ on Win32 systems doesn't define S_IFIFO, it defines _S_IFIFO.
|
|
|
|
*/
|
2000-07-31 04:19:54 +00:00
|
|
|
#ifndef S_ISREG
|
|
|
|
#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
|
|
|
|
#endif
|
|
|
|
#ifndef S_IFIFO
|
|
|
|
#define S_IFIFO _S_IFIFO
|
|
|
|
#endif
|
|
|
|
#ifndef S_ISFIFO
|
|
|
|
#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
|
|
|
|
#endif
|
|
|
|
#ifndef S_ISDIR
|
|
|
|
#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
|
|
|
|
#endif
|
1998-11-12 00:06:47 +00:00
|
|
|
|
2013-12-30 06:43:19 +00:00
|
|
|
static char *get_file_extension(const char *pathname)
|
|
|
|
{
|
|
|
|
gchar *filename;
|
|
|
|
gchar **components;
|
|
|
|
size_t ncomponents;
|
|
|
|
GSList *compressed_file_extensions, *compressed_file_extension;
|
|
|
|
gchar *extensionp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is the pathname empty?
|
|
|
|
*/
|
|
|
|
if (strcmp(pathname, "") == 0)
|
|
|
|
return NULL; /* no extension */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the last component of the pathname.
|
|
|
|
*/
|
|
|
|
filename = g_path_get_basename(pathname);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Does it have an extension?
|
|
|
|
*/
|
|
|
|
if (strchr(filename, '.') == NULL) {
|
|
|
|
g_free(filename);
|
|
|
|
return NULL; /* no extension whatsoever */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Yes. Split it into components separated by ".".
|
|
|
|
*/
|
|
|
|
components = g_strsplit(filename, ".", 0);
|
|
|
|
g_free(filename);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Count the components.
|
|
|
|
*/
|
|
|
|
for (ncomponents = 0; components[ncomponents] != NULL; ncomponents++)
|
|
|
|
;
|
|
|
|
|
|
|
|
if (ncomponents == 0) {
|
|
|
|
g_strfreev(components);
|
|
|
|
return NULL; /* no components */
|
|
|
|
}
|
|
|
|
if (ncomponents == 1) {
|
|
|
|
g_strfreev(components);
|
|
|
|
return NULL; /* only one component, with no "." */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is the last component one of the extensions used for compressed
|
|
|
|
* files?
|
|
|
|
*/
|
|
|
|
compressed_file_extensions = wtap_get_compressed_file_extensions();
|
|
|
|
if (compressed_file_extensions == NULL) {
|
|
|
|
/*
|
|
|
|
* We don't support reading compressed files, so just
|
|
|
|
* return a copy of whatever extension we did find.
|
|
|
|
*/
|
|
|
|
extensionp = g_strdup(components[ncomponents - 1]);
|
|
|
|
g_strfreev(components);
|
|
|
|
return extensionp;
|
|
|
|
}
|
|
|
|
extensionp = components[ncomponents - 1];
|
|
|
|
for (compressed_file_extension = compressed_file_extensions;
|
|
|
|
compressed_file_extension != NULL;
|
|
|
|
compressed_file_extension = g_slist_next(compressed_file_extension)) {
|
|
|
|
if (strcmp(extensionp, (char *)compressed_file_extension->data) == 0) {
|
|
|
|
/*
|
|
|
|
* Yes, it's one of the compressed-file extensions.
|
|
|
|
* Is there an extension before that?
|
|
|
|
*/
|
|
|
|
if (ncomponents == 2) {
|
|
|
|
g_strfreev(components);
|
|
|
|
return NULL; /* no, only two components */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Yes, return that extension.
|
|
|
|
*/
|
|
|
|
extensionp = g_strdup(components[ncomponents - 2]);
|
|
|
|
g_strfreev(components);
|
|
|
|
return extensionp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The extension isn't one of the compressed-file extensions;
|
|
|
|
* return it.
|
|
|
|
*/
|
|
|
|
extensionp = g_strdup(extensionp);
|
|
|
|
g_strfreev(components);
|
|
|
|
return extensionp;
|
|
|
|
}
|
|
|
|
|
2014-01-10 07:01:15 +00:00
|
|
|
static gboolean heuristic_uses_extension(unsigned int i, const char *extension)
|
2013-12-30 06:43:19 +00:00
|
|
|
{
|
|
|
|
gchar **extensions_set, **extensionp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Does this file type *have* any extensions?
|
|
|
|
*/
|
|
|
|
if (heuristic_open_info[i].extensions == NULL)
|
|
|
|
return FALSE; /* no */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a list of the extensions used by the specified file type.
|
|
|
|
*/
|
|
|
|
extensions_set = g_strsplit(heuristic_open_info[i].extensions, ";", 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check each of them against the specified extension.
|
|
|
|
*/
|
|
|
|
for (extensionp = extensions_set; *extensionp != NULL;
|
|
|
|
extensionp++) {
|
|
|
|
if (strcmp(extension, *extensionp) == 0) {
|
|
|
|
g_strfreev(extensions_set);
|
|
|
|
return TRUE; /* it's one of them */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_strfreev(extensions_set);
|
|
|
|
return FALSE; /* it's not one of them */
|
|
|
|
}
|
|
|
|
|
2000-05-18 09:09:50 +00:00
|
|
|
/* Opens a file and prepares a wtap struct.
|
|
|
|
If "do_random" is TRUE, it opens the file twice; the second open
|
|
|
|
allows the application to do random-access I/O without moving
|
2006-05-22 08:14:01 +00:00
|
|
|
the seek offset for sequential I/O, which is used by Wireshark
|
2000-05-18 09:09:50 +00:00
|
|
|
so that it can do sequential I/O to a capture file that's being
|
|
|
|
written to as new packets arrive independently of random I/O done
|
|
|
|
to display protocol trees for packets when they're selected. */
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
wtap* wtap_open_offline(const char *filename, int *err, char **err_info,
|
2009-01-04 16:45:34 +00:00
|
|
|
gboolean do_random)
|
1998-11-12 00:06:47 +00:00
|
|
|
{
|
2011-05-09 08:12:26 +00:00
|
|
|
int fd;
|
2011-04-10 20:59:10 +00:00
|
|
|
ws_statb64 statb;
|
1998-11-12 00:06:47 +00:00
|
|
|
wtap *wth;
|
2001-07-13 00:55:58 +00:00
|
|
|
unsigned int i;
|
2005-01-28 11:31:19 +00:00
|
|
|
gboolean use_stdin = FALSE;
|
2013-12-30 06:43:19 +00:00
|
|
|
gchar *extension;
|
2005-01-28 11:31:19 +00:00
|
|
|
|
|
|
|
/* open standard input if filename is '-' */
|
|
|
|
if (strcmp(filename, "-") == 0)
|
|
|
|
use_stdin = TRUE;
|
1998-11-12 00:06:47 +00:00
|
|
|
|
1999-08-15 06:59:13 +00:00
|
|
|
/* First, make sure the file is valid */
|
2005-01-28 11:31:19 +00:00
|
|
|
if (use_stdin) {
|
2011-04-10 22:04:14 +00:00
|
|
|
if (ws_fstat64(0, &statb) < 0) {
|
2005-01-28 11:31:19 +00:00
|
|
|
*err = errno;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else {
|
2011-04-10 20:59:10 +00:00
|
|
|
if (ws_stat64(filename, &statb) < 0) {
|
2005-01-28 11:31:19 +00:00
|
|
|
*err = errno;
|
|
|
|
return NULL;
|
|
|
|
}
|
1999-08-15 06:59:13 +00:00
|
|
|
}
|
2002-06-07 07:47:58 +00:00
|
|
|
if (S_ISFIFO(statb.st_mode)) {
|
|
|
|
/*
|
|
|
|
* Opens of FIFOs are allowed only when not opening
|
|
|
|
* for random access.
|
|
|
|
*
|
|
|
|
* XXX - currently, we do seeking when trying to find
|
|
|
|
* out the file type, so we don't actually support
|
|
|
|
* opening FIFOs. However, we may eventually
|
|
|
|
* do buffering that allows us to do at least some
|
|
|
|
* file type determination even on pipes, so we
|
|
|
|
* allow FIFO opens and let things fail later when
|
|
|
|
* we try to seek.
|
|
|
|
*/
|
|
|
|
if (do_random) {
|
|
|
|
*err = WTAP_ERR_RANDOM_OPEN_PIPE;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else if (S_ISDIR(statb.st_mode)) {
|
|
|
|
/*
|
|
|
|
* Return different errors for "this is a directory"
|
|
|
|
* and "this is some random special file type", so
|
|
|
|
* the user can get a potentially more helpful error.
|
|
|
|
*/
|
|
|
|
*err = EISDIR;
|
|
|
|
return NULL;
|
|
|
|
} else if (! S_ISREG(statb.st_mode)) {
|
|
|
|
*err = WTAP_ERR_NOT_REGULAR_FILE;
|
1999-08-15 06:59:13 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-01-28 11:31:19 +00:00
|
|
|
/*
|
|
|
|
* We need two independent descriptors for random access, so
|
|
|
|
* they have different file positions. If we're opening the
|
|
|
|
* standard input, we can only dup it to get additional
|
|
|
|
* descriptors, so we can't have two independent descriptors,
|
|
|
|
* and thus can't do random access.
|
|
|
|
*/
|
|
|
|
if (use_stdin && do_random) {
|
|
|
|
*err = WTAP_ERR_RANDOM_OPEN_STDIN;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1999-08-18 04:41:20 +00:00
|
|
|
errno = ENOMEM;
|
2011-03-24 22:47:57 +00:00
|
|
|
wth = (wtap *)g_malloc0(sizeof(wtap));
|
1998-11-12 00:06:47 +00:00
|
|
|
|
|
|
|
/* Open the file */
|
1999-08-18 04:41:20 +00:00
|
|
|
errno = WTAP_ERR_CANT_OPEN;
|
2005-01-28 11:31:19 +00:00
|
|
|
if (use_stdin) {
|
|
|
|
/*
|
|
|
|
* We dup FD 0, so that we don't have to worry about
|
2011-05-09 03:48:41 +00:00
|
|
|
* a file_close of wth->fh closing the standard
|
2005-01-28 11:31:19 +00:00
|
|
|
* input of the process.
|
|
|
|
*/
|
2011-05-09 08:12:26 +00:00
|
|
|
fd = ws_dup(0);
|
|
|
|
if (fd < 0) {
|
2011-04-14 02:53:18 +00:00
|
|
|
*err = errno;
|
|
|
|
g_free(wth);
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-01-28 11:31:19 +00:00
|
|
|
#ifdef _WIN32
|
2011-05-09 08:12:26 +00:00
|
|
|
if (_setmode(fd, O_BINARY) == -1) {
|
2011-04-14 02:53:18 +00:00
|
|
|
/* "Shouldn't happen" */
|
|
|
|
*err = errno;
|
|
|
|
g_free(wth);
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-01-28 11:31:19 +00:00
|
|
|
#endif
|
2012-06-01 08:05:12 +00:00
|
|
|
if (!(wth->fh = file_fdopen(fd))) {
|
2011-05-09 03:48:41 +00:00
|
|
|
*err = errno;
|
2011-05-09 08:12:26 +00:00
|
|
|
ws_close(fd);
|
2011-05-09 03:48:41 +00:00
|
|
|
g_free(wth);
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-04-14 02:53:18 +00:00
|
|
|
} else {
|
2011-05-09 03:48:41 +00:00
|
|
|
if (!(wth->fh = file_open(filename))) {
|
2011-04-14 02:53:18 +00:00
|
|
|
*err = errno;
|
|
|
|
g_free(wth);
|
|
|
|
return NULL;
|
|
|
|
}
|
1999-09-23 04:39:01 +00:00
|
|
|
}
|
1998-11-12 00:06:47 +00:00
|
|
|
|
2000-05-18 09:09:50 +00:00
|
|
|
if (do_random) {
|
2011-04-06 07:09:56 +00:00
|
|
|
if (!(wth->random_fh = file_open(filename))) {
|
2000-05-18 09:09:50 +00:00
|
|
|
*err = errno;
|
|
|
|
file_close(wth->fh);
|
|
|
|
g_free(wth);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
wth->random_fh = NULL;
|
|
|
|
|
1999-03-01 18:57:07 +00:00
|
|
|
/* initialization */
|
1999-08-22 02:29:40 +00:00
|
|
|
wth->file_encap = WTAP_ENCAP_UNKNOWN;
|
2000-05-25 09:00:24 +00:00
|
|
|
wth->subtype_sequential_close = NULL;
|
2000-03-22 07:06:59 +00:00
|
|
|
wth->subtype_close = NULL;
|
2005-08-24 21:31:56 +00:00
|
|
|
wth->tsprecision = WTAP_FILE_TSPREC_USEC;
|
2010-02-26 07:59:54 +00:00
|
|
|
wth->priv = NULL;
|
2008-05-22 15:46:27 +00:00
|
|
|
|
2013-12-30 06:43:19 +00:00
|
|
|
init_magic_number_open_routines();
|
|
|
|
init_heuristic_open_info();
|
2011-04-12 02:40:14 +00:00
|
|
|
if (wth->random_fh) {
|
|
|
|
wth->fast_seek = g_ptr_array_new();
|
|
|
|
|
|
|
|
file_set_random_access(wth->fh, FALSE, wth->fast_seek);
|
|
|
|
file_set_random_access(wth->random_fh, TRUE, wth->fast_seek);
|
|
|
|
}
|
2008-05-22 15:46:27 +00:00
|
|
|
|
2013-12-30 06:43:19 +00:00
|
|
|
/* Try all file types that support magic numbers */
|
|
|
|
for (i = 0; i < magic_number_open_routines_arr->len; i++) {
|
2001-03-10 06:33:58 +00:00
|
|
|
/* Seek back to the beginning of the file; the open routine
|
|
|
|
for the previous file type may have left the file
|
|
|
|
position somewhere other than the beginning, and the
|
|
|
|
open routine for this file type will probably want
|
|
|
|
to start reading at the beginning.
|
|
|
|
|
|
|
|
Initialize the data offset while we're at it. */
|
2002-06-07 07:27:35 +00:00
|
|
|
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) {
|
2002-03-04 00:25:35 +00:00
|
|
|
/* I/O error - give up */
|
2012-12-26 11:59:47 +00:00
|
|
|
wtap_close(wth);
|
2002-03-04 00:25:35 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2008-05-22 15:46:27 +00:00
|
|
|
|
2013-12-30 06:43:19 +00:00
|
|
|
switch ((*magic_number_open_routines[i])(wth, err, err_info)) {
|
1998-11-12 00:06:47 +00:00
|
|
|
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
case -1:
|
|
|
|
/* I/O error - give up */
|
2012-12-26 11:59:47 +00:00
|
|
|
wtap_close(wth);
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
/* No I/O error, but not that type of file */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
/* We found the file type */
|
|
|
|
goto success;
|
|
|
|
}
|
1999-02-20 06:49:27 +00:00
|
|
|
}
|
1998-11-12 00:06:47 +00:00
|
|
|
|
2013-12-30 06:43:19 +00:00
|
|
|
/* Does this file's name have an extension? */
|
|
|
|
extension = get_file_extension(filename);
|
|
|
|
if (extension != NULL) {
|
|
|
|
/* Yes - try the heuristic types that use that extension first. */
|
|
|
|
for (i = 0; i < heuristic_open_info_arr->len; i++) {
|
|
|
|
/* Does this type use that extension? */
|
|
|
|
if (heuristic_uses_extension(i, extension)) {
|
|
|
|
/* Yes. */
|
|
|
|
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) {
|
|
|
|
/* I/O error - give up */
|
|
|
|
g_free(extension);
|
|
|
|
wtap_close(wth);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ((*heuristic_open_info[i].open_routine)(wth,
|
|
|
|
err, err_info)) {
|
|
|
|
|
|
|
|
case -1:
|
|
|
|
/* I/O error - give up */
|
|
|
|
g_free(extension);
|
|
|
|
wtap_close(wth);
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
/* No I/O error, but not that type of file */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
/* We found the file type */
|
|
|
|
g_free(extension);
|
|
|
|
goto success;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now try the ones that don't use it. */
|
|
|
|
for (i = 0; i < heuristic_open_info_arr->len; i++) {
|
|
|
|
/* Does this type use that extension? */
|
|
|
|
if (!heuristic_uses_extension(i, extension)) {
|
|
|
|
/* No. */
|
|
|
|
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) {
|
|
|
|
/* I/O error - give up */
|
|
|
|
g_free(extension);
|
|
|
|
wtap_close(wth);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ((*heuristic_open_info[i].open_routine)(wth,
|
|
|
|
err, err_info)) {
|
|
|
|
|
|
|
|
case -1:
|
|
|
|
/* I/O error - give up */
|
|
|
|
g_free(extension);
|
|
|
|
wtap_close(wth);
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
/* No I/O error, but not that type of file */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
/* We found the file type */
|
|
|
|
g_free(extension);
|
|
|
|
goto success;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_free(extension);
|
|
|
|
} else {
|
|
|
|
/* No - try all the heuristics types in order. */
|
|
|
|
for (i = 0; i < heuristic_open_info_arr->len; i++) {
|
|
|
|
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) {
|
|
|
|
/* I/O error - give up */
|
|
|
|
wtap_close(wth);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ((*heuristic_open_info[i].open_routine)(wth,
|
|
|
|
err, err_info)) {
|
|
|
|
|
|
|
|
case -1:
|
|
|
|
/* I/O error - give up */
|
|
|
|
wtap_close(wth);
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
/* No I/O error, but not that type of file */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
/* We found the file type */
|
|
|
|
goto success;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
/* Well, it's not one of the types of file we know about. */
|
2011-04-12 02:40:14 +00:00
|
|
|
wtap_close(wth);
|
1999-08-15 06:59:13 +00:00
|
|
|
*err = WTAP_ERR_FILE_UNKNOWN_FORMAT;
|
|
|
|
return NULL;
|
1998-11-12 00:06:47 +00:00
|
|
|
|
|
|
|
success:
|
2010-02-23 02:11:52 +00:00
|
|
|
wth->frame_buffer = (struct Buffer *)g_malloc(sizeof(struct Buffer));
|
1999-03-01 18:57:07 +00:00
|
|
|
buffer_init(wth->frame_buffer, 1500);
|
2012-08-06 11:53:26 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
if(wth->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_PCAP){
|
2012-08-06 11:53:26 +00:00
|
|
|
|
|
|
|
wtapng_if_descr_t descr;
|
|
|
|
|
|
|
|
descr.wtap_encap = wth->file_encap;
|
|
|
|
descr.time_units_per_second = 1000000; /* default microsecond resolution */
|
|
|
|
descr.link_type = wtap_wtap_encap_to_pcap_encap(wth->file_encap);
|
|
|
|
descr.snap_len = wth->snapshot_length;
|
|
|
|
descr.opt_comment = NULL;
|
|
|
|
descr.if_name = NULL;
|
|
|
|
descr.if_description = NULL;
|
|
|
|
descr.if_speed = 0;
|
|
|
|
descr.if_tsresol = 6;
|
|
|
|
descr.if_filter_str= NULL;
|
|
|
|
descr.bpf_filter_len= 0;
|
|
|
|
descr.if_filter_bpf_bytes= NULL;
|
|
|
|
descr.if_os = NULL;
|
|
|
|
descr.if_fcslen = -1;
|
|
|
|
descr.num_stat_entries = 0; /* Number of ISB:s */
|
|
|
|
descr.interface_statistics = NULL;
|
|
|
|
wth->number_of_interfaces= 1;
|
|
|
|
wth->interface_data= g_array_new(FALSE, FALSE, sizeof(wtapng_if_descr_t));
|
|
|
|
g_array_append_val(wth->interface_data, descr);
|
|
|
|
|
|
|
|
}
|
1998-11-12 00:06:47 +00:00
|
|
|
return wth;
|
|
|
|
}
|
Add to Wiretap the ability to write capture files; for now, it can only
write them in "libpcap" format, but the mechanism can have other formats
added.
When creating the temporary file for a capture, use "create_tempfile()",
to close a security hole opened by the fact that "tempnam()" creates a
temporary file, but doesn't open it, and we open the file with the name
it gives us - somebody could remove the file and plant a link to some
file, and, if as may well be the case when Ethereal is capturing
packets, it's running as "root", that means we write a capture on top of
that file.... (The aforementioned changes to Wiretap let you open a
capture file for writing given an file descriptor, "fdopen()"-style,
which this change requires.)
svn path=/trunk/; revision=509
1999-08-18 04:17:38 +00:00
|
|
|
|
2012-06-01 08:45:39 +00:00
|
|
|
/*
|
|
|
|
* Given the pathname of the file we just closed with wtap_fdclose(), attempt
|
|
|
|
* to reopen that file and assign the new file descriptor(s) to the sequential
|
|
|
|
* stream and, if do_random is TRUE, to the random stream. Used on Windows
|
|
|
|
* after the rename of a file we had open was done or if the rename of a
|
|
|
|
* file on top of a file we had open failed.
|
2012-06-01 16:55:10 +00:00
|
|
|
*
|
|
|
|
* This is only required by Wireshark, not TShark, and, at the point that
|
|
|
|
* Wireshark is doing this, the sequential stream is closed, and the
|
|
|
|
* random stream is open, so this refuses to open pipes, and only
|
|
|
|
* reopens the random stream.
|
2012-06-01 08:45:39 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
2012-06-01 16:55:10 +00:00
|
|
|
wtap_fdreopen(wtap *wth, const char *filename, int *err)
|
2012-06-01 08:45:39 +00:00
|
|
|
{
|
|
|
|
ws_statb64 statb;
|
|
|
|
|
2012-06-01 16:55:10 +00:00
|
|
|
/*
|
|
|
|
* We need two independent descriptors for random access, so
|
|
|
|
* they have different file positions. If we're opening the
|
|
|
|
* standard input, we can only dup it to get additional
|
|
|
|
* descriptors, so we can't have two independent descriptors,
|
|
|
|
* and thus can't do random access.
|
|
|
|
*/
|
|
|
|
if (strcmp(filename, "-") == 0) {
|
|
|
|
*err = WTAP_ERR_RANDOM_OPEN_STDIN;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-06-01 08:45:39 +00:00
|
|
|
|
|
|
|
/* First, make sure the file is valid */
|
2012-06-01 16:55:10 +00:00
|
|
|
if (ws_stat64(filename, &statb) < 0) {
|
|
|
|
*err = errno;
|
|
|
|
return FALSE;
|
2012-06-01 08:45:39 +00:00
|
|
|
}
|
|
|
|
if (S_ISFIFO(statb.st_mode)) {
|
|
|
|
/*
|
2012-06-01 16:55:10 +00:00
|
|
|
* Opens of FIFOs are not allowed; see above.
|
2012-06-01 08:45:39 +00:00
|
|
|
*/
|
2012-06-01 16:55:10 +00:00
|
|
|
*err = WTAP_ERR_RANDOM_OPEN_PIPE;
|
|
|
|
return FALSE;
|
2012-06-01 08:45:39 +00:00
|
|
|
} else if (S_ISDIR(statb.st_mode)) {
|
|
|
|
/*
|
|
|
|
* Return different errors for "this is a directory"
|
|
|
|
* and "this is some random special file type", so
|
|
|
|
* the user can get a potentially more helpful error.
|
|
|
|
*/
|
|
|
|
*err = EISDIR;
|
|
|
|
return FALSE;
|
|
|
|
} else if (! S_ISREG(statb.st_mode)) {
|
|
|
|
*err = WTAP_ERR_NOT_REGULAR_FILE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Open the file */
|
|
|
|
errno = WTAP_ERR_CANT_OPEN;
|
2012-06-01 16:55:10 +00:00
|
|
|
if (!file_fdreopen(wth->random_fh, filename)) {
|
|
|
|
*err = errno;
|
|
|
|
return FALSE;
|
2012-06-01 08:45:39 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-03-07 08:03:42 +00:00
|
|
|
/* Table of the file types we know about.
|
2013-11-08 09:53:01 +00:00
|
|
|
Entries must be sorted by WTAP_FILE_TYPE_SUBTYPE_xxx values in ascending order */
|
|
|
|
static const struct file_type_subtype_info dump_open_table_base[] = {
|
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_UNKNOWN (only used internally for initialization) */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ NULL, NULL, NULL, NULL,
|
|
|
|
FALSE, FALSE, 0,
|
1999-12-04 08:32:14 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_PCAP */
|
2011-06-17 17:52:31 +00:00
|
|
|
/* Gianluca Varenni suggests that we add "deprecated" to the description. */
|
2013-07-28 21:12:07 +00:00
|
|
|
{ "Wireshark/tcpdump/... - pcap", "pcap", "pcap", "cap;dmp",
|
2013-04-01 20:36:42 +00:00
|
|
|
FALSE, FALSE, 0,
|
1999-12-04 09:38:38 +00:00
|
|
|
libpcap_dump_can_write_encap, libpcap_dump_open },
|
1999-12-04 08:32:14 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_PCAPNG */
|
2013-07-28 21:12:07 +00:00
|
|
|
{ "Wireshark/... - pcapng", "pcapng", "pcapng", "ntar",
|
2013-04-01 20:36:42 +00:00
|
|
|
FALSE, TRUE, WTAP_COMMENT_PER_SECTION|WTAP_COMMENT_PER_INTERFACE|WTAP_COMMENT_PER_PACKET,
|
2012-01-14 09:12:05 +00:00
|
|
|
pcapng_dump_can_write_encap, pcapng_dump_open },
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "Wireshark - nanosecond libpcap", "nseclibpcap", "pcap", "cap;dmp",
|
|
|
|
FALSE, FALSE, 0,
|
Provide different file types for "modified" and Red Hat 6.1 "libpcap"
files (the former have a different per-packet header, and a different
magic number, from the standard "libpcap"; the latter have the same
per-packet header as "modified" "libpcap" files, but the same magic
number as standard "libpcap" files, sigh).
Support writing "libpcap" captures in all three formats (so that, for
example, people running Ethereal on RH 6.1 can write out captures that
the "tcpdump" that comes with RH 6.1 can read, although that's not the
default format we save in - there's no way to tell whether you're
running on RH 6.1, as far as I know; "uname()" just tells you, on Linux
systems, that the kernel is Linux 2.x, and what "x" is, it doesn't say
what the *rest* of the system is).
Fix the table in "file.c" to use Olivier's code for writing Sniffer
files.
svn path=/trunk/; revision=1288
1999-12-11 00:40:40 +00:00
|
|
|
libpcap_dump_can_write_encap, libpcap_dump_open },
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_PCAP_AIX */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "AIX tcpdump - libpcap", "aixlibpcap", "pcap", "cap;dmp",
|
|
|
|
FALSE, FALSE, 0,
|
2006-06-23 18:20:34 +00:00
|
|
|
NULL, NULL },
|
2000-07-26 06:04:34 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_PCAP_SS991029 */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "Modified tcpdump - libpcap", "modlibpcap", "pcap", "cap;dmp",
|
|
|
|
FALSE, FALSE, 0,
|
Provide different file types for "modified" and Red Hat 6.1 "libpcap"
files (the former have a different per-packet header, and a different
magic number, from the standard "libpcap"; the latter have the same
per-packet header as "modified" "libpcap" files, but the same magic
number as standard "libpcap" files, sigh).
Support writing "libpcap" captures in all three formats (so that, for
example, people running Ethereal on RH 6.1 can write out captures that
the "tcpdump" that comes with RH 6.1 can read, although that's not the
default format we save in - there's no way to tell whether you're
running on RH 6.1, as far as I know; "uname()" just tells you, on Linux
systems, that the kernel is Linux 2.x, and what "x" is, it doesn't say
what the *rest* of the system is).
Fix the table in "file.c" to use Olivier's code for writing Sniffer
files.
svn path=/trunk/; revision=1288
1999-12-11 00:40:40 +00:00
|
|
|
libpcap_dump_can_write_encap, libpcap_dump_open },
|
1999-12-04 08:32:14 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_PCAP_NOKIA */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "Nokia tcpdump - libpcap ", "nokialibpcap", "pcap", "cap;dmp",
|
|
|
|
FALSE, FALSE, 0,
|
2000-09-15 07:52:43 +00:00
|
|
|
libpcap_dump_can_write_encap, libpcap_dump_open },
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_PCAP_SS990417 */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "RedHat 6.1 tcpdump - libpcap", "rh6_1libpcap", "pcap", "cap;dmp",
|
|
|
|
FALSE, FALSE, 0,
|
2005-08-30 09:43:47 +00:00
|
|
|
libpcap_dump_can_write_encap, libpcap_dump_open },
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_PCAP_SS990915 */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "SuSE 6.3 tcpdump - libpcap", "suse6_3libpcap", "pcap", "cap;dmp",
|
|
|
|
FALSE, FALSE, 0,
|
2006-06-23 18:20:34 +00:00
|
|
|
libpcap_dump_can_write_encap, libpcap_dump_open },
|
1999-12-04 08:32:14 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_5VIEWS */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "InfoVista 5View capture", "5views", "5vw", NULL,
|
|
|
|
TRUE, FALSE, 0,
|
2006-06-23 18:20:34 +00:00
|
|
|
_5views_dump_can_write_encap, _5views_dump_open },
|
2002-12-05 22:33:11 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_IPTRACE_1_0 */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "AIX iptrace 1.0", "iptrace_1", NULL, NULL,
|
|
|
|
FALSE, FALSE, 0,
|
1999-12-04 08:32:14 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_IPTRACE_2_0 */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "AIX iptrace 2.0", "iptrace_2", NULL, NULL,
|
|
|
|
FALSE, FALSE, 0,
|
1999-12-04 08:32:14 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_BER */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "ASN.1 Basic Encoding Rules", "ber", NULL, NULL,
|
|
|
|
FALSE, FALSE, 0,
|
|
|
|
NULL, NULL },
|
1999-12-04 08:32:14 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_HCIDUMP */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "Bluetooth HCI dump", "hcidump", NULL, NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2006-06-23 18:20:34 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_CATAPULT_DCT2000 */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "Catapult DCT2000 trace (.out format)", "dct2000", "out", NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2006-06-23 18:20:34 +00:00
|
|
|
catapult_dct2000_dump_can_write_encap, catapult_dct2000_dump_open },
|
1999-12-04 08:32:14 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_NETXRAY_OLD */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "Cinco Networks NetXRay 1.x", "netxray1", "cap", NULL,
|
|
|
|
TRUE, FALSE, 0,
|
2002-05-28 02:39:15 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_NETXRAY_1_0 */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "Cinco Networks NetXRay 2.0 or later", "netxray2", "cap", NULL,
|
|
|
|
TRUE, FALSE, 0,
|
1999-12-04 08:32:14 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_COSINE */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "CoSine IPSX L2 capture", "cosine", "txt", NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2006-06-23 18:20:34 +00:00
|
|
|
NULL, NULL },
|
1999-12-04 08:32:14 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_CSIDS */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "CSIDS IPLog", "csids", NULL, NULL,
|
|
|
|
FALSE, FALSE, 0,
|
1999-12-04 08:32:14 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_DBS_ETHERWATCH */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "DBS Etherwatch (VMS)", "etherwatch", "txt", NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2006-06-23 18:20:34 +00:00
|
|
|
NULL, NULL},
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_ERF */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "Endace ERF capture", "erf", "erf", NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2011-08-31 20:50:15 +00:00
|
|
|
erf_dump_can_write_encap, erf_dump_open },
|
1999-12-04 08:32:14 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_EYESDN */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "EyeSDN USB S0/E1 ISDN trace format", "eyesdn", "trc", NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2010-06-05 22:59:20 +00:00
|
|
|
eyesdn_dump_can_write_encap, eyesdn_dump_open },
|
2008-05-22 15:46:27 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_NETTL */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "HP-UX nettl trace", "nettl", "trc0", "trc1",
|
|
|
|
FALSE, FALSE, 0,
|
2004-10-11 07:18:20 +00:00
|
|
|
nettl_dump_can_write_encap, nettl_dump_open },
|
1999-12-04 08:32:14 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_ISERIES */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "IBM iSeries comm. trace (ASCII)", "iseries_ascii", "txt", NULL,
|
|
|
|
FALSE, FALSE, 0,
|
1999-12-12 22:40:10 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_ISERIES_UNICODE */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "IBM iSeries comm. trace (UNICODE)", "iseries_unicode", "txt", NULL,
|
|
|
|
FALSE, FALSE, 0,
|
1999-12-12 22:40:10 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_I4BTRACE */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "I4B ISDN trace", "i4btrace", NULL, NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2001-02-22 22:03:31 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_ASCEND */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "Lucent/Ascend access server trace", "ascend", "txt", NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2001-02-22 22:03:31 +00:00
|
|
|
NULL, NULL },
|
2001-10-18 20:29:56 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_NETMON_1_x */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "Microsoft NetMon 1.x", "netmon1", "cap", NULL,
|
|
|
|
TRUE, FALSE, 0,
|
2012-01-14 10:31:25 +00:00
|
|
|
netmon_dump_can_write_encap_1_x, netmon_dump_open },
|
2001-10-19 20:18:48 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_NETMON_2_x */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "Microsoft NetMon 2.x", "netmon2", "cap", NULL,
|
|
|
|
TRUE, FALSE, 0,
|
2012-01-14 10:31:25 +00:00
|
|
|
netmon_dump_can_write_encap_2_x, netmon_dump_open },
|
2001-12-04 22:28:19 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_NGSNIFFER_UNCOMPRESSED */
|
2013-08-27 20:46:47 +00:00
|
|
|
{ "Sniffer (DOS)", "ngsniffer", "cap", "enc;trc;fdc;syc",
|
2013-04-01 20:36:42 +00:00
|
|
|
FALSE, FALSE, 0,
|
2006-06-23 18:20:34 +00:00
|
|
|
ngsniffer_dump_can_write_encap, ngsniffer_dump_open },
|
2002-07-31 19:27:57 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_NGSNIFFER_COMPRESSED */
|
2013-08-27 20:46:47 +00:00
|
|
|
{ "Sniffer (DOS), compressed", "ngsniffer_comp", "cap", "enc;trc;fdc;syc",
|
2013-04-01 20:36:42 +00:00
|
|
|
FALSE, FALSE, 0,
|
2002-07-31 19:27:57 +00:00
|
|
|
NULL, NULL },
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_NETXRAY_1_1 */
|
2013-08-27 20:46:47 +00:00
|
|
|
{ "NetXray, Sniffer (Windows) 1.1", "ngwsniffer_1_1", "cap", NULL,
|
2013-04-01 20:36:42 +00:00
|
|
|
TRUE, FALSE, 0,
|
2006-06-23 18:20:34 +00:00
|
|
|
netxray_dump_can_write_encap_1_1, netxray_dump_open_1_1 },
|
2003-08-26 07:10:39 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_NETXRAY_2_00x */
|
2013-08-27 20:46:47 +00:00
|
|
|
{ "Sniffer (Windows) 2.00x", "ngwsniffer_2_0", "cap", "caz",
|
2013-04-01 20:36:42 +00:00
|
|
|
TRUE, FALSE, 0,
|
2006-06-23 18:20:34 +00:00
|
|
|
netxray_dump_can_write_encap_2_0, netxray_dump_open_2_0 },
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_NETWORK_INSTRUMENTS */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "Network Instruments Observer", "niobserver", "bfr", NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2006-06-23 18:20:34 +00:00
|
|
|
network_instruments_dump_can_write_encap, network_instruments_dump_open },
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_LANALYZER */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "Novell LANalyzer","lanalyzer", "tr1", NULL,
|
|
|
|
TRUE, FALSE, 0,
|
2006-06-23 18:20:34 +00:00
|
|
|
lanalyzer_dump_can_write_encap, lanalyzer_dump_open },
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_PPPDUMP */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "pppd log (pppdump format)", "pppd", NULL, NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2003-08-26 07:10:39 +00:00
|
|
|
NULL, NULL },
|
2003-10-30 03:11:03 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_RADCOM */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "RADCOM WAN/LAN analyzer", "radcom", NULL, NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2003-10-30 03:11:03 +00:00
|
|
|
NULL, NULL },
|
2003-10-31 00:43:21 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_SNOOP */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "Sun snoop", "snoop", "snoop", "cap",
|
|
|
|
FALSE, FALSE, 0,
|
2006-06-23 18:20:34 +00:00
|
|
|
snoop_dump_can_write_encap, snoop_dump_open },
|
2003-12-02 19:37:05 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_SHOMITI */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "Shomiti/Finisar Surveyor", "shomiti", "cap", NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2003-12-02 19:37:05 +00:00
|
|
|
NULL, NULL },
|
2006-06-23 18:20:34 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_VMS */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "TCPIPtrace (VMS)", "tcpiptrace", "txt", NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2006-06-23 18:20:34 +00:00
|
|
|
NULL, NULL},
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_K12 */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "Tektronix K12xx 32-bit .rf5 format", "rf5", "rf5", NULL,
|
|
|
|
TRUE, FALSE, 0,
|
|
|
|
k12_dump_can_write_encap, k12_dump_open },
|
2005-11-25 20:30:42 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_TOSHIBA */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "Toshiba Compact ISDN Router snoop", "toshiba", "txt", NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2005-11-25 20:30:42 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_VISUAL_NETWORKS */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "Visual Networks traffic capture", "visual", NULL, NULL,
|
|
|
|
TRUE, FALSE, 0,
|
2006-06-23 18:20:34 +00:00
|
|
|
visual_dump_can_write_encap, visual_dump_open },
|
2005-11-25 20:30:42 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_PEEKCLASSIC_V56 */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "WildPackets classic (V5 and V6)", "peekclassic56", "pkt", "tpc;apc;wpz",
|
|
|
|
FALSE, FALSE, 0,
|
2006-06-23 18:20:34 +00:00
|
|
|
NULL, NULL },
|
2006-05-08 19:56:36 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_PEEKCLASSIC_V7 */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "WildPackets classic (V7)", "peekclassic7", "pkt", "tpc;apc;wpz",
|
|
|
|
FALSE, FALSE, 0,
|
2006-06-23 18:20:34 +00:00
|
|
|
NULL, NULL },
|
2006-05-08 19:56:36 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_PEEKTAGGED */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "WildPackets tagged", "peektagged", "pkt", "tpc;apc;wpz",
|
|
|
|
FALSE, FALSE, 0,
|
2006-06-23 18:20:34 +00:00
|
|
|
NULL, NULL },
|
2008-05-22 15:46:27 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_MPEG */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "MPEG", "mpeg", "mpeg", "mpg;mp3",
|
|
|
|
FALSE, FALSE, 0,
|
2007-03-22 10:44:33 +00:00
|
|
|
NULL, NULL },
|
2007-05-02 20:09:42 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_K12TEXT */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "K12 text file", "k12text", "txt", NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2007-05-02 20:09:42 +00:00
|
|
|
k12text_dump_can_write_encap, k12text_dump_open },
|
2007-08-17 08:03:32 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_NETSCREEN */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "NetScreen snoop text file", "netscreen", "txt", NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2007-08-17 08:03:32 +00:00
|
|
|
NULL, NULL },
|
2007-11-24 03:33:18 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_COMMVIEW */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "TamoSoft CommView", "commview", "ncf", NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2008-01-13 20:05:07 +00:00
|
|
|
commview_dump_can_write_encap, commview_dump_open },
|
2008-05-22 15:46:27 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_BTSNOOP */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "Symbian OS btsnoop", "btsnoop", "log", NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2009-05-22 00:05:19 +00:00
|
|
|
btsnoop_dump_can_write_encap, btsnoop_dump_open_h4 },
|
2010-10-20 00:36:53 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_TNEF */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "Transport-Neutral Encapsulation Format", "tnef", NULL, NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2011-03-24 22:47:57 +00:00
|
|
|
NULL, NULL },
|
2009-01-07 07:21:31 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_DCT3TRACE */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "Gammu DCT3 trace", "dct3trace", "xml", NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2011-03-24 22:47:57 +00:00
|
|
|
NULL, NULL },
|
2009-04-23 09:13:56 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_PACKETLOGGER */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "PacketLogger", "pklg", "pklg", NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2011-03-24 22:47:57 +00:00
|
|
|
NULL, NULL },
|
2009-05-24 22:49:36 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_DAINTREE_SNA */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "Daintree SNA", "dsna", "dcf", NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2011-03-24 22:47:57 +00:00
|
|
|
NULL, NULL },
|
2009-06-01 17:23:38 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_NETSCALER_1_0 */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "NetScaler Trace (Version 1.0)", "nstrace10", NULL, NULL,
|
|
|
|
TRUE, FALSE, 0,
|
2009-06-01 17:23:38 +00:00
|
|
|
nstrace_10_dump_can_write_encap, nstrace_dump_open },
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_NETSCALER_2_0 */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "NetScaler Trace (Version 2.0)", "nstrace20", "cap", NULL,
|
|
|
|
TRUE, FALSE, 0,
|
2009-06-01 17:23:38 +00:00
|
|
|
nstrace_20_dump_can_write_encap, nstrace_dump_open },
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_JPEG_JFIF */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "JPEG/JFIF", "jpeg", "jpg", "jpeg;jfif",
|
|
|
|
FALSE, FALSE, 0,
|
2011-03-24 22:47:57 +00:00
|
|
|
NULL, NULL },
|
2009-10-17 20:56:06 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_IPFIX */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "IPFIX File Format", "ipfix", "pfx", "ipfix",
|
|
|
|
FALSE, FALSE, 0,
|
2011-06-10 07:16:10 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
|
|
|
/* WTAP_ENCAP_MIME */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "MIME File Format", "mime", NULL, NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2011-10-26 02:18:55 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_AETHRA */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "Aethra .aps file", "aethra", "aps", NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2011-10-26 02:18:55 +00:00
|
|
|
NULL, NULL },
|
2012-03-07 08:03:42 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_MPEG_2_TS */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "MPEG2 transport stream", "mp2t", "mp2t", "ts;mpg",
|
|
|
|
FALSE, FALSE, 0,
|
2012-04-20 12:08:31 +00:00
|
|
|
NULL, NULL },
|
2012-10-12 21:37:02 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_VWR_80211 */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "Ixia IxVeriWave .vwr Raw 802.11 Capture", "vwr80211", "vwr", NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2012-04-20 12:08:31 +00:00
|
|
|
NULL, NULL },
|
2012-10-12 21:37:02 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_VWR_ETH */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "Ixia IxVeriWave .vwr Raw Ethernet Capture", "vwreth", "vwr", NULL,
|
|
|
|
FALSE, FALSE, 0,
|
2013-03-30 09:56:57 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_CAMINS */
|
2013-04-01 20:36:42 +00:00
|
|
|
{ "CAM Inspector file", "camins", "camins", NULL,
|
2013-07-28 23:41:18 +00:00
|
|
|
FALSE, FALSE, 0,
|
|
|
|
NULL, NULL },
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* WTAP_FILE_TYPE_SUBTYPE_STANAG_4607 */
|
2013-07-28 23:41:18 +00:00
|
|
|
{ "STANAG 4607 Format", "stanag4607", NULL, NULL,
|
2013-04-01 20:36:42 +00:00
|
|
|
FALSE, FALSE, 0,
|
2013-10-28 04:07:52 +00:00
|
|
|
NULL, NULL }
|
2013-07-28 23:41:18 +00:00
|
|
|
|
1999-12-04 08:32:14 +00:00
|
|
|
};
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
gint wtap_num_file_types_subtypes = sizeof(dump_open_table_base) / sizeof(struct file_type_subtype_info);
|
2007-06-06 20:56:38 +00:00
|
|
|
|
|
|
|
static GArray* dump_open_table_arr = NULL;
|
2013-11-08 09:53:01 +00:00
|
|
|
static const struct file_type_subtype_info* dump_open_table = dump_open_table_base;
|
2007-06-06 20:56:38 +00:00
|
|
|
|
2013-08-27 20:46:47 +00:00
|
|
|
/* initialize the file types array if it has not being initialized yet */
|
2013-11-08 09:53:01 +00:00
|
|
|
static void init_file_types_subtypes(void) {
|
2008-05-22 15:46:27 +00:00
|
|
|
|
2007-06-06 20:56:38 +00:00
|
|
|
if (dump_open_table_arr) return;
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
dump_open_table_arr = g_array_new(FALSE,TRUE,sizeof(struct file_type_subtype_info));
|
2008-05-22 15:46:27 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
g_array_append_vals(dump_open_table_arr,dump_open_table_base,wtap_num_file_types_subtypes);
|
2008-05-22 15:46:27 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
dump_open_table = (const struct file_type_subtype_info*)(void *)dump_open_table_arr->data;
|
2007-06-06 20:56:38 +00:00
|
|
|
}
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
int wtap_register_file_type_subtypes(const struct file_type_subtype_info* fi) {
|
|
|
|
init_file_types_subtypes();
|
2007-06-06 20:56:38 +00:00
|
|
|
|
|
|
|
g_array_append_val(dump_open_table_arr,*fi);
|
2008-05-22 15:46:27 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
dump_open_table = (const struct file_type_subtype_info*)(void *)dump_open_table_arr->data;
|
2008-05-22 15:46:27 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
return wtap_num_file_types_subtypes++;
|
2007-06-06 20:56:38 +00:00
|
|
|
}
|
2007-05-04 21:10:55 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
int wtap_get_num_file_types_subtypes(void)
|
2007-05-05 10:47:35 +00:00
|
|
|
{
|
2013-11-08 09:53:01 +00:00
|
|
|
return wtap_num_file_types_subtypes;
|
2007-05-05 10:47:35 +00:00
|
|
|
}
|
|
|
|
|
Add a routine that, given a set of packet encapsulation types, returns
the per-file encapsulation type needed to write out a set of packets
with all those encapsulation types. If there's only one such
encapsulation type, that's the type, otherwise WTAP_ENCAP_PER_PACKET is
needed. Use that in wtap_dump_can_write_encaps().
Also use it in cf_save_packets() and cf_export_specified_packets(), so
that we can write out files with WTAP_ENCAP_PER_PACKET as the file
encapsulation type and only one actual per-packet encapsulation type in
some cases where that failed before. This fixes the case that showed up
in bug 7505, although there are other cases where we *could* write out a
capture in a given file format but won't be able to do so; fixing those
will take more work.
#BACKPORT
(Note: this adds a routine to libwiretap, so, when backported, the
*minor* version of the library should be increased. Code that worked
with the version of the library prior to this change will continue to
work, so there's no need to change the *major* version of the library.)
svn path=/trunk/; revision=43847
2012-07-20 04:00:29 +00:00
|
|
|
/*
|
|
|
|
* Given a GArray of WTAP_ENCAP_ types, return the per-file encapsulation
|
|
|
|
* type that would be needed to write out a file with those types. If
|
|
|
|
* there's only one type, it's that type, otherwise it's
|
|
|
|
* WTAP_ENCAP_PER_PACKET.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
wtap_dump_file_encap_type(const GArray *file_encaps)
|
|
|
|
{
|
|
|
|
int encap;
|
|
|
|
|
|
|
|
encap = WTAP_ENCAP_PER_PACKET;
|
|
|
|
if (file_encaps->len == 1) {
|
|
|
|
/* OK, use the one-and-only encapsulation type. */
|
|
|
|
encap = g_array_index(file_encaps, gint, 0);
|
|
|
|
}
|
|
|
|
return encap;
|
|
|
|
}
|
|
|
|
|
2013-04-01 21:39:28 +00:00
|
|
|
static gboolean
|
|
|
|
wtap_dump_can_write_encap(int filetype, int encap)
|
|
|
|
{
|
2013-11-08 09:53:01 +00:00
|
|
|
if (filetype < 0 || filetype >= wtap_num_file_types_subtypes
|
2013-04-01 21:39:28 +00:00
|
|
|
|| dump_open_table[filetype].can_write_encap == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if ((*dump_open_table[filetype].can_write_encap)(encap) != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-01-24 04:33:23 +00:00
|
|
|
/*
|
2013-04-01 21:17:50 +00:00
|
|
|
* Return TRUE if a capture with a given GArray of encapsulation types
|
|
|
|
* and a given bitset of comment types can be written in a specified
|
|
|
|
* format, and FALSE if it can't.
|
2012-01-24 04:33:23 +00:00
|
|
|
*/
|
2013-04-01 21:17:50 +00:00
|
|
|
static gboolean
|
|
|
|
wtap_dump_can_write_format(int ft, const GArray *file_encaps,
|
|
|
|
guint32 required_comment_types)
|
2012-01-24 04:33:23 +00:00
|
|
|
{
|
2012-06-17 01:32:50 +00:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Can we write in this format?
|
|
|
|
*/
|
|
|
|
if (!wtap_dump_can_open(ft)) {
|
|
|
|
/* No. */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-01-24 04:33:23 +00:00
|
|
|
/*
|
2013-04-01 21:17:50 +00:00
|
|
|
* Yes. Can we write out all the required comments in this
|
|
|
|
* format?
|
|
|
|
*/
|
|
|
|
if (!wtap_dump_supports_comment_types(ft, required_comment_types)) {
|
|
|
|
/* No. */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Yes. Is the required per-file encapsulation type supported?
|
Add a routine that, given a set of packet encapsulation types, returns
the per-file encapsulation type needed to write out a set of packets
with all those encapsulation types. If there's only one such
encapsulation type, that's the type, otherwise WTAP_ENCAP_PER_PACKET is
needed. Use that in wtap_dump_can_write_encaps().
Also use it in cf_save_packets() and cf_export_specified_packets(), so
that we can write out files with WTAP_ENCAP_PER_PACKET as the file
encapsulation type and only one actual per-packet encapsulation type in
some cases where that failed before. This fixes the case that showed up
in bug 7505, although there are other cases where we *could* write out a
capture in a given file format but won't be able to do so; fixing those
will take more work.
#BACKPORT
(Note: this adds a routine to libwiretap, so, when backported, the
*minor* version of the library should be increased. Code that worked
with the version of the library prior to this change will continue to
work, so there's no need to change the *major* version of the library.)
svn path=/trunk/; revision=43847
2012-07-20 04:00:29 +00:00
|
|
|
* This might be WTAP_ENCAP_PER_PACKET.
|
|
|
|
*/
|
2013-04-01 21:17:50 +00:00
|
|
|
if (!wtap_dump_can_write_encap(ft, wtap_dump_file_encap_type(file_encaps))) {
|
|
|
|
/* No. */
|
Add a routine that, given a set of packet encapsulation types, returns
the per-file encapsulation type needed to write out a set of packets
with all those encapsulation types. If there's only one such
encapsulation type, that's the type, otherwise WTAP_ENCAP_PER_PACKET is
needed. Use that in wtap_dump_can_write_encaps().
Also use it in cf_save_packets() and cf_export_specified_packets(), so
that we can write out files with WTAP_ENCAP_PER_PACKET as the file
encapsulation type and only one actual per-packet encapsulation type in
some cases where that failed before. This fixes the case that showed up
in bug 7505, although there are other cases where we *could* write out a
capture in a given file format but won't be able to do so; fixing those
will take more work.
#BACKPORT
(Note: this adds a routine to libwiretap, so, when backported, the
*minor* version of the library should be increased. Code that worked
with the version of the library prior to this change will continue to
work, so there's no need to change the *major* version of the library.)
svn path=/trunk/; revision=43847
2012-07-20 04:00:29 +00:00
|
|
|
return FALSE;
|
2013-04-01 21:17:50 +00:00
|
|
|
}
|
2012-10-12 21:37:02 +00:00
|
|
|
|
Add a routine that, given a set of packet encapsulation types, returns
the per-file encapsulation type needed to write out a set of packets
with all those encapsulation types. If there's only one such
encapsulation type, that's the type, otherwise WTAP_ENCAP_PER_PACKET is
needed. Use that in wtap_dump_can_write_encaps().
Also use it in cf_save_packets() and cf_export_specified_packets(), so
that we can write out files with WTAP_ENCAP_PER_PACKET as the file
encapsulation type and only one actual per-packet encapsulation type in
some cases where that failed before. This fixes the case that showed up
in bug 7505, although there are other cases where we *could* write out a
capture in a given file format but won't be able to do so; fixing those
will take more work.
#BACKPORT
(Note: this adds a routine to libwiretap, so, when backported, the
*minor* version of the library should be increased. Code that worked
with the version of the library prior to this change will continue to
work, so there's no need to change the *major* version of the library.)
svn path=/trunk/; revision=43847
2012-07-20 04:00:29 +00:00
|
|
|
/*
|
|
|
|
* Yes. Are all the individual encapsulation types supported?
|
2012-01-24 04:33:23 +00:00
|
|
|
*/
|
2012-06-17 01:32:50 +00:00
|
|
|
for (i = 0; i < file_encaps->len; i++) {
|
|
|
|
if (!wtap_dump_can_write_encap(ft,
|
Add a routine that, given a set of packet encapsulation types, returns
the per-file encapsulation type needed to write out a set of packets
with all those encapsulation types. If there's only one such
encapsulation type, that's the type, otherwise WTAP_ENCAP_PER_PACKET is
needed. Use that in wtap_dump_can_write_encaps().
Also use it in cf_save_packets() and cf_export_specified_packets(), so
that we can write out files with WTAP_ENCAP_PER_PACKET as the file
encapsulation type and only one actual per-packet encapsulation type in
some cases where that failed before. This fixes the case that showed up
in bug 7505, although there are other cases where we *could* write out a
capture in a given file format but won't be able to do so; fixing those
will take more work.
#BACKPORT
(Note: this adds a routine to libwiretap, so, when backported, the
*minor* version of the library should be increased. Code that worked
with the version of the library prior to this change will continue to
work, so there's no need to change the *major* version of the library.)
svn path=/trunk/; revision=43847
2012-07-20 04:00:29 +00:00
|
|
|
g_array_index(file_encaps, int, i))) {
|
|
|
|
/* No - one of them isn't. */
|
2012-06-17 01:32:50 +00:00
|
|
|
return FALSE;
|
Add a routine that, given a set of packet encapsulation types, returns
the per-file encapsulation type needed to write out a set of packets
with all those encapsulation types. If there's only one such
encapsulation type, that's the type, otherwise WTAP_ENCAP_PER_PACKET is
needed. Use that in wtap_dump_can_write_encaps().
Also use it in cf_save_packets() and cf_export_specified_packets(), so
that we can write out files with WTAP_ENCAP_PER_PACKET as the file
encapsulation type and only one actual per-packet encapsulation type in
some cases where that failed before. This fixes the case that showed up
in bug 7505, although there are other cases where we *could* write out a
capture in a given file format but won't be able to do so; fixing those
will take more work.
#BACKPORT
(Note: this adds a routine to libwiretap, so, when backported, the
*minor* version of the library should be increased. Code that worked
with the version of the library prior to this change will continue to
work, so there's no need to change the *major* version of the library.)
svn path=/trunk/; revision=43847
2012-07-20 04:00:29 +00:00
|
|
|
}
|
2012-06-17 01:32:50 +00:00
|
|
|
}
|
Add a routine that, given a set of packet encapsulation types, returns
the per-file encapsulation type needed to write out a set of packets
with all those encapsulation types. If there's only one such
encapsulation type, that's the type, otherwise WTAP_ENCAP_PER_PACKET is
needed. Use that in wtap_dump_can_write_encaps().
Also use it in cf_save_packets() and cf_export_specified_packets(), so
that we can write out files with WTAP_ENCAP_PER_PACKET as the file
encapsulation type and only one actual per-packet encapsulation type in
some cases where that failed before. This fixes the case that showed up
in bug 7505, although there are other cases where we *could* write out a
capture in a given file format but won't be able to do so; fixing those
will take more work.
#BACKPORT
(Note: this adds a routine to libwiretap, so, when backported, the
*minor* version of the library should be increased. Code that worked
with the version of the library prior to this change will continue to
work, so there's no need to change the *major* version of the library.)
svn path=/trunk/; revision=43847
2012-07-20 04:00:29 +00:00
|
|
|
|
|
|
|
/* Yes - we're OK. */
|
2012-06-17 01:32:50 +00:00
|
|
|
return TRUE;
|
2012-01-24 04:33:23 +00:00
|
|
|
}
|
|
|
|
|
2013-04-01 21:17:50 +00:00
|
|
|
/**
|
|
|
|
* Return TRUE if we can write a file with the given GArray of
|
|
|
|
* encapsulation types and the given bitmask of comment types.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
wtap_dump_can_write(const GArray *file_encaps, guint32 required_comment_types)
|
|
|
|
{
|
|
|
|
int ft;
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
for (ft = 0; ft < WTAP_NUM_FILE_TYPES_SUBTYPES; ft++) {
|
2013-04-01 21:17:50 +00:00
|
|
|
/* To save a file with Wiretap, Wiretap has to handle that format,
|
|
|
|
and its code to handle that format must be able to write a file
|
|
|
|
with this file's encapsulation types. */
|
|
|
|
if (wtap_dump_can_write_format(ft, file_encaps, required_comment_types)) {
|
|
|
|
/* OK, we can write it out in this type. */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No, we couldn't save it in any format. */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-04-01 20:36:42 +00:00
|
|
|
/**
|
2013-11-08 09:53:01 +00:00
|
|
|
* Get a GArray of WTAP_FILE_TYPE_SUBTYPE_ values for file types/subtypes
|
|
|
|
* that can be used to save a file of a given type/subtype with a given
|
|
|
|
* GArray of encapsulation types and the given bitmask of comment types.
|
2012-06-17 16:44:09 +00:00
|
|
|
*/
|
2012-01-24 04:33:23 +00:00
|
|
|
GArray *
|
2013-11-08 09:53:01 +00:00
|
|
|
wtap_get_savable_file_types_subtypes(int file_type_subtype,
|
|
|
|
const GArray *file_encaps, guint32 required_comment_types)
|
2012-01-24 04:33:23 +00:00
|
|
|
{
|
2013-11-08 09:53:01 +00:00
|
|
|
GArray *savable_file_types_subtypes;
|
2012-01-24 04:33:23 +00:00
|
|
|
int ft;
|
2013-11-08 09:53:01 +00:00
|
|
|
int default_file_type_subtype = -1;
|
|
|
|
int other_file_type_subtype = -1;
|
2012-01-24 04:33:23 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* Can we save this file in its own file type/subtype? */
|
|
|
|
if (wtap_dump_can_write_format(file_type_subtype, file_encaps,
|
2013-04-01 21:17:50 +00:00
|
|
|
required_comment_types)) {
|
2013-11-08 09:53:01 +00:00
|
|
|
/* Yes - make that the default file type/subtype. */
|
|
|
|
default_file_type_subtype = file_type_subtype;
|
2012-01-24 04:33:23 +00:00
|
|
|
} else {
|
2013-11-08 09:53:01 +00:00
|
|
|
/* OK, find the first file type/subtype we *can* save it as. */
|
|
|
|
default_file_type_subtype = -1;
|
|
|
|
for (ft = 0; ft < WTAP_NUM_FILE_TYPES_SUBTYPES; ft++) {
|
2013-04-01 21:17:50 +00:00
|
|
|
if (wtap_dump_can_write_format(ft, file_encaps,
|
|
|
|
required_comment_types)) {
|
2013-04-01 20:36:42 +00:00
|
|
|
/* OK, got it. */
|
2013-11-08 09:53:01 +00:00
|
|
|
default_file_type_subtype = ft;
|
2012-01-24 04:33:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
if (default_file_type_subtype == -1) {
|
|
|
|
/* We don't support writing this file as any file type/subtype. */
|
2012-01-24 04:33:23 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate the array. */
|
2013-11-08 09:53:01 +00:00
|
|
|
savable_file_types_subtypes = g_array_new(FALSE, FALSE, (guint)sizeof (int));
|
2012-01-24 04:33:23 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* Put the default file type/subtype first in the list. */
|
|
|
|
g_array_append_val(savable_file_types_subtypes, default_file_type_subtype);
|
2012-01-24 04:33:23 +00:00
|
|
|
|
2013-04-01 20:36:42 +00:00
|
|
|
/* If the default is pcap, put pcap-NG right after it if we can
|
|
|
|
also write it in pcap-NG format; otherwise, if the default is
|
|
|
|
pcap-NG, put pcap right after it if we can also write it in
|
|
|
|
pcap format. */
|
2013-11-08 09:53:01 +00:00
|
|
|
if (default_file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_PCAP) {
|
|
|
|
if (wtap_dump_can_write_format(WTAP_FILE_TYPE_SUBTYPE_PCAPNG, file_encaps,
|
2013-04-01 21:17:50 +00:00
|
|
|
required_comment_types))
|
2013-11-08 09:53:01 +00:00
|
|
|
other_file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_PCAPNG;
|
|
|
|
} else if (default_file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_PCAPNG) {
|
|
|
|
if (wtap_dump_can_write_format(WTAP_FILE_TYPE_SUBTYPE_PCAP, file_encaps,
|
2013-04-01 21:17:50 +00:00
|
|
|
required_comment_types))
|
2013-11-08 09:53:01 +00:00
|
|
|
other_file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_PCAP;
|
2012-01-24 04:33:23 +00:00
|
|
|
}
|
2013-11-08 09:53:01 +00:00
|
|
|
if (other_file_type_subtype != -1)
|
|
|
|
g_array_append_val(savable_file_types_subtypes, other_file_type_subtype);
|
2012-01-24 04:33:23 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* Add all the other file types/subtypes that work. */
|
|
|
|
for (ft = 0; ft < WTAP_NUM_FILE_TYPES_SUBTYPES; ft++) {
|
|
|
|
if (ft == WTAP_FILE_TYPE_SUBTYPE_UNKNOWN)
|
2012-01-24 04:33:23 +00:00
|
|
|
continue; /* not a real file type */
|
2013-11-08 09:53:01 +00:00
|
|
|
if (ft == default_file_type_subtype || ft == other_file_type_subtype)
|
2012-01-24 04:33:23 +00:00
|
|
|
continue; /* we've already done this one */
|
2013-04-01 21:17:50 +00:00
|
|
|
if (wtap_dump_can_write_format(ft, file_encaps,
|
|
|
|
required_comment_types)) {
|
2012-01-24 04:33:23 +00:00
|
|
|
/* OK, we can write it out in this type. */
|
2013-11-08 09:53:01 +00:00
|
|
|
g_array_append_val(savable_file_types_subtypes, ft);
|
2012-01-24 04:33:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
return savable_file_types_subtypes;
|
2012-01-24 04:33:23 +00:00
|
|
|
}
|
|
|
|
|
1999-12-04 21:20:09 +00:00
|
|
|
/* Name that should be somewhat descriptive. */
|
2013-11-08 09:53:01 +00:00
|
|
|
const char *wtap_file_type_subtype_string(int file_type_subtype)
|
1999-12-04 08:32:14 +00:00
|
|
|
{
|
2013-11-08 09:53:01 +00:00
|
|
|
if (file_type_subtype < 0 || file_type_subtype >= wtap_num_file_types_subtypes) {
|
|
|
|
g_error("Unknown capture file type %d", file_type_subtype);
|
2011-01-30 23:27:57 +00:00
|
|
|
/** g_error() does an abort() and thus never returns **/
|
2011-01-31 16:38:40 +00:00
|
|
|
return "";
|
1999-12-04 08:32:14 +00:00
|
|
|
} else
|
2013-11-08 09:53:01 +00:00
|
|
|
return dump_open_table[file_type_subtype].name;
|
1999-12-04 08:32:14 +00:00
|
|
|
}
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* Name to use in, say, a command-line flag specifying the type/subtype. */
|
|
|
|
const char *wtap_file_type_subtype_short_string(int file_type_subtype)
|
1999-12-04 21:20:09 +00:00
|
|
|
{
|
2013-11-08 09:53:01 +00:00
|
|
|
if (file_type_subtype < 0 || file_type_subtype >= wtap_num_file_types_subtypes)
|
1999-12-04 21:20:09 +00:00
|
|
|
return NULL;
|
|
|
|
else
|
2013-11-08 09:53:01 +00:00
|
|
|
return dump_open_table[file_type_subtype].short_name;
|
1999-12-04 21:20:09 +00:00
|
|
|
}
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* Translate a short name to a capture file type/subtype. */
|
|
|
|
int wtap_short_string_to_file_type_subtype(const char *short_name)
|
1999-12-04 21:20:09 +00:00
|
|
|
{
|
2013-11-08 09:53:01 +00:00
|
|
|
int file_type_subtype;
|
1999-12-04 21:20:09 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
for (file_type_subtype = 0; file_type_subtype < wtap_num_file_types_subtypes; file_type_subtype++) {
|
|
|
|
if (dump_open_table[file_type_subtype].short_name != NULL &&
|
|
|
|
strcmp(short_name, dump_open_table[file_type_subtype].short_name) == 0)
|
|
|
|
return file_type_subtype;
|
1999-12-04 21:20:09 +00:00
|
|
|
}
|
2013-07-28 21:12:07 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We now call the "libpcap" file format just "pcap", but we
|
|
|
|
* allow it to be specified as "libpcap" as well, for
|
|
|
|
* backwards compatibility.
|
|
|
|
*/
|
|
|
|
if (strcmp(short_name, "libpcap") == 0)
|
2013-11-08 09:53:01 +00:00
|
|
|
return WTAP_FILE_TYPE_SUBTYPE_PCAP;
|
2013-07-28 21:12:07 +00:00
|
|
|
|
1999-12-04 21:20:09 +00:00
|
|
|
return -1; /* no such file type, or we can't write it */
|
|
|
|
}
|
|
|
|
|
2013-08-23 00:06:26 +00:00
|
|
|
static GSList *
|
2013-11-08 09:53:01 +00:00
|
|
|
add_extensions_for_file_type_subtype(int file_type_subtype, GSList *extensions,
|
2013-08-23 00:06:26 +00:00
|
|
|
GSList *compressed_file_extensions)
|
2006-06-23 18:20:34 +00:00
|
|
|
{
|
2012-01-21 08:59:21 +00:00
|
|
|
gchar **extensions_set, **extensionp;
|
|
|
|
gchar *extension;
|
|
|
|
|
|
|
|
/*
|
2012-01-23 23:17:03 +00:00
|
|
|
* Add the default extension, and all compressed variants of
|
|
|
|
* it.
|
2012-01-21 08:59:21 +00:00
|
|
|
*/
|
2012-01-23 23:17:03 +00:00
|
|
|
extensions = add_extensions(extensions,
|
2013-11-08 09:53:01 +00:00
|
|
|
dump_open_table[file_type_subtype].default_file_extension,
|
2012-01-23 23:17:03 +00:00
|
|
|
compressed_file_extensions);
|
2012-01-21 08:59:21 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
if (dump_open_table[file_type_subtype].additional_file_extensions != NULL) {
|
2012-01-21 08:59:21 +00:00
|
|
|
/*
|
2012-01-23 23:17:03 +00:00
|
|
|
* We have additional extensions; add them.
|
|
|
|
*
|
|
|
|
* First, split the extension-list string into a set of
|
|
|
|
* extensions.
|
2012-01-21 08:59:21 +00:00
|
|
|
*/
|
2013-11-08 09:53:01 +00:00
|
|
|
extensions_set = g_strsplit(dump_open_table[file_type_subtype].additional_file_extensions,
|
2012-01-23 23:17:03 +00:00
|
|
|
";", 0);
|
2012-01-21 08:59:21 +00:00
|
|
|
|
|
|
|
/*
|
2012-01-23 23:17:03 +00:00
|
|
|
* Add each of those extensions to the list.
|
2012-01-21 08:59:21 +00:00
|
|
|
*/
|
2012-01-23 23:17:03 +00:00
|
|
|
for (extensionp = extensions_set; *extensionp != NULL;
|
|
|
|
extensionp++) {
|
|
|
|
extension = *extensionp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add the extension, and all compressed variants
|
|
|
|
* of it.
|
|
|
|
*/
|
|
|
|
extensions = add_extensions(extensions, extension,
|
|
|
|
compressed_file_extensions);
|
2012-01-21 08:59:21 +00:00
|
|
|
}
|
2012-01-23 23:17:03 +00:00
|
|
|
|
|
|
|
g_strfreev(extensions_set);
|
2012-01-21 08:59:21 +00:00
|
|
|
}
|
2013-08-23 00:06:26 +00:00
|
|
|
return extensions;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return a list of file extensions that are used by the specified file type.
|
|
|
|
|
|
|
|
If include_compressed is TRUE, the list will include compressed
|
|
|
|
extensions, e.g. not just "pcap" but also "pcap.gz" if we can read
|
|
|
|
gzipped files.
|
|
|
|
|
|
|
|
All strings in the list are allocated with g_malloc() and must be freed
|
|
|
|
with g_free(). */
|
2013-11-08 09:53:01 +00:00
|
|
|
GSList *wtap_get_file_extensions_list(int file_type_subtype, gboolean include_compressed)
|
2013-08-23 00:06:26 +00:00
|
|
|
{
|
|
|
|
GSList *compressed_file_extensions;
|
|
|
|
GSList *extensions;
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
if (file_type_subtype < 0 || file_type_subtype >= wtap_num_file_types_subtypes)
|
2013-08-23 00:06:26 +00:00
|
|
|
return NULL; /* not a valid file type */
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
if (dump_open_table[file_type_subtype].default_file_extension == NULL)
|
2013-08-23 00:06:26 +00:00
|
|
|
return NULL; /* valid, but no extensions known */
|
|
|
|
|
|
|
|
extensions = NULL; /* empty list, to start with */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If include_compressions is true, get the list of compressed-file
|
|
|
|
* extensions.
|
|
|
|
*/
|
|
|
|
if (include_compressed)
|
|
|
|
compressed_file_extensions = wtap_get_compressed_file_extensions();
|
|
|
|
else
|
|
|
|
compressed_file_extensions = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add all this file type's extensions, with compressed
|
|
|
|
* variants.
|
|
|
|
*/
|
2013-11-08 09:53:01 +00:00
|
|
|
extensions = add_extensions_for_file_type_subtype(file_type_subtype, extensions,
|
2013-08-23 00:06:26 +00:00
|
|
|
compressed_file_extensions);
|
|
|
|
|
2012-01-21 08:59:21 +00:00
|
|
|
g_slist_free(compressed_file_extensions);
|
|
|
|
return extensions;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2013-11-08 01:08:42 +00:00
|
|
|
* Free a list returned by wtap_get_file_extension_type_extensions(),
|
|
|
|
* wtap_get_all_file_extensions_list, or wtap_get_file_extensions_list().
|
2012-01-21 08:59:21 +00:00
|
|
|
*/
|
2013-11-08 01:08:42 +00:00
|
|
|
void wtap_free_extensions_list(GSList *extensions)
|
2012-01-21 08:59:21 +00:00
|
|
|
{
|
|
|
|
GSList *extension;
|
|
|
|
|
|
|
|
for (extension = extensions; extension != NULL;
|
|
|
|
extension = g_slist_next(extension)) {
|
|
|
|
g_free(extension->data);
|
|
|
|
}
|
|
|
|
g_slist_free(extensions);
|
2006-06-23 18:20:34 +00:00
|
|
|
}
|
|
|
|
|
2012-01-23 21:57:45 +00:00
|
|
|
/* Return the default file extension to use with the specified file type;
|
|
|
|
that's just the extension, without any ".". */
|
2013-11-08 09:53:01 +00:00
|
|
|
const char *wtap_default_file_extension(int file_type_subtype)
|
2006-06-23 18:20:34 +00:00
|
|
|
{
|
2013-11-08 09:53:01 +00:00
|
|
|
if (file_type_subtype < 0 || file_type_subtype >= wtap_num_file_types_subtypes)
|
2006-06-23 18:20:34 +00:00
|
|
|
return NULL;
|
2012-01-23 23:17:03 +00:00
|
|
|
else
|
2013-11-08 09:53:01 +00:00
|
|
|
return dump_open_table[file_type_subtype].default_file_extension;
|
2006-06-23 18:20:34 +00:00
|
|
|
}
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
gboolean wtap_dump_can_open(int file_type_subtype)
|
1999-12-04 08:32:14 +00:00
|
|
|
{
|
2013-11-08 09:53:01 +00:00
|
|
|
if (file_type_subtype < 0 || file_type_subtype >= wtap_num_file_types_subtypes
|
|
|
|
|| dump_open_table[file_type_subtype].dump_open == NULL)
|
1999-12-04 08:32:14 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-09-15 21:50:50 +00:00
|
|
|
#ifdef HAVE_LIBZ
|
2013-11-08 09:53:01 +00:00
|
|
|
gboolean wtap_dump_can_compress(int file_type_subtype)
|
2005-09-14 21:57:30 +00:00
|
|
|
{
|
2011-04-12 00:44:44 +00:00
|
|
|
/*
|
|
|
|
* If this is an unknown file type, or if we have to
|
|
|
|
* seek when writing out a file with this file type,
|
|
|
|
* return FALSE.
|
|
|
|
*/
|
2013-11-08 09:53:01 +00:00
|
|
|
if (file_type_subtype < 0 || file_type_subtype >= wtap_num_file_types_subtypes
|
|
|
|
|| dump_open_table[file_type_subtype].writing_must_seek)
|
2005-09-14 21:57:30 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
2008-09-15 21:50:50 +00:00
|
|
|
}
|
2005-09-14 21:57:30 +00:00
|
|
|
#else
|
2013-11-08 09:53:01 +00:00
|
|
|
gboolean wtap_dump_can_compress(int file_type_subtype _U_)
|
2008-09-15 21:50:50 +00:00
|
|
|
{
|
2005-09-14 21:57:30 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-09-15 21:50:50 +00:00
|
|
|
#endif
|
2005-09-14 21:57:30 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
gboolean wtap_dump_has_name_resolution(int file_type_subtype)
|
2011-03-24 22:47:57 +00:00
|
|
|
{
|
2013-11-08 09:53:01 +00:00
|
|
|
if (file_type_subtype < 0 || file_type_subtype >= wtap_num_file_types_subtypes
|
|
|
|
|| dump_open_table[file_type_subtype].has_name_resolution == FALSE)
|
2011-03-24 22:47:57 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2005-09-14 21:57:30 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
gboolean wtap_dump_supports_comment_types(int file_type_subtype, guint32 comment_types)
|
2013-04-01 20:36:42 +00:00
|
|
|
{
|
|
|
|
guint32 supported_comment_types;
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
if (file_type_subtype < 0 || file_type_subtype >= wtap_num_file_types_subtypes)
|
2013-04-01 20:36:42 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
supported_comment_types = dump_open_table[file_type_subtype].supported_comment_types;
|
2013-04-01 20:36:42 +00:00
|
|
|
|
|
|
|
if ((comment_types & supported_comment_types) == comment_types)
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
static gboolean wtap_dump_open_check(int file_type_subtype, int encap, gboolean comressed, int *err);
|
|
|
|
static wtap_dumper* wtap_dump_alloc_wdh(int file_type_subtype, int encap, int snaplen,
|
2009-01-04 16:45:34 +00:00
|
|
|
gboolean compressed, int *err);
|
2013-11-08 09:53:01 +00:00
|
|
|
static gboolean wtap_dump_open_finish(wtap_dumper *wdh, int file_type_subtype, gboolean compressed, int *err);
|
2005-09-14 21:57:30 +00:00
|
|
|
|
2011-04-08 00:28:37 +00:00
|
|
|
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);
|
2005-09-14 21:57:30 +00:00
|
|
|
static int wtap_dump_file_close(wtap_dumper *wdh);
|
Add to Wiretap the ability to write capture files; for now, it can only
write them in "libpcap" format, but the mechanism can have other formats
added.
When creating the temporary file for a capture, use "create_tempfile()",
to close a security hole opened by the fact that "tempnam()" creates a
temporary file, but doesn't open it, and we open the file with the name
it gives us - somebody could remove the file and plant a link to some
file, and, if as may well be the case when Ethereal is capturing
packets, it's running as "root", that means we write a capture on top of
that file.... (The aforementioned changes to Wiretap let you open a
capture file for writing given an file descriptor, "fdopen()"-style,
which this change requires.)
svn path=/trunk/; revision=509
1999-08-18 04:17:38 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
wtap_dumper* wtap_dump_open(const char *filename, int file_type_subtype, int encap,
|
2005-09-14 21:57:30 +00:00
|
|
|
int snaplen, gboolean compressed, int *err)
|
2012-02-15 19:44:16 +00:00
|
|
|
{
|
2013-11-08 09:53:01 +00:00
|
|
|
return wtap_dump_open_ng(filename, file_type_subtype, encap,snaplen, compressed, NULL, NULL, err);
|
2012-02-15 19:44:16 +00:00
|
|
|
}
|
|
|
|
|
2012-07-11 03:50:28 +00:00
|
|
|
static wtap_dumper *
|
2013-11-08 09:53:01 +00:00
|
|
|
wtap_dump_init_dumper(int file_type_subtype, int encap, int snaplen, gboolean compressed,
|
2012-07-11 03:50:28 +00:00
|
|
|
wtapng_section_t *shb_hdr, wtapng_iface_descriptions_t *idb_inf, int *err)
|
Add to Wiretap the ability to write capture files; for now, it can only
write them in "libpcap" format, but the mechanism can have other formats
added.
When creating the temporary file for a capture, use "create_tempfile()",
to close a security hole opened by the fact that "tempnam()" creates a
temporary file, but doesn't open it, and we open the file with the name
it gives us - somebody could remove the file and plant a link to some
file, and, if as may well be the case when Ethereal is capturing
packets, it's running as "root", that means we write a capture on top of
that file.... (The aforementioned changes to Wiretap let you open a
capture file for writing given an file descriptor, "fdopen()"-style,
which this change requires.)
svn path=/trunk/; revision=509
1999-08-18 04:17:38 +00:00
|
|
|
{
|
2001-10-16 04:58:24 +00:00
|
|
|
wtap_dumper *wdh;
|
|
|
|
|
|
|
|
/* Allocate a data structure for the output stream. */
|
2013-11-08 09:53:01 +00:00
|
|
|
wdh = wtap_dump_alloc_wdh(file_type_subtype, encap, snaplen, compressed, err);
|
2001-10-16 04:58:24 +00:00
|
|
|
if (wdh == NULL)
|
|
|
|
return NULL; /* couldn't allocate it */
|
2012-02-21 16:51:23 +00:00
|
|
|
|
2012-02-15 19:44:16 +00:00
|
|
|
/* Set Section Header Block data */
|
|
|
|
wdh->shb_hdr = shb_hdr;
|
2012-02-20 20:15:51 +00:00
|
|
|
/* Set Interface Description Block data */
|
2012-02-21 17:19:45 +00:00
|
|
|
if ((idb_inf != NULL) && (idb_inf->number_of_interfaces > 0)) {
|
2012-02-21 15:21:01 +00:00
|
|
|
wdh->number_of_interfaces = idb_inf->number_of_interfaces;
|
|
|
|
wdh->interface_data = idb_inf->interface_data;
|
|
|
|
} else {
|
2012-02-21 16:51:23 +00:00
|
|
|
wtapng_if_descr_t descr;
|
|
|
|
|
|
|
|
descr.wtap_encap = encap;
|
2012-07-10 19:59:39 +00:00
|
|
|
descr.time_units_per_second = 1000000; /* default microsecond resolution */
|
2012-02-21 16:51:23 +00:00
|
|
|
descr.link_type = wtap_wtap_encap_to_pcap_encap(encap);
|
|
|
|
descr.snap_len = snaplen;
|
|
|
|
descr.opt_comment = NULL;
|
2012-08-06 11:53:26 +00:00
|
|
|
descr.if_name = g_strdup("Unknown/not available in original file format(libpcap)");
|
2012-02-21 16:51:23 +00:00
|
|
|
descr.if_description = NULL;
|
|
|
|
descr.if_speed = 0;
|
|
|
|
descr.if_tsresol = 6;
|
2012-03-04 19:01:14 +00:00
|
|
|
descr.if_filter_str= NULL;
|
|
|
|
descr.bpf_filter_len= 0;
|
|
|
|
descr.if_filter_bpf_bytes= NULL;
|
2012-02-21 16:51:23 +00:00
|
|
|
descr.if_os = NULL;
|
|
|
|
descr.if_fcslen = -1;
|
2012-03-13 08:36:52 +00:00
|
|
|
descr.num_stat_entries = 0; /* Number of ISB:s */
|
|
|
|
descr.interface_statistics = NULL;
|
2012-02-21 16:51:23 +00:00
|
|
|
wdh->number_of_interfaces= 1;
|
|
|
|
wdh->interface_data= g_array_new(FALSE, FALSE, sizeof(wtapng_if_descr_t));
|
|
|
|
g_array_append_val(wdh->interface_data, descr);
|
2012-02-21 15:21:01 +00:00
|
|
|
}
|
2012-07-11 03:50:28 +00:00
|
|
|
return wdh;
|
|
|
|
}
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
wtap_dumper* wtap_dump_open_ng(const char *filename, int file_type_subtype, int encap,
|
2012-07-11 03:50:28 +00:00
|
|
|
int snaplen, gboolean compressed, wtapng_section_t *shb_hdr, wtapng_iface_descriptions_t *idb_inf, int *err)
|
|
|
|
{
|
|
|
|
wtap_dumper *wdh;
|
|
|
|
WFILE_T fh;
|
|
|
|
|
|
|
|
/* Check whether we can open a capture file with that file type
|
|
|
|
and that encapsulation. */
|
2013-11-08 09:53:01 +00:00
|
|
|
if (!wtap_dump_open_check(file_type_subtype, encap, compressed, err))
|
2012-07-11 03:50:28 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Allocate and initialize a data structure for the output stream. */
|
2013-11-08 09:53:01 +00:00
|
|
|
wdh = wtap_dump_init_dumper(file_type_subtype, encap, snaplen, compressed,
|
2012-07-11 03:50:28 +00:00
|
|
|
shb_hdr, idb_inf, err);
|
|
|
|
if (wdh == NULL)
|
|
|
|
return NULL;
|
2012-02-21 15:21:01 +00:00
|
|
|
|
2006-01-06 01:06:46 +00:00
|
|
|
/* "-" means stdout */
|
|
|
|
if (strcmp(filename, "-") == 0) {
|
2011-04-14 02:53:18 +00:00
|
|
|
if (compressed) {
|
|
|
|
*err = EINVAL; /* XXX - return a Wiretap error code for this */
|
2005-09-14 21:57:30 +00:00
|
|
|
g_free(wdh);
|
|
|
|
return NULL; /* compress won't work on stdout */
|
|
|
|
}
|
2004-04-28 05:47:33 +00:00
|
|
|
#ifdef _WIN32
|
2011-04-14 02:53:18 +00:00
|
|
|
if (_setmode(fileno(stdout), O_BINARY) == -1) {
|
|
|
|
/* "Should not happen" */
|
|
|
|
*err = errno;
|
|
|
|
g_free(wdh);
|
|
|
|
return NULL; /* couldn't put standard output in binary mode */
|
|
|
|
}
|
2004-04-28 05:47:33 +00:00
|
|
|
#endif
|
2002-07-16 07:15:09 +00:00
|
|
|
wdh->fh = stdout;
|
2004-04-28 05:47:33 +00:00
|
|
|
} else {
|
2002-07-16 07:15:09 +00:00
|
|
|
/* In case "fopen()" fails but doesn't set "errno", set "errno"
|
|
|
|
to a generic "the open failed" error. */
|
|
|
|
errno = WTAP_ERR_CANT_OPEN;
|
2005-09-14 21:57:30 +00:00
|
|
|
fh = wtap_dump_file_open(wdh, filename);
|
2002-07-16 07:15:09 +00:00
|
|
|
if (fh == NULL) {
|
|
|
|
*err = errno;
|
2005-09-14 21:57:30 +00:00
|
|
|
g_free(wdh);
|
2002-07-16 07:15:09 +00:00
|
|
|
return NULL; /* can't create file */
|
|
|
|
}
|
|
|
|
wdh->fh = fh;
|
Add to Wiretap the ability to write capture files; for now, it can only
write them in "libpcap" format, but the mechanism can have other formats
added.
When creating the temporary file for a capture, use "create_tempfile()",
to close a security hole opened by the fact that "tempnam()" creates a
temporary file, but doesn't open it, and we open the file with the name
it gives us - somebody could remove the file and plant a link to some
file, and, if as may well be the case when Ethereal is capturing
packets, it's running as "root", that means we write a capture on top of
that file.... (The aforementioned changes to Wiretap let you open a
capture file for writing given an file descriptor, "fdopen()"-style,
which this change requires.)
svn path=/trunk/; revision=509
1999-08-18 04:17:38 +00:00
|
|
|
}
|
2001-10-16 04:58:24 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
if (!wtap_dump_open_finish(wdh, file_type_subtype, compressed, err)) {
|
2001-10-16 04:58:24 +00:00
|
|
|
/* Get rid of the file we created; we couldn't finish
|
|
|
|
opening it. */
|
2005-09-14 21:57:30 +00:00
|
|
|
if (wdh->fh != stdout) {
|
|
|
|
wtap_dump_file_close(wdh);
|
2008-05-22 15:46:27 +00:00
|
|
|
ws_unlink(filename);
|
2005-09-14 21:57:30 +00:00
|
|
|
}
|
|
|
|
g_free(wdh);
|
2001-10-16 04:58:24 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return wdh;
|
Add to Wiretap the ability to write capture files; for now, it can only
write them in "libpcap" format, but the mechanism can have other formats
added.
When creating the temporary file for a capture, use "create_tempfile()",
to close a security hole opened by the fact that "tempnam()" creates a
temporary file, but doesn't open it, and we open the file with the name
it gives us - somebody could remove the file and plant a link to some
file, and, if as may well be the case when Ethereal is capturing
packets, it's running as "root", that means we write a capture on top of
that file.... (The aforementioned changes to Wiretap let you open a
capture file for writing given an file descriptor, "fdopen()"-style,
which this change requires.)
svn path=/trunk/; revision=509
1999-08-18 04:17:38 +00:00
|
|
|
}
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
wtap_dumper* wtap_dump_fdopen(int fd, int file_type_subtype, int encap, int snaplen,
|
2005-09-14 21:57:30 +00:00
|
|
|
gboolean compressed, int *err)
|
2012-04-25 12:33:23 +00:00
|
|
|
{
|
2013-11-08 09:53:01 +00:00
|
|
|
return wtap_dump_fdopen_ng(fd, file_type_subtype, encap, snaplen, compressed, NULL, NULL, err);
|
2012-04-25 12:33:23 +00:00
|
|
|
}
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
wtap_dumper* wtap_dump_fdopen_ng(int fd, int file_type_subtype, int encap, int snaplen,
|
2012-04-25 12:33:23 +00:00
|
|
|
gboolean compressed, wtapng_section_t *shb_hdr, wtapng_iface_descriptions_t *idb_inf, int *err)
|
Add to Wiretap the ability to write capture files; for now, it can only
write them in "libpcap" format, but the mechanism can have other formats
added.
When creating the temporary file for a capture, use "create_tempfile()",
to close a security hole opened by the fact that "tempnam()" creates a
temporary file, but doesn't open it, and we open the file with the name
it gives us - somebody could remove the file and plant a link to some
file, and, if as may well be the case when Ethereal is capturing
packets, it's running as "root", that means we write a capture on top of
that file.... (The aforementioned changes to Wiretap let you open a
capture file for writing given an file descriptor, "fdopen()"-style,
which this change requires.)
svn path=/trunk/; revision=509
1999-08-18 04:17:38 +00:00
|
|
|
{
|
2001-10-16 04:58:24 +00:00
|
|
|
wtap_dumper *wdh;
|
2011-04-08 00:28:37 +00:00
|
|
|
WFILE_T fh;
|
Add to Wiretap the ability to write capture files; for now, it can only
write them in "libpcap" format, but the mechanism can have other formats
added.
When creating the temporary file for a capture, use "create_tempfile()",
to close a security hole opened by the fact that "tempnam()" creates a
temporary file, but doesn't open it, and we open the file with the name
it gives us - somebody could remove the file and plant a link to some
file, and, if as may well be the case when Ethereal is capturing
packets, it's running as "root", that means we write a capture on top of
that file.... (The aforementioned changes to Wiretap let you open a
capture file for writing given an file descriptor, "fdopen()"-style,
which this change requires.)
svn path=/trunk/; revision=509
1999-08-18 04:17:38 +00:00
|
|
|
|
2001-10-16 04:58:24 +00:00
|
|
|
/* Check whether we can open a capture file with that file type
|
|
|
|
and that encapsulation. */
|
2013-11-08 09:53:01 +00:00
|
|
|
if (!wtap_dump_open_check(file_type_subtype, encap, compressed, err))
|
2001-10-16 04:58:24 +00:00
|
|
|
return NULL;
|
|
|
|
|
2012-07-11 03:50:28 +00:00
|
|
|
/* Allocate and initialize a data structure for the output stream. */
|
2013-11-08 09:53:01 +00:00
|
|
|
wdh = wtap_dump_init_dumper(file_type_subtype, encap, snaplen, compressed,
|
2012-07-11 03:50:28 +00:00
|
|
|
shb_hdr, idb_inf, err);
|
2001-10-16 04:58:24 +00:00
|
|
|
if (wdh == NULL)
|
2012-07-11 03:50:28 +00:00
|
|
|
return NULL;
|
2001-10-16 04:58:24 +00:00
|
|
|
|
2006-01-05 22:24:09 +00:00
|
|
|
#ifdef _WIN32
|
2011-04-14 02:53:18 +00:00
|
|
|
if (fd == 1) {
|
|
|
|
if (_setmode(fileno(stdout), O_BINARY) == -1) {
|
|
|
|
/* "Should not happen" */
|
|
|
|
*err = errno;
|
|
|
|
g_free(wdh);
|
|
|
|
return NULL; /* couldn't put standard output in binary mode */
|
|
|
|
}
|
2009-01-04 16:45:34 +00:00
|
|
|
}
|
2006-01-05 22:24:09 +00:00
|
|
|
#endif
|
|
|
|
|
1999-09-23 05:00:59 +00:00
|
|
|
/* In case "fopen()" fails but doesn't set "errno", set "errno"
|
Add to Wiretap the ability to write capture files; for now, it can only
write them in "libpcap" format, but the mechanism can have other formats
added.
When creating the temporary file for a capture, use "create_tempfile()",
to close a security hole opened by the fact that "tempnam()" creates a
temporary file, but doesn't open it, and we open the file with the name
it gives us - somebody could remove the file and plant a link to some
file, and, if as may well be the case when Ethereal is capturing
packets, it's running as "root", that means we write a capture on top of
that file.... (The aforementioned changes to Wiretap let you open a
capture file for writing given an file descriptor, "fdopen()"-style,
which this change requires.)
svn path=/trunk/; revision=509
1999-08-18 04:17:38 +00:00
|
|
|
to a generic "the open failed" error. */
|
|
|
|
errno = WTAP_ERR_CANT_OPEN;
|
2005-09-14 21:57:30 +00:00
|
|
|
fh = wtap_dump_file_fdopen(wdh, fd);
|
Add to Wiretap the ability to write capture files; for now, it can only
write them in "libpcap" format, but the mechanism can have other formats
added.
When creating the temporary file for a capture, use "create_tempfile()",
to close a security hole opened by the fact that "tempnam()" creates a
temporary file, but doesn't open it, and we open the file with the name
it gives us - somebody could remove the file and plant a link to some
file, and, if as may well be the case when Ethereal is capturing
packets, it's running as "root", that means we write a capture on top of
that file.... (The aforementioned changes to Wiretap let you open a
capture file for writing given an file descriptor, "fdopen()"-style,
which this change requires.)
svn path=/trunk/; revision=509
1999-08-18 04:17:38 +00:00
|
|
|
if (fh == NULL) {
|
|
|
|
*err = errno;
|
2005-09-14 21:57:30 +00:00
|
|
|
g_free(wdh);
|
Add to Wiretap the ability to write capture files; for now, it can only
write them in "libpcap" format, but the mechanism can have other formats
added.
When creating the temporary file for a capture, use "create_tempfile()",
to close a security hole opened by the fact that "tempnam()" creates a
temporary file, but doesn't open it, and we open the file with the name
it gives us - somebody could remove the file and plant a link to some
file, and, if as may well be the case when Ethereal is capturing
packets, it's running as "root", that means we write a capture on top of
that file.... (The aforementioned changes to Wiretap let you open a
capture file for writing given an file descriptor, "fdopen()"-style,
which this change requires.)
svn path=/trunk/; revision=509
1999-08-18 04:17:38 +00:00
|
|
|
return NULL; /* can't create standard I/O stream */
|
|
|
|
}
|
2001-10-16 04:58:24 +00:00
|
|
|
wdh->fh = fh;
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
if (!wtap_dump_open_finish(wdh, file_type_subtype, compressed, err)) {
|
2005-09-14 21:57:30 +00:00
|
|
|
wtap_dump_file_close(wdh);
|
|
|
|
g_free(wdh);
|
2001-10-16 04:58:24 +00:00
|
|
|
return NULL;
|
2005-09-14 21:57:30 +00:00
|
|
|
}
|
2001-10-16 04:58:24 +00:00
|
|
|
return wdh;
|
Add to Wiretap the ability to write capture files; for now, it can only
write them in "libpcap" format, but the mechanism can have other formats
added.
When creating the temporary file for a capture, use "create_tempfile()",
to close a security hole opened by the fact that "tempnam()" creates a
temporary file, but doesn't open it, and we open the file with the name
it gives us - somebody could remove the file and plant a link to some
file, and, if as may well be the case when Ethereal is capturing
packets, it's running as "root", that means we write a capture on top of
that file.... (The aforementioned changes to Wiretap let you open a
capture file for writing given an file descriptor, "fdopen()"-style,
which this change requires.)
svn path=/trunk/; revision=509
1999-08-18 04:17:38 +00:00
|
|
|
}
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
static gboolean wtap_dump_open_check(int file_type_subtype, int encap, gboolean compressed, int *err)
|
Add to Wiretap the ability to write capture files; for now, it can only
write them in "libpcap" format, but the mechanism can have other formats
added.
When creating the temporary file for a capture, use "create_tempfile()",
to close a security hole opened by the fact that "tempnam()" creates a
temporary file, but doesn't open it, and we open the file with the name
it gives us - somebody could remove the file and plant a link to some
file, and, if as may well be the case when Ethereal is capturing
packets, it's running as "root", that means we write a capture on top of
that file.... (The aforementioned changes to Wiretap let you open a
capture file for writing given an file descriptor, "fdopen()"-style,
which this change requires.)
svn path=/trunk/; revision=509
1999-08-18 04:17:38 +00:00
|
|
|
{
|
2013-11-08 09:53:01 +00:00
|
|
|
if (!wtap_dump_can_open(file_type_subtype)) {
|
1999-12-04 08:32:14 +00:00
|
|
|
/* Invalid type, or type we don't know how to write. */
|
|
|
|
*err = WTAP_ERR_UNSUPPORTED_FILE_TYPE;
|
2001-10-16 04:58:24 +00:00
|
|
|
return FALSE;
|
1999-12-04 08:32:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* OK, we know how to write that type; can we write the specified
|
|
|
|
encapsulation type? */
|
2013-11-08 09:53:01 +00:00
|
|
|
*err = (*dump_open_table[file_type_subtype].can_write_encap)(encap);
|
2001-10-16 04:58:24 +00:00
|
|
|
if (*err != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
/* if compression is wanted, do we support this for this file_type_subtype? */
|
|
|
|
if(compressed && !wtap_dump_can_compress(file_type_subtype)) {
|
2005-09-14 21:57:30 +00:00
|
|
|
*err = WTAP_ERR_COMPRESSION_NOT_SUPPORTED;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
*err = (*dump_open_table[file_type_subtype].can_write_encap)(encap);
|
2005-09-14 21:57:30 +00:00
|
|
|
if (*err != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2001-10-16 04:58:24 +00:00
|
|
|
/* All systems go! */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
static wtap_dumper* wtap_dump_alloc_wdh(int file_type_subtype, int encap, int snaplen,
|
2005-09-14 21:57:30 +00:00
|
|
|
gboolean compressed, int *err)
|
2001-10-16 04:58:24 +00:00
|
|
|
{
|
|
|
|
wtap_dumper *wdh;
|
1999-12-04 08:32:14 +00:00
|
|
|
|
2011-03-24 22:47:57 +00:00
|
|
|
wdh = (wtap_dumper *)g_malloc0(sizeof (wtap_dumper));
|
Add to Wiretap the ability to write capture files; for now, it can only
write them in "libpcap" format, but the mechanism can have other formats
added.
When creating the temporary file for a capture, use "create_tempfile()",
to close a security hole opened by the fact that "tempnam()" creates a
temporary file, but doesn't open it, and we open the file with the name
it gives us - somebody could remove the file and plant a link to some
file, and, if as may well be the case when Ethereal is capturing
packets, it's running as "root", that means we write a capture on top of
that file.... (The aforementioned changes to Wiretap let you open a
capture file for writing given an file descriptor, "fdopen()"-style,
which this change requires.)
svn path=/trunk/; revision=509
1999-08-18 04:17:38 +00:00
|
|
|
if (wdh == NULL) {
|
|
|
|
*err = errno;
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-03-24 22:47:57 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
wdh->file_type_subtype = file_type_subtype;
|
Add to Wiretap the ability to write capture files; for now, it can only
write them in "libpcap" format, but the mechanism can have other formats
added.
When creating the temporary file for a capture, use "create_tempfile()",
to close a security hole opened by the fact that "tempnam()" creates a
temporary file, but doesn't open it, and we open the file with the name
it gives us - somebody could remove the file and plant a link to some
file, and, if as may well be the case when Ethereal is capturing
packets, it's running as "root", that means we write a capture on top of
that file.... (The aforementioned changes to Wiretap let you open a
capture file for writing given an file descriptor, "fdopen()"-style,
which this change requires.)
svn path=/trunk/; revision=509
1999-08-18 04:17:38 +00:00
|
|
|
wdh->snaplen = snaplen;
|
|
|
|
wdh->encap = encap;
|
2005-09-14 21:57:30 +00:00
|
|
|
wdh->compressed = compressed;
|
2001-10-16 04:58:24 +00:00
|
|
|
return wdh;
|
|
|
|
}
|
1999-12-04 08:32:14 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
static gboolean wtap_dump_open_finish(wtap_dumper *wdh, int file_type_subtype, gboolean compressed, int *err)
|
2001-10-16 04:58:24 +00:00
|
|
|
{
|
2002-07-16 07:15:09 +00:00
|
|
|
int fd;
|
|
|
|
gboolean cant_seek;
|
|
|
|
|
|
|
|
/* Can we do a seek on the file descriptor?
|
|
|
|
If not, note that fact. */
|
2005-09-14 21:57:30 +00:00
|
|
|
if(compressed) {
|
|
|
|
cant_seek = TRUE;
|
|
|
|
} else {
|
2011-04-08 17:42:20 +00:00
|
|
|
fd = fileno((FILE *)wdh->fh);
|
2005-09-14 21:57:30 +00:00
|
|
|
if (lseek(fd, 1, SEEK_CUR) == -1)
|
2009-01-04 16:45:34 +00:00
|
|
|
cant_seek = TRUE;
|
2005-09-14 21:57:30 +00:00
|
|
|
else {
|
2009-01-04 16:45:34 +00:00
|
|
|
/* Undo the seek. */
|
|
|
|
lseek(fd, 0, SEEK_SET);
|
|
|
|
cant_seek = FALSE;
|
2005-09-14 21:57:30 +00:00
|
|
|
}
|
2002-07-16 07:15:09 +00:00
|
|
|
}
|
|
|
|
|
2011-04-12 00:44:44 +00:00
|
|
|
/* If this file type requires seeking, and we can't seek, fail. */
|
2013-11-08 09:53:01 +00:00
|
|
|
if (dump_open_table[file_type_subtype].writing_must_seek && cant_seek) {
|
2011-04-12 00:44:44 +00:00
|
|
|
*err = WTAP_ERR_CANT_WRITE_TO_PIPE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1999-12-04 08:32:14 +00:00
|
|
|
/* Now try to open the file for writing. */
|
2013-11-08 09:53:01 +00:00
|
|
|
if (!(*dump_open_table[file_type_subtype].dump_open)(wdh, err)) {
|
2001-10-16 04:58:24 +00:00
|
|
|
return FALSE;
|
Add to Wiretap the ability to write capture files; for now, it can only
write them in "libpcap" format, but the mechanism can have other formats
added.
When creating the temporary file for a capture, use "create_tempfile()",
to close a security hole opened by the fact that "tempnam()" creates a
temporary file, but doesn't open it, and we open the file with the name
it gives us - somebody could remove the file and plant a link to some
file, and, if as may well be the case when Ethereal is capturing
packets, it's running as "root", that means we write a capture on top of
that file.... (The aforementioned changes to Wiretap let you open a
capture file for writing given an file descriptor, "fdopen()"-style,
which this change requires.)
svn path=/trunk/; revision=509
1999-08-18 04:17:38 +00:00
|
|
|
}
|
|
|
|
|
2001-10-16 04:58:24 +00:00
|
|
|
return TRUE; /* success! */
|
Add to Wiretap the ability to write capture files; for now, it can only
write them in "libpcap" format, but the mechanism can have other formats
added.
When creating the temporary file for a capture, use "create_tempfile()",
to close a security hole opened by the fact that "tempnam()" creates a
temporary file, but doesn't open it, and we open the file with the name
it gives us - somebody could remove the file and plant a link to some
file, and, if as may well be the case when Ethereal is capturing
packets, it's running as "root", that means we write a capture on top of
that file.... (The aforementioned changes to Wiretap let you open a
capture file for writing given an file descriptor, "fdopen()"-style,
which this change requires.)
svn path=/trunk/; revision=509
1999-08-18 04:17:38 +00:00
|
|
|
}
|
|
|
|
|
1999-12-04 05:14:39 +00:00
|
|
|
gboolean wtap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
|
2012-10-16 21:50:57 +00:00
|
|
|
const guint8 *pd, int *err)
|
Add to Wiretap the ability to write capture files; for now, it can only
write them in "libpcap" format, but the mechanism can have other formats
added.
When creating the temporary file for a capture, use "create_tempfile()",
to close a security hole opened by the fact that "tempnam()" creates a
temporary file, but doesn't open it, and we open the file with the name
it gives us - somebody could remove the file and plant a link to some
file, and, if as may well be the case when Ethereal is capturing
packets, it's running as "root", that means we write a capture on top of
that file.... (The aforementioned changes to Wiretap let you open a
capture file for writing given an file descriptor, "fdopen()"-style,
which this change requires.)
svn path=/trunk/; revision=509
1999-08-18 04:17:38 +00:00
|
|
|
{
|
2012-10-16 21:50:57 +00:00
|
|
|
return (wdh->subtype_write)(wdh, phdr, pd, err);
|
Add to Wiretap the ability to write capture files; for now, it can only
write them in "libpcap" format, but the mechanism can have other formats
added.
When creating the temporary file for a capture, use "create_tempfile()",
to close a security hole opened by the fact that "tempnam()" creates a
temporary file, but doesn't open it, and we open the file with the name
it gives us - somebody could remove the file and plant a link to some
file, and, if as may well be the case when Ethereal is capturing
packets, it's running as "root", that means we write a capture on top of
that file.... (The aforementioned changes to Wiretap let you open a
capture file for writing given an file descriptor, "fdopen()"-style,
which this change requires.)
svn path=/trunk/; revision=509
1999-08-18 04:17:38 +00:00
|
|
|
}
|
|
|
|
|
2005-09-14 21:57:30 +00:00
|
|
|
void wtap_dump_flush(wtap_dumper *wdh)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_LIBZ
|
|
|
|
if(wdh->compressed) {
|
2011-04-11 21:33:22 +00:00
|
|
|
gzwfile_flush((GZWFILE_T)wdh->fh);
|
2008-05-22 15:46:27 +00:00
|
|
|
} else
|
2005-09-14 21:57:30 +00:00
|
|
|
#endif
|
|
|
|
{
|
2011-04-08 17:42:20 +00:00
|
|
|
fflush((FILE *)wdh->fh);
|
2005-09-14 21:57:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-04 05:14:39 +00:00
|
|
|
gboolean wtap_dump_close(wtap_dumper *wdh, int *err)
|
Add to Wiretap the ability to write capture files; for now, it can only
write them in "libpcap" format, but the mechanism can have other formats
added.
When creating the temporary file for a capture, use "create_tempfile()",
to close a security hole opened by the fact that "tempnam()" creates a
temporary file, but doesn't open it, and we open the file with the name
it gives us - somebody could remove the file and plant a link to some
file, and, if as may well be the case when Ethereal is capturing
packets, it's running as "root", that means we write a capture on top of
that file.... (The aforementioned changes to Wiretap let you open a
capture file for writing given an file descriptor, "fdopen()"-style,
which this change requires.)
svn path=/trunk/; revision=509
1999-08-18 04:17:38 +00:00
|
|
|
{
|
1999-12-04 05:14:39 +00:00
|
|
|
gboolean ret = TRUE;
|
Add to Wiretap the ability to write capture files; for now, it can only
write them in "libpcap" format, but the mechanism can have other formats
added.
When creating the temporary file for a capture, use "create_tempfile()",
to close a security hole opened by the fact that "tempnam()" creates a
temporary file, but doesn't open it, and we open the file with the name
it gives us - somebody could remove the file and plant a link to some
file, and, if as may well be the case when Ethereal is capturing
packets, it's running as "root", that means we write a capture on top of
that file.... (The aforementioned changes to Wiretap let you open a
capture file for writing given an file descriptor, "fdopen()"-style,
which this change requires.)
svn path=/trunk/; revision=509
1999-08-18 04:17:38 +00:00
|
|
|
|
1999-12-04 08:32:14 +00:00
|
|
|
if (wdh->subtype_close != NULL) {
|
|
|
|
/* There's a close routine for this dump stream. */
|
|
|
|
if (!(wdh->subtype_close)(wdh, err))
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
1999-08-18 04:41:20 +00:00
|
|
|
errno = WTAP_ERR_CANT_CLOSE;
|
2002-07-16 07:15:09 +00:00
|
|
|
/* Don't close stdout */
|
|
|
|
if (wdh->fh != stdout) {
|
2005-09-14 21:57:30 +00:00
|
|
|
if (wtap_dump_file_close(wdh) == EOF) {
|
2002-07-16 07:15:09 +00:00
|
|
|
if (ret) {
|
|
|
|
/* The per-format close function succeeded,
|
|
|
|
but the fclose didn't. Save the reason
|
|
|
|
why, if our caller asked for it. */
|
|
|
|
if (err != NULL)
|
|
|
|
*err = errno;
|
|
|
|
}
|
|
|
|
ret = FALSE;
|
1999-08-18 04:41:20 +00:00
|
|
|
}
|
2009-01-04 16:45:34 +00:00
|
|
|
} else {
|
|
|
|
/* as we don't close stdout, at least try to flush it */
|
|
|
|
wtap_dump_flush(wdh);
|
|
|
|
}
|
2010-02-26 07:59:54 +00:00
|
|
|
if (wdh->priv != NULL)
|
|
|
|
g_free(wdh->priv);
|
1999-11-10 19:47:57 +00:00
|
|
|
g_free(wdh);
|
Add to Wiretap the ability to write capture files; for now, it can only
write them in "libpcap" format, but the mechanism can have other formats
added.
When creating the temporary file for a capture, use "create_tempfile()",
to close a security hole opened by the fact that "tempnam()" creates a
temporary file, but doesn't open it, and we open the file with the name
it gives us - somebody could remove the file and plant a link to some
file, and, if as may well be the case when Ethereal is capturing
packets, it's running as "root", that means we write a capture on top of
that file.... (The aforementioned changes to Wiretap let you open a
capture file for writing given an file descriptor, "fdopen()"-style,
which this change requires.)
svn path=/trunk/; revision=509
1999-08-18 04:17:38 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2001-12-04 07:32:05 +00:00
|
|
|
|
2006-11-05 22:46:44 +00:00
|
|
|
gint64 wtap_get_bytes_dumped(wtap_dumper *wdh)
|
2001-12-04 07:32:05 +00:00
|
|
|
{
|
|
|
|
return wdh->bytes_dumped;
|
|
|
|
}
|
2001-12-04 08:26:00 +00:00
|
|
|
|
2006-11-05 22:46:44 +00:00
|
|
|
void wtap_set_bytes_dumped(wtap_dumper *wdh, gint64 bytes_dumped)
|
2001-12-04 08:26:00 +00:00
|
|
|
{
|
|
|
|
wdh->bytes_dumped = bytes_dumped;
|
|
|
|
}
|
|
|
|
|
2013-09-22 19:40:02 +00:00
|
|
|
gboolean wtap_dump_set_addrinfo_list(wtap_dumper *wdh, addrinfo_lists_t *addrinfo_lists)
|
2011-03-24 22:47:57 +00:00
|
|
|
{
|
2013-11-08 09:53:01 +00:00
|
|
|
if (!wdh || wdh->file_type_subtype < 0 || wdh->file_type_subtype >= wtap_num_file_types_subtypes
|
|
|
|
|| dump_open_table[wdh->file_type_subtype].has_name_resolution == FALSE)
|
2011-03-24 22:47:57 +00:00
|
|
|
return FALSE;
|
2013-09-22 19:40:02 +00:00
|
|
|
wdh->addrinfo_lists = addrinfo_lists;
|
2011-03-24 22:47:57 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2005-09-14 21:57:30 +00:00
|
|
|
|
|
|
|
/* internally open a file for writing (compressed or not) */
|
2008-09-15 21:50:50 +00:00
|
|
|
#ifdef HAVE_LIBZ
|
2011-04-08 00:28:37 +00:00
|
|
|
static WFILE_T wtap_dump_file_open(wtap_dumper *wdh, const char *filename)
|
2005-09-14 21:57:30 +00:00
|
|
|
{
|
|
|
|
if(wdh->compressed) {
|
2011-04-11 21:33:22 +00:00
|
|
|
return gzwfile_open(filename);
|
2008-09-15 21:50:50 +00:00
|
|
|
} else {
|
2008-05-22 15:46:27 +00:00
|
|
|
return ws_fopen(filename, "wb");
|
2005-09-14 21:57:30 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-15 21:50:50 +00:00
|
|
|
#else
|
2011-04-08 00:28:37 +00:00
|
|
|
static WFILE_T wtap_dump_file_open(wtap_dumper *wdh _U_, const char *filename)
|
2008-09-15 21:50:50 +00:00
|
|
|
{
|
|
|
|
return ws_fopen(filename, "wb");
|
|
|
|
}
|
|
|
|
#endif
|
2005-09-14 21:57:30 +00:00
|
|
|
|
|
|
|
/* internally open a file for writing (compressed or not) */
|
2008-09-15 21:50:50 +00:00
|
|
|
#ifdef HAVE_LIBZ
|
2011-04-08 00:28:37 +00:00
|
|
|
static WFILE_T wtap_dump_file_fdopen(wtap_dumper *wdh, int fd)
|
2005-09-14 21:57:30 +00:00
|
|
|
{
|
|
|
|
if(wdh->compressed) {
|
2011-04-11 21:33:22 +00:00
|
|
|
return gzwfile_fdopen(fd);
|
2008-09-15 21:50:50 +00:00
|
|
|
} else {
|
2005-09-14 21:57:30 +00:00
|
|
|
return fdopen(fd, "wb");
|
|
|
|
}
|
|
|
|
}
|
2008-09-15 21:50:50 +00:00
|
|
|
#else
|
2011-04-08 00:28:37 +00:00
|
|
|
static WFILE_T wtap_dump_file_fdopen(wtap_dumper *wdh _U_, int fd)
|
2008-09-15 21:50:50 +00:00
|
|
|
{
|
|
|
|
return fdopen(fd, "wb");
|
|
|
|
}
|
|
|
|
#endif
|
2005-09-14 21:57:30 +00:00
|
|
|
|
|
|
|
/* internally writing raw bytes (compressed or not) */
|
2010-10-20 00:36:53 +00:00
|
|
|
gboolean wtap_dump_file_write(wtap_dumper *wdh, const void *buf, size_t bufsize,
|
|
|
|
int *err)
|
2005-09-14 21:57:30 +00:00
|
|
|
{
|
2010-06-06 19:14:32 +00:00
|
|
|
size_t nwritten;
|
|
|
|
|
|
|
|
#ifdef HAVE_LIBZ
|
|
|
|
if (wdh->compressed) {
|
2011-04-11 21:33:22 +00:00
|
|
|
nwritten = gzwfile_write((GZWFILE_T)wdh->fh, buf, (unsigned) bufsize);
|
2010-06-06 19:14:32 +00:00
|
|
|
/*
|
2011-04-11 21:33:22 +00:00
|
|
|
* gzwfile_write() returns 0 on error.
|
2010-06-06 19:14:32 +00:00
|
|
|
*/
|
|
|
|
if (nwritten == 0) {
|
2011-04-11 21:33:22 +00:00
|
|
|
*err = gzwfile_geterr((GZWFILE_T)wdh->fh);
|
2010-06-06 19:14:32 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-05-22 15:46:27 +00:00
|
|
|
} else
|
2005-09-14 21:57:30 +00:00
|
|
|
#endif
|
|
|
|
{
|
2011-04-08 17:42:20 +00:00
|
|
|
nwritten = fwrite(buf, 1, bufsize, (FILE *)wdh->fh);
|
2010-06-06 19:14:32 +00:00
|
|
|
/*
|
|
|
|
* At least according to the Mac OS X man page,
|
|
|
|
* this can return a short count on an error.
|
|
|
|
*/
|
|
|
|
if (nwritten != bufsize) {
|
2011-04-08 17:42:20 +00:00
|
|
|
if (ferror((FILE *)wdh->fh))
|
2010-06-06 19:14:32 +00:00
|
|
|
*err = errno;
|
|
|
|
else
|
|
|
|
*err = WTAP_ERR_SHORT_WRITE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-09-14 21:57:30 +00:00
|
|
|
}
|
2010-06-06 19:14:32 +00:00
|
|
|
return TRUE;
|
2009-05-22 00:05:19 +00:00
|
|
|
}
|
|
|
|
|
2005-09-14 21:57:30 +00:00
|
|
|
/* internally close a file for writing (compressed or not) */
|
|
|
|
static int wtap_dump_file_close(wtap_dumper *wdh)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_LIBZ
|
|
|
|
if(wdh->compressed) {
|
2011-04-11 21:33:22 +00:00
|
|
|
return gzwfile_close((GZWFILE_T)wdh->fh);
|
2008-05-22 15:46:27 +00:00
|
|
|
} else
|
2005-09-14 21:57:30 +00:00
|
|
|
#endif
|
|
|
|
{
|
2011-04-08 17:42:20 +00:00
|
|
|
return fclose((FILE *)wdh->fh);
|
2005-09-14 21:57:30 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-17 09:20:13 +00:00
|
|
|
|
|
|
|
gint64 wtap_dump_file_seek(wtap_dumper *wdh, gint64 offset, int whence, int *err)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_LIBZ
|
|
|
|
if(wdh->compressed) {
|
|
|
|
*err = WTAP_ERR_CANT_SEEK_COMPRESSED;
|
|
|
|
return -1;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (-1 == fseek((FILE *)wdh->fh, (long)offset, whence)) {
|
|
|
|
*err = errno;
|
|
|
|
return -1;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
return 0;
|
2013-11-08 17:17:57 +00:00
|
|
|
}
|
2013-03-17 09:20:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
gint64 wtap_dump_file_tell(wtap_dumper *wdh, int *err)
|
|
|
|
{
|
|
|
|
gint64 rval;
|
|
|
|
#ifdef HAVE_LIBZ
|
|
|
|
if(wdh->compressed) {
|
|
|
|
*err = WTAP_ERR_CANT_SEEK_COMPRESSED;
|
|
|
|
return -1;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (-1 == (rval = ftell((FILE *)wdh->fh))) {
|
|
|
|
*err = errno;
|
|
|
|
return -1;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
return rval;
|
2013-11-08 17:17:57 +00:00
|
|
|
}
|
2013-03-17 09:20:13 +00:00
|
|
|
}
|
|
|
|
}
|