1998-11-12 06:01:27 +00:00
|
|
|
/* file.c
|
|
|
|
*
|
1999-12-12 21:34:51 +00:00
|
|
|
* $Id: file.c,v 1.40 1999/12/12 21:34:51 guy Exp $
|
1998-11-12 06:01:27 +00:00
|
|
|
*
|
|
|
|
* Wiretap Library
|
|
|
|
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
*/
|
1999-07-13 02:53:26 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
1998-11-12 00:06:47 +00:00
|
|
|
#include <stdio.h>
|
1999-09-23 04:39:01 +00:00
|
|
|
#include <fcntl.h>
|
1998-11-12 00:06:47 +00:00
|
|
|
#include <string.h>
|
1998-11-12 23:29:34 +00:00
|
|
|
#include <stdlib.h>
|
1999-08-15 06:59:13 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <errno.h>
|
1998-11-12 00:06:47 +00:00
|
|
|
#include "wtap.h"
|
1999-09-24 05:49:53 +00:00
|
|
|
#include "file.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"
|
1999-09-11 04:50:44 +00:00
|
|
|
#include "ascend.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"
|
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"
|
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
|
|
|
/* 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.
|
|
|
|
*
|
|
|
|
* XXX - I need to drag my damn ANSI C spec in to figure out how to
|
|
|
|
* declare a "const" array of pointers to functions; putting "const"
|
|
|
|
* right after "static" isn't the right answer, at least according
|
|
|
|
* to GCC, which whines if I do that.
|
1999-10-31 17:46:11 +00:00
|
|
|
*
|
|
|
|
* Put the trace files that are merely saved telnet-sessions last, since it's
|
|
|
|
* possible that you could have captured someone a router telnet-session
|
|
|
|
* using another tool. So, a libpcap trace of an toshiba "snoop" session
|
|
|
|
* should be discovered as a libpcap file, not a toshiba file.
|
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
|
|
|
*/
|
|
|
|
|
|
|
|
static int (*open_routines[])(wtap *, int *) = {
|
1999-10-31 17:46:11 +00:00
|
|
|
/* Files that have magic bytes in fixed locations. These
|
|
|
|
* are easy to identify.
|
|
|
|
*/
|
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,
|
|
|
|
lanalyzer_open,
|
|
|
|
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,
|
|
|
|
|
|
|
|
/* Files whose magic headers are in text *somewhere* in the
|
|
|
|
* file (usually because the trace is just a saved copy of
|
|
|
|
* the telnet session).
|
|
|
|
*/
|
1999-10-18 01:51:34 +00:00
|
|
|
ascend_open,
|
1999-10-31 17:46:11 +00:00
|
|
|
toshiba_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
|
|
|
};
|
|
|
|
|
1999-09-11 04:50:44 +00:00
|
|
|
int wtap_def_seek_read (FILE *fh, int seek_off, guint8 *pd, int len)
|
|
|
|
{
|
1999-09-22 01:26:50 +00:00
|
|
|
file_seek(fh, seek_off, SEEK_SET);
|
|
|
|
return file_read(pd, sizeof(guint8), len, fh);
|
1999-09-11 04:50:44 +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
|
|
|
#define N_FILE_TYPES (sizeof open_routines / sizeof open_routines[0])
|
1998-11-12 00:06:47 +00:00
|
|
|
|
|
|
|
/* Opens a file and prepares a wtap struct */
|
1999-08-15 06:59:13 +00:00
|
|
|
wtap* wtap_open_offline(const char *filename, int *err)
|
1998-11-12 00:06:47 +00:00
|
|
|
{
|
1999-08-15 06:59:13 +00:00
|
|
|
struct stat statb;
|
1998-11-12 00:06:47 +00:00
|
|
|
wtap *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
|
|
|
int i;
|
1998-11-12 00:06:47 +00:00
|
|
|
|
1999-08-15 06:59:13 +00:00
|
|
|
/* First, make sure the file is valid */
|
1999-08-18 04:41:20 +00:00
|
|
|
if (stat(filename, &statb) < 0) {
|
1999-08-15 06:59:13 +00:00
|
|
|
*err = errno;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#ifndef WIN32
|
|
|
|
if (! S_ISREG(statb.st_mode) && ! S_ISFIFO(statb.st_mode)) {
|
|
|
|
*err = WTAP_ERR_NOT_REGULAR_FILE;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-08-18 04:41:20 +00:00
|
|
|
errno = ENOMEM;
|
1999-11-10 19:47:57 +00:00
|
|
|
wth = g_malloc(sizeof(wtap));
|
1999-08-18 04:41:20 +00:00
|
|
|
if (wth == NULL) {
|
|
|
|
*err = errno;
|
|
|
|
return NULL;
|
|
|
|
}
|
1998-11-12 00:06:47 +00:00
|
|
|
|
|
|
|
/* Open the file */
|
1999-08-18 04:41:20 +00:00
|
|
|
errno = WTAP_ERR_CANT_OPEN;
|
1999-09-23 04:39:01 +00:00
|
|
|
if (!(wth->fd = open(filename, O_RDONLY))) {
|
|
|
|
*err = errno;
|
1999-11-10 19:47:57 +00:00
|
|
|
g_free(wth);
|
1999-09-23 04:39:01 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!(wth->fh = filed_open(wth->fd, "rb"))) {
|
1999-08-15 06:59:13 +00:00
|
|
|
*err = errno;
|
1999-11-10 19:47:57 +00:00
|
|
|
g_free(wth);
|
1998-11-12 00:06:47 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1999-03-01 18:57:07 +00:00
|
|
|
/* initialization */
|
1999-08-22 02:29:40 +00:00
|
|
|
wth->file_encap = WTAP_ENCAP_UNKNOWN;
|
1999-08-28 01:19:45 +00:00
|
|
|
wth->data_offset = 0;
|
1999-03-01 18:57:07 +00:00
|
|
|
|
|
|
|
/* Try all file types */
|
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
|
|
|
for (i = 0; i < N_FILE_TYPES; i++) {
|
|
|
|
switch ((*open_routines[i])(wth, err)) {
|
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 */
|
1999-09-22 01:26:50 +00:00
|
|
|
file_close(wth->fh);
|
1999-11-10 19:47:57 +00:00
|
|
|
g_free(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
|
|
|
|
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. */
|
1999-09-22 01:26:50 +00:00
|
|
|
file_close(wth->fh);
|
1999-11-10 19:47:57 +00:00
|
|
|
g_free(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:
|
1999-03-01 18:57:07 +00:00
|
|
|
wth->frame_buffer = g_malloc(sizeof(struct Buffer));
|
|
|
|
buffer_init(wth->frame_buffer, 1500);
|
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
|
|
|
|
1999-12-04 08:32:14 +00:00
|
|
|
/* Table of the file types we know about. */
|
|
|
|
const static struct file_type_info {
|
|
|
|
const char *name;
|
1999-12-04 21:20:09 +00:00
|
|
|
const char *short_name;
|
1999-12-04 09:38:38 +00:00
|
|
|
int (*can_write_encap)(int, int);
|
1999-12-04 08:32:14 +00:00
|
|
|
int (*dump_open)(wtap_dumper *, int *);
|
|
|
|
} dump_open_table[WTAP_NUM_FILE_TYPES] = {
|
|
|
|
/* WTAP_FILE_UNKNOWN */
|
1999-12-04 21:20:09 +00:00
|
|
|
{ NULL, NULL,
|
1999-12-04 08:32:14 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
|
|
|
/* WTAP_FILE_WTAP */
|
1999-12-04 21:20:09 +00:00
|
|
|
{ "Wiretap (Ethereal)", NULL,
|
1999-12-04 08:32:14 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
|
|
|
/* WTAP_FILE_PCAP */
|
1999-12-05 01:23:22 +00:00
|
|
|
{ "libpcap (tcpdump, Ethereal, etc.)", "libpcap",
|
1999-12-04 09:38:38 +00:00
|
|
|
libpcap_dump_can_write_encap, libpcap_dump_open },
|
1999-12-04 08:32:14 +00:00
|
|
|
|
|
|
|
/* WTAP_FILE_PCAP_MODIFIED */
|
1999-12-12 21:34:51 +00:00
|
|
|
{ "modified libpcap (tcpdump)", "modlibpcap",
|
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 },
|
|
|
|
|
|
|
|
/* WTAP_FILE_PCAP_RH_6_1 */
|
1999-12-12 21:34:51 +00:00
|
|
|
{ "Red Hat Linux 6.1 libpcap (tcpdump)", "rh6_1libpcap",
|
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
|
|
|
|
|
|
|
/* WTAP_FILE_LANALYZER */
|
1999-12-04 21:20:09 +00:00
|
|
|
{ "Novell LANalyzer", NULL,
|
1999-12-04 08:32:14 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
|
|
|
/* WTAP_FILE_NGSNIFFER */
|
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
|
|
|
{ "Network Associates Sniffer (DOS-based)", "ngsniffer",
|
|
|
|
ngsniffer_dump_can_write_encap, ngsniffer_dump_open },
|
1999-12-04 08:32:14 +00:00
|
|
|
|
|
|
|
/* WTAP_FILE_SNOOP */
|
1999-12-05 01:23:22 +00:00
|
|
|
{ "Sun snoop", "snoop",
|
1999-12-04 09:38:38 +00:00
|
|
|
snoop_dump_can_write_encap, snoop_dump_open },
|
1999-12-04 08:32:14 +00:00
|
|
|
|
|
|
|
/* WTAP_FILE_IPTRACE_1_0 */
|
1999-12-04 21:20:09 +00:00
|
|
|
{ "AIX iptrace 1.0", NULL,
|
1999-12-04 08:32:14 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
|
|
|
/* WTAP_FILE_IPTRACE_2_0 */
|
1999-12-04 21:20:09 +00:00
|
|
|
{ "AIX iptrace 2.0", NULL,
|
1999-12-04 08:32:14 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
|
|
|
/* WTAP_FILE_NETMON_1_x */
|
1999-12-04 21:20:09 +00:00
|
|
|
{ "Microsoft Network Monitor 1.x", "netmon1",
|
1999-12-04 09:38:38 +00:00
|
|
|
netmon_dump_can_write_encap, netmon_dump_open },
|
1999-12-04 08:32:14 +00:00
|
|
|
|
|
|
|
/* WTAP_FILE_NETMON_2_x */
|
1999-12-04 21:20:09 +00:00
|
|
|
{ "Microsoft Network Monitor 2.x", NULL,
|
1999-12-04 08:32:14 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
|
|
|
/* WTAP_FILE_NETXRAY_1_0 */
|
1999-12-04 21:20:09 +00:00
|
|
|
{ "Cinco Networks NetXRay", NULL,
|
1999-12-04 08:32:14 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
|
|
|
/* WTAP_FILE_NETXRAY_1_1 */
|
1999-12-04 21:20:09 +00:00
|
|
|
{ "Network Associates Sniffer (Windows-based) 1.1", NULL,
|
1999-12-04 08:32:14 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
|
|
|
/* WTAP_FILE_NETXRAY_2_001 */
|
1999-12-04 21:20:09 +00:00
|
|
|
{ "Network Associates Sniffer (Windows-based) 2.001", NULL,
|
1999-12-04 08:32:14 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
|
|
|
/* WTAP_FILE_RADCOM */
|
1999-12-04 21:20:09 +00:00
|
|
|
{ "RADCOM WAN/LAN analyzer", NULL,
|
1999-12-04 08:32:14 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
|
|
|
/* WTAP_FILE_ASCEND */
|
1999-12-04 21:20:09 +00:00
|
|
|
{ "Lucent/Ascend access server trace", NULL,
|
1999-12-04 08:32:14 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
|
|
|
/* WTAP_FILE_NETTL */
|
1999-12-04 21:20:09 +00:00
|
|
|
{ "HP-UX nettl trace", NULL,
|
1999-12-04 08:32:14 +00:00
|
|
|
NULL, NULL },
|
|
|
|
|
|
|
|
/* WTAP_FILE_TOSHIBA */
|
1999-12-04 21:20:09 +00:00
|
|
|
{ "Toshiba Compact ISDN Router snoop trace", NULL,
|
1999-12-04 08:32:14 +00:00
|
|
|
NULL, NULL }
|
|
|
|
};
|
|
|
|
|
1999-12-04 21:20:09 +00:00
|
|
|
/* Name that should be somewhat descriptive. */
|
1999-12-04 08:51:52 +00:00
|
|
|
const char *wtap_file_type_string(int filetype)
|
1999-12-04 08:32:14 +00:00
|
|
|
{
|
1999-12-04 08:51:52 +00:00
|
|
|
if (filetype < 0 || filetype >= WTAP_NUM_FILE_TYPES) {
|
|
|
|
g_error("Unknown capture file type %d", filetype);
|
1999-12-04 08:32:14 +00:00
|
|
|
return NULL;
|
|
|
|
} else
|
1999-12-04 08:51:52 +00:00
|
|
|
return dump_open_table[filetype].name;
|
1999-12-04 08:32:14 +00:00
|
|
|
}
|
|
|
|
|
1999-12-04 21:20:09 +00:00
|
|
|
/* Name to use in, say, a command-line flag specifying the type. */
|
|
|
|
const char *wtap_file_type_short_string(int filetype)
|
|
|
|
{
|
|
|
|
if (filetype < 0 || filetype >= WTAP_NUM_FILE_TYPES)
|
|
|
|
return NULL;
|
|
|
|
else
|
|
|
|
return dump_open_table[filetype].short_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Translate a short name to a capture file type. */
|
|
|
|
int wtap_short_string_to_file_type(const char *short_name)
|
|
|
|
{
|
|
|
|
int filetype;
|
|
|
|
|
|
|
|
for (filetype = 0; filetype < WTAP_NUM_FILE_TYPES; filetype++) {
|
1999-12-04 21:32:58 +00:00
|
|
|
if (dump_open_table[filetype].short_name != NULL &&
|
|
|
|
strcmp(short_name, dump_open_table[filetype].short_name) == 0)
|
1999-12-04 21:20:09 +00:00
|
|
|
return filetype;
|
|
|
|
}
|
|
|
|
return -1; /* no such file type, or we can't write it */
|
|
|
|
}
|
|
|
|
|
1999-12-04 09:38:38 +00:00
|
|
|
gboolean wtap_dump_can_open(int filetype)
|
1999-12-04 08:32:14 +00:00
|
|
|
{
|
1999-12-04 08:51:52 +00:00
|
|
|
if (filetype < 0 || filetype >= WTAP_NUM_FILE_TYPES
|
1999-12-04 08:32:14 +00:00
|
|
|
|| dump_open_table[filetype].dump_open == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1999-12-04 09:38:38 +00:00
|
|
|
gboolean wtap_dump_can_write_encap(int filetype, int encap)
|
1999-12-04 08:32:14 +00:00
|
|
|
{
|
1999-12-04 08:51:52 +00:00
|
|
|
if (filetype < 0 || filetype >= WTAP_NUM_FILE_TYPES
|
1999-12-04 09:38:38 +00:00
|
|
|
|| dump_open_table[filetype].can_write_encap == NULL)
|
1999-12-04 08:32:14 +00:00
|
|
|
return FALSE;
|
|
|
|
|
1999-12-04 09:38:38 +00:00
|
|
|
if ((*dump_open_table[filetype].can_write_encap)(filetype, encap) != 0)
|
1999-12-04 08:32:14 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return 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
|
|
|
|
|
|
|
static wtap_dumper* wtap_dump_open_common(FILE *fh, int filetype,
|
|
|
|
int encap, int snaplen, int *err);
|
|
|
|
|
|
|
|
wtap_dumper* wtap_dump_open(const char *filename, int filetype, int encap,
|
|
|
|
int snaplen, int *err)
|
|
|
|
{
|
|
|
|
FILE *fh;
|
|
|
|
|
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;
|
1999-09-23 05:00:59 +00:00
|
|
|
fh = fopen(filename, "w");
|
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;
|
|
|
|
return NULL; /* can't create file */
|
|
|
|
}
|
|
|
|
return wtap_dump_open_common(fh, filetype, encap, snaplen, err);
|
|
|
|
}
|
|
|
|
|
|
|
|
wtap_dumper* wtap_dump_fdopen(int fd, int filetype, int encap, int snaplen,
|
|
|
|
int *err)
|
|
|
|
{
|
|
|
|
FILE *fh;
|
|
|
|
|
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;
|
1999-09-23 05:00:59 +00:00
|
|
|
fh = fdopen(fd, "w");
|
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;
|
|
|
|
return NULL; /* can't create standard I/O stream */
|
|
|
|
}
|
|
|
|
return wtap_dump_open_common(fh, filetype, encap, snaplen, err);
|
|
|
|
}
|
|
|
|
|
|
|
|
static wtap_dumper* wtap_dump_open_common(FILE *fh, int filetype, int encap,
|
|
|
|
int snaplen, int *err)
|
|
|
|
{
|
|
|
|
wtap_dumper *wdh;
|
|
|
|
|
1999-12-04 08:51:52 +00:00
|
|
|
if (filetype < 0 || filetype >= WTAP_NUM_FILE_TYPES
|
1999-12-04 08:32:14 +00:00
|
|
|
|| dump_open_table[filetype].dump_open == NULL) {
|
|
|
|
/* Invalid type, or type we don't know how to write. */
|
|
|
|
*err = WTAP_ERR_UNSUPPORTED_FILE_TYPE;
|
|
|
|
/* NOTE: this means the FD handed to "wtap_dump_fdopen()"
|
|
|
|
will be closed if we can't write that file type. */
|
|
|
|
fclose(fh);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* OK, we know how to write that type; can we write the specified
|
|
|
|
encapsulation type? */
|
1999-12-04 09:38:38 +00:00
|
|
|
*err = (*dump_open_table[filetype].can_write_encap)(filetype, encap);
|
1999-12-04 08:32:14 +00:00
|
|
|
if (*err != 0) {
|
|
|
|
/* NOTE: this means the FD handed to "wtap_dump_fdopen()"
|
|
|
|
will be closed if we can't write that encapsulation type. */
|
|
|
|
fclose(fh);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* OK, we can write the specified encapsulation type. Allocate
|
|
|
|
a data structure for the output stream. */
|
1999-11-10 19:47:57 +00:00
|
|
|
wdh = g_malloc(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;
|
|
|
|
/* NOTE: this means the FD handed to "wtap_dump_fdopen()"
|
|
|
|
will be closed if the malloc fails. */
|
1999-09-23 05:00:59 +00:00
|
|
|
fclose(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
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
wdh->fh = fh;
|
|
|
|
wdh->file_type = filetype;
|
|
|
|
wdh->snaplen = snaplen;
|
|
|
|
wdh->encap = encap;
|
1999-12-04 05:37:36 +00:00
|
|
|
wdh->private.opaque = NULL;
|
1999-12-04 08:32:14 +00:00
|
|
|
wdh->subtype_write = NULL;
|
|
|
|
wdh->subtype_close = NULL;
|
|
|
|
|
|
|
|
/* Now try to open the file for writing. */
|
|
|
|
if (!(*dump_open_table[filetype].dump_open)(wdh, err)) {
|
|
|
|
/* The attempt failed. */
|
|
|
|
g_free(wdh);
|
|
|
|
/* NOTE: this means the FD handed to "wtap_dump_fdopen()"
|
|
|
|
will be closed if the open fails. */
|
|
|
|
fclose(fh);
|
|
|
|
return NULL;
|
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
|
|
|
return wdh; /* 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
|
|
|
}
|
|
|
|
|
|
|
|
FILE* wtap_dump_file(wtap_dumper *wdh)
|
|
|
|
{
|
|
|
|
return wdh->fh;
|
|
|
|
}
|
|
|
|
|
1999-12-04 05:14:39 +00:00
|
|
|
gboolean wtap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
|
1999-08-18 04:41:20 +00:00
|
|
|
const u_char *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
|
|
|
{
|
1999-08-18 04:41:20 +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
|
|
|
}
|
|
|
|
|
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;
|
1999-09-23 05:00:59 +00:00
|
|
|
if (fclose(wdh->fh) == EOF) {
|
1999-08-18 04:41:20 +00:00
|
|
|
if (ret) {
|
|
|
|
/* The per-format close function succeeded,
|
1999-09-23 05:00:59 +00:00
|
|
|
but the fclose didn't. Save the reason
|
1999-08-18 04:41:20 +00:00
|
|
|
why, if our caller asked for it. */
|
|
|
|
if (err != NULL)
|
|
|
|
*err = errno;
|
|
|
|
}
|
1999-12-04 05:14:39 +00:00
|
|
|
ret = FALSE;
|
1999-08-18 04:41:20 +00:00
|
|
|
}
|
1999-12-04 05:14:39 +00:00
|
|
|
if (wdh->private.opaque != NULL)
|
|
|
|
g_free(wdh->private.opaque);
|
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;
|
|
|
|
}
|
|
|
|
|
1999-10-05 07:06:08 +00:00
|
|
|
/*
|
|
|
|
* Routine to return a Wiretap error code (0 for no error, an errno
|
|
|
|
* for a file error, or a WTAP_ERR_ code for other errors) for an
|
|
|
|
* I/O stream.
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_LIBZ
|
|
|
|
int
|
|
|
|
file_error(void *fh)
|
|
|
|
{
|
|
|
|
int errnum;
|
|
|
|
|
|
|
|
gzerror(fh, &errnum);
|
|
|
|
switch (errnum) {
|
|
|
|
|
|
|
|
case Z_OK: /* no error */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case Z_STREAM_END: /* EOF - not an error */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case Z_ERRNO: /* file I/O error */
|
|
|
|
return errno;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return WTAP_ERR_ZLIB + errnum;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else /* HAVE_LIBZ */
|
|
|
|
int
|
|
|
|
file_error(FILE *fh)
|
|
|
|
{
|
|
|
|
if (ferror(fh))
|
|
|
|
return errno;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_LIBZ */
|