2003-07-29 19:42:01 +00:00
|
|
|
/* 5views.c
|
|
|
|
*
|
|
|
|
* Wiretap Library
|
|
|
|
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.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
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2003-07-29 19:42:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "wtap-int.h"
|
|
|
|
#include "file_wrappers.h"
|
2014-07-15 23:40:46 +00:00
|
|
|
#include <wsutil/buffer.h>
|
2005-08-02 04:23:39 +00:00
|
|
|
#include "5views.h"
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2003-07-29 20:26:34 +00:00
|
|
|
guint32 Signature;
|
|
|
|
guint32 Size; /* Total size of Header in bytes (included Signature) */
|
|
|
|
guint32 Version; /* Identify version and so the format of this record */
|
|
|
|
guint32 DataSize; /* Total size of data included in the Info Record (except the header size) */
|
|
|
|
guint32 FileType; /* Type of the file */
|
|
|
|
guint32 Reserved[3]; /* Reserved for future use */
|
2003-07-29 19:42:01 +00:00
|
|
|
}t_5VW_Info_Header;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2003-07-29 20:26:34 +00:00
|
|
|
guint32 Type; /* Id of the attribute */
|
|
|
|
guint16 Size; /* Size of the data part of the attribute (not including header size) */
|
|
|
|
guint16 Nb; /* Number of elements */
|
2003-07-29 19:42:01 +00:00
|
|
|
}t_5VW_Attributes_Header;
|
|
|
|
|
|
|
|
|
2008-02-09 23:35:28 +00:00
|
|
|
#define CST_5VW_INFO_HEADER_KEY 0xAAAAAAAAU /* signature */
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2008-02-09 23:35:28 +00:00
|
|
|
#define CST_5VW_INFO_RECORD_VERSION 0x00010000U /* version */
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
#define CST_5VW_DECALE_FILE_TYPE 24
|
2008-02-09 23:35:28 +00:00
|
|
|
#define CST_5VW_SECTION_CAPTURES 0x08U
|
2003-07-29 19:42:01 +00:00
|
|
|
#define CST_5VW_CAPTURES_FILE (CST_5VW_SECTION_CAPTURES << CST_5VW_DECALE_FILE_TYPE) /* 0x08000000 */
|
2008-02-09 23:35:28 +00:00
|
|
|
#define CST_5VW_FLAT_FILE 0x10000000U
|
2003-07-29 19:42:01 +00:00
|
|
|
#define CST_5VW_CAPTURE_FILEID (CST_5VW_FLAT_FILE | CST_5VW_CAPTURES_FILE)
|
2008-02-09 23:35:28 +00:00
|
|
|
#define CST_5VW_FAMILY_CAP_ETH 0x01U
|
|
|
|
#define CST_5VW_FAMILY_CAP_WAN 0x02U
|
2003-07-29 19:42:01 +00:00
|
|
|
#define CST_5VW_DECALE_FILE_FAMILY 12
|
|
|
|
#define CST_5VW_CAP_ETH (CST_5VW_FAMILY_CAP_ETH << CST_5VW_DECALE_FILE_FAMILY) /* 0x00001000 */
|
|
|
|
#define CST_5VW_CAP_WAN (CST_5VW_FAMILY_CAP_WAN << CST_5VW_DECALE_FILE_FAMILY) /* 0x00002000 */
|
|
|
|
#define CST_5VW_CAPTURE_ETH_FILEID (CST_5VW_CAPTURE_FILEID | CST_5VW_CAP_ETH)
|
|
|
|
#define CST_5VW_CAPTURE_WAN_FILEID (CST_5VW_CAPTURE_FILEID | CST_5VW_CAP_WAN)
|
|
|
|
|
2008-02-09 23:35:28 +00:00
|
|
|
#define CST_5VW_CAPTURE_FILE_TYPE_MASK 0xFF000000U
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2008-02-09 23:35:28 +00:00
|
|
|
#define CST_5VW_FRAME_RECORD 0x00000000U
|
|
|
|
#define CST_5VW_RECORDS_HEADER_KEY 0x3333EEEEU
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
t_5VW_Info_Header Info_Header;
|
|
|
|
t_5VW_Attributes_Header HeaderDateCreation;
|
2003-07-29 20:26:34 +00:00
|
|
|
guint32 Time;
|
2003-07-29 19:42:01 +00:00
|
|
|
t_5VW_Attributes_Header HeaderNbFrames;
|
2003-07-29 20:26:34 +00:00
|
|
|
guint32 TramesStockeesInFile;
|
2003-07-29 19:42:01 +00:00
|
|
|
}t_5VW_Capture_Header;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2003-07-29 20:26:34 +00:00
|
|
|
guint32 Key; /* 0x3333EEEE */
|
|
|
|
guint16 HeaderSize; /* Actual size of this header in bytes (32) */
|
|
|
|
guint16 HeaderType; /* Exact type of this header (0x4000) */
|
|
|
|
guint32 RecType; /* Type of record */
|
|
|
|
guint32 RecSubType; /* Subtype of record */
|
|
|
|
guint32 RecSize; /* Size of one record */
|
|
|
|
guint32 RecNb; /* Number of records */
|
|
|
|
guint32 Utc;
|
|
|
|
guint32 NanoSecondes;
|
|
|
|
guint32 RecInfo; /* Info about Alarm / Event / Frame captured */
|
2003-07-29 19:42:01 +00:00
|
|
|
}t_5VW_TimeStamped_Header;
|
|
|
|
|
|
|
|
|
2008-02-09 23:35:28 +00:00
|
|
|
#define CST_5VW_IA_CAP_INF_NB_TRAMES_STOCKEES 0x20000000U
|
|
|
|
#define CST_5VW_IA_DATE_CREATION 0x80000007U /* Struct t_Attrib_Date_Create */
|
|
|
|
#define CST_5VW_TIMESTAMPED_HEADER_TYPE 0x4000U
|
2003-07-29 19:42:01 +00:00
|
|
|
#define CST_5VW_CAPTURES_RECORD (CST_5VW_SECTION_CAPTURES << 28) /* 0x80000000 */
|
2008-02-09 23:35:28 +00:00
|
|
|
#define CST_5VW_SYSTEM_RECORD 0x00000000U
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean _5views_read(wtap *wth, int *err, gchar **err_info,
|
2006-11-05 22:46:44 +00:00
|
|
|
gint64 *data_offset);
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean _5views_seek_read(wtap *wth, gint64 seek_off,
|
2014-01-02 20:47:21 +00:00
|
|
|
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
|
2014-05-09 05:18:49 +00:00
|
|
|
static int _5views_read_header(wtap *wth, FILE_T fh, t_5VW_TimeStamped_Header *hdr,
|
2013-05-16 21:19:53 +00:00
|
|
|
struct wtap_pkthdr *phdr, int *err, gchar **err_info);
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
static gboolean _5views_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, const guint8 *pd, int *err);
|
|
|
|
static gboolean _5views_dump_close(wtap_dumper *wdh, int *err);
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
|
2014-10-09 23:44:15 +00:00
|
|
|
wtap_open_return_val
|
|
|
|
_5views_open(wtap *wth, int *err, gchar **err_info)
|
2003-07-29 19:42:01 +00:00
|
|
|
{
|
|
|
|
t_5VW_Capture_Header Capture_Header;
|
|
|
|
int encap = WTAP_ENCAP_UNKNOWN;
|
|
|
|
|
Add some higher-level file-read APIs and use them.
Add wtap_read_bytes(), which takes a FILE_T, a pointer, a byte count, an
error number pointer, and an error string pointer as arguments, and that
treats a short read of any sort, including a read that returns 0 bytes,
as a WTAP_ERR_SHORT_READ error, and that returns the error number and
string through its last two arguments.
Add wtap_read_bytes_or_eof(), which is similar, but that treats a read
that returns 0 bytes as an EOF, supplying an error number of 0 as an EOF
indication.
Use those in file readers; that simplifies the code and makes it less
likely that somebody will fail to supply the error number and error
string on a file read error.
Change-Id: Ia5dba2a6f81151e87b614461349d611cffc16210
Reviewed-on: https://code.wireshark.org/review/4512
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-10-07 01:00:57 +00:00
|
|
|
if (!wtap_read_bytes(wth->fh, &Capture_Header.Info_Header,
|
|
|
|
sizeof(t_5VW_Info_Header), err, err_info)) {
|
|
|
|
if (*err != WTAP_ERR_SHORT_READ)
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
|
|
|
return WTAP_OPEN_NOT_MINE;
|
2003-07-29 19:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check whether that's 5Views format or not */
|
|
|
|
if(Capture_Header.Info_Header.Signature != CST_5VW_INFO_HEADER_KEY)
|
|
|
|
{
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_NOT_MINE;
|
2003-07-29 19:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check Version */
|
2003-07-29 20:26:34 +00:00
|
|
|
Capture_Header.Info_Header.Version =
|
2013-12-03 20:35:50 +00:00
|
|
|
pletoh32(&Capture_Header.Info_Header.Version);
|
2003-07-29 19:42:01 +00:00
|
|
|
switch (Capture_Header.Info_Header.Version) {
|
|
|
|
|
|
|
|
case CST_5VW_INFO_RECORD_VERSION:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
*err = WTAP_ERR_UNSUPPORTED;
|
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
|
|
|
*err_info = g_strdup_printf("5views: header version %u unsupported", Capture_Header.Info_Header.Version);
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
2003-07-29 19:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check File Type */
|
2003-07-29 20:26:34 +00:00
|
|
|
Capture_Header.Info_Header.FileType =
|
2013-12-03 20:35:50 +00:00
|
|
|
pletoh32(&Capture_Header.Info_Header.FileType);
|
2003-07-29 19:42:01 +00:00
|
|
|
if((Capture_Header.Info_Header.FileType & CST_5VW_CAPTURE_FILE_TYPE_MASK) != CST_5VW_CAPTURE_FILEID)
|
|
|
|
{
|
|
|
|
*err = WTAP_ERR_UNSUPPORTED;
|
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
|
|
|
*err_info = g_strdup_printf("5views: file is not a capture file (filetype is %u)", Capture_Header.Info_Header.Version);
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
2003-07-29 19:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check possible Encap */
|
|
|
|
switch (Capture_Header.Info_Header.FileType) {
|
|
|
|
case CST_5VW_CAPTURE_ETH_FILEID:
|
|
|
|
encap = WTAP_ENCAP_ETHERNET;
|
|
|
|
break;
|
|
|
|
/* case CST_5VW_CAPTURE_WAN_FILEID:
|
|
|
|
break;
|
|
|
|
*/
|
|
|
|
default:
|
|
|
|
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
|
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
|
|
|
*err_info = g_strdup_printf("5views: network type %u unknown or unsupported",
|
|
|
|
Capture_Header.Info_Header.FileType);
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
2003-07-29 19:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* read the remaining header information */
|
Add some higher-level file-read APIs and use them.
Add wtap_read_bytes(), which takes a FILE_T, a pointer, a byte count, an
error number pointer, and an error string pointer as arguments, and that
treats a short read of any sort, including a read that returns 0 bytes,
as a WTAP_ERR_SHORT_READ error, and that returns the error number and
string through its last two arguments.
Add wtap_read_bytes_or_eof(), which is similar, but that treats a read
that returns 0 bytes as an EOF, supplying an error number of 0 as an EOF
indication.
Use those in file readers; that simplifies the code and makes it less
likely that somebody will fail to supply the error number and error
string on a file read error.
Change-Id: Ia5dba2a6f81151e87b614461349d611cffc16210
Reviewed-on: https://code.wireshark.org/review/4512
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-10-07 01:00:57 +00:00
|
|
|
if (!wtap_read_bytes(wth->fh, &Capture_Header.HeaderDateCreation,
|
|
|
|
sizeof (t_5VW_Capture_Header) - sizeof(t_5VW_Info_Header), err, err_info))
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
/* This is a 5views capture file */
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_5VIEWS;
|
|
|
|
wth->subtype_read = _5views_read;
|
|
|
|
wth->subtype_seek_read = _5views_seek_read;
|
|
|
|
wth->file_encap = encap;
|
|
|
|
wth->snapshot_length = 0; /* not available in header */
|
2014-09-28 18:37:06 +00:00
|
|
|
wth->file_tsprec = WTAP_TSPREC_NSEC;
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_MINE;
|
2003-07-29 19:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the next packet */
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean
|
2014-05-09 05:18:49 +00:00
|
|
|
_5views_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
|
2003-07-29 19:42:01 +00:00
|
|
|
{
|
|
|
|
t_5VW_TimeStamped_Header TimeStamped_Header;
|
|
|
|
|
2013-05-16 21:19:53 +00:00
|
|
|
/*
|
|
|
|
* Keep reading until we see a record with a subtype of
|
|
|
|
* CST_5VW_FRAME_RECORD.
|
|
|
|
*/
|
2003-07-29 19:42:01 +00:00
|
|
|
do
|
|
|
|
{
|
2014-05-09 05:18:49 +00:00
|
|
|
*data_offset = file_tell(wth->fh);
|
2013-05-16 21:19:53 +00:00
|
|
|
|
|
|
|
/* Read record header. */
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!_5views_read_header(wth, wth->fh, &TimeStamped_Header,
|
2013-05-16 21:19:53 +00:00
|
|
|
&wth->phdr, err, err_info))
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2013-05-16 21:19:53 +00:00
|
|
|
|
|
|
|
if (TimeStamped_Header.RecSubType == CST_5VW_FRAME_RECORD) {
|
2003-07-29 19:42:01 +00:00
|
|
|
/*
|
2013-05-16 21:19:53 +00:00
|
|
|
* OK, this is a packet.
|
2003-07-29 19:42:01 +00:00
|
|
|
*/
|
2013-05-16 21:19:53 +00:00
|
|
|
break;
|
2003-07-29 19:42:01 +00:00
|
|
|
}
|
|
|
|
|
2013-05-16 21:19:53 +00:00
|
|
|
/*
|
|
|
|
* Not a packet - skip to the next record.
|
|
|
|
*/
|
2014-05-09 05:18:49 +00:00
|
|
|
if (file_seek(wth->fh, TimeStamped_Header.RecSize, SEEK_CUR, err) == -1)
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2003-07-29 19:42:01 +00:00
|
|
|
} while (1);
|
|
|
|
|
2013-05-16 21:19:53 +00:00
|
|
|
if (wth->phdr.caplen > WTAP_MAX_PACKET_SIZE) {
|
2011-12-13 00:57:09 +00:00
|
|
|
/*
|
|
|
|
* Probably a corrupt capture file; don't blow up trying
|
|
|
|
* to allocate space for an immensely-large packet.
|
|
|
|
*/
|
2011-12-13 09:53:50 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
2011-12-13 00:57:09 +00:00
|
|
|
*err_info = g_strdup_printf("5views: File has %u-byte packet, bigger than maximum of %u",
|
2013-05-16 21:19:53 +00:00
|
|
|
wth->phdr.caplen, WTAP_MAX_PACKET_SIZE);
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2011-12-13 00:57:09 +00:00
|
|
|
}
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
return wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
|
|
|
|
wth->phdr.caplen, err, err_info);
|
2003-07-29 19:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-05-09 05:18:49 +00:00
|
|
|
_5views_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
|
2014-01-02 20:47:21 +00:00
|
|
|
Buffer *buf, int *err, gchar **err_info)
|
2003-07-29 19:42:01 +00:00
|
|
|
{
|
2013-05-16 21:19:53 +00:00
|
|
|
t_5VW_TimeStamped_Header TimeStamped_Header;
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2013-05-16 21:19:53 +00:00
|
|
|
/*
|
|
|
|
* Read the header.
|
|
|
|
*/
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!_5views_read_header(wth, wth->random_fh, &TimeStamped_Header,
|
2013-12-31 23:30:18 +00:00
|
|
|
phdr, err, err_info)) {
|
|
|
|
if (*err == 0)
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2013-12-31 23:30:18 +00:00
|
|
|
}
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2013-05-16 21:19:53 +00:00
|
|
|
/*
|
|
|
|
* Read the packet data.
|
|
|
|
*/
|
2014-05-23 10:50:02 +00:00
|
|
|
return wtap_read_packet_bytes(wth->random_fh, buf, phdr->caplen,
|
|
|
|
err, err_info);
|
2013-05-16 21:19:53 +00:00
|
|
|
}
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2013-05-16 21:19:53 +00:00
|
|
|
/* Read the header of the next packet. Return TRUE on success, FALSE
|
|
|
|
on error. */
|
|
|
|
static gboolean
|
2014-05-09 05:18:49 +00:00
|
|
|
_5views_read_header(wtap *wth, FILE_T fh, t_5VW_TimeStamped_Header *hdr,
|
2013-05-16 21:19:53 +00:00
|
|
|
struct wtap_pkthdr *phdr, int *err, gchar **err_info)
|
2003-07-29 19:42:01 +00:00
|
|
|
{
|
|
|
|
/* Read record header. */
|
Add some higher-level file-read APIs and use them.
Add wtap_read_bytes(), which takes a FILE_T, a pointer, a byte count, an
error number pointer, and an error string pointer as arguments, and that
treats a short read of any sort, including a read that returns 0 bytes,
as a WTAP_ERR_SHORT_READ error, and that returns the error number and
string through its last two arguments.
Add wtap_read_bytes_or_eof(), which is similar, but that treats a read
that returns 0 bytes as an EOF, supplying an error number of 0 as an EOF
indication.
Use those in file readers; that simplifies the code and makes it less
likely that somebody will fail to supply the error number and error
string on a file read error.
Change-Id: Ia5dba2a6f81151e87b614461349d611cffc16210
Reviewed-on: https://code.wireshark.org/review/4512
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-10-07 01:00:57 +00:00
|
|
|
if (!wtap_read_bytes_or_eof(fh, hdr, (unsigned int)sizeof(t_5VW_TimeStamped_Header),
|
|
|
|
err, err_info))
|
2013-05-16 21:19:53 +00:00
|
|
|
return FALSE;
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2013-12-03 20:35:50 +00:00
|
|
|
hdr->Key = pletoh32(&hdr->Key);
|
2013-05-16 21:19:53 +00:00
|
|
|
if (hdr->Key != CST_5VW_RECORDS_HEADER_KEY) {
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup_printf("5views: Time-stamped header has bad key value 0x%08X",
|
|
|
|
hdr->Key);
|
2003-07-29 19:42:01 +00:00
|
|
|
return FALSE;
|
2013-05-16 21:19:53 +00:00
|
|
|
}
|
|
|
|
|
2013-12-03 20:35:50 +00:00
|
|
|
hdr->RecSubType = pletoh32(&hdr->RecSubType);
|
|
|
|
hdr->RecSize = pletoh32(&hdr->RecSize);
|
|
|
|
hdr->Utc = pletoh32(&hdr->Utc);
|
|
|
|
hdr->NanoSecondes = pletoh32(&hdr->NanoSecondes);
|
2013-05-16 21:19:53 +00:00
|
|
|
|
2014-05-24 18:28:30 +00:00
|
|
|
phdr->rec_type = REC_TYPE_PACKET;
|
2014-04-25 21:25:47 +00:00
|
|
|
phdr->presence_flags = WTAP_HAS_TS;
|
2013-05-16 21:19:53 +00:00
|
|
|
phdr->ts.secs = hdr->Utc;
|
|
|
|
phdr->ts.nsecs = hdr->NanoSecondes;
|
|
|
|
phdr->caplen = hdr->RecSize;
|
|
|
|
phdr->len = hdr->RecSize;
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
switch (wth->file_encap) {
|
2003-10-01 07:11:49 +00:00
|
|
|
|
|
|
|
case WTAP_ENCAP_ETHERNET:
|
|
|
|
/* We assume there's no FCS in this frame. */
|
2013-05-16 21:19:53 +00:00
|
|
|
phdr->pseudo_header.eth.fcs_len = 0;
|
2003-10-01 07:11:49 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-02-26 07:59:54 +00:00
|
|
|
typedef struct {
|
|
|
|
guint32 nframes;
|
|
|
|
} _5views_dump_t;
|
|
|
|
|
2003-07-29 19:42:01 +00:00
|
|
|
static const int wtap_encap[] = {
|
|
|
|
-1, /* WTAP_ENCAP_UNKNOWN -> unsupported */
|
2011-12-22 09:22:35 +00:00
|
|
|
CST_5VW_CAPTURE_ETH_FILEID, /* WTAP_ENCAP_ETHERNET -> Ethernet */
|
2003-07-29 19:42:01 +00:00
|
|
|
};
|
|
|
|
#define NUM_WTAP_ENCAPS (sizeof wtap_encap / sizeof wtap_encap[0])
|
|
|
|
|
|
|
|
/* Returns 0 if we could write the specified encapsulation type,
|
|
|
|
an error indication otherwise. */
|
|
|
|
int _5views_dump_can_write_encap(int encap)
|
|
|
|
{
|
|
|
|
/* Per-packet encapsulations aren't supported. */
|
|
|
|
if (encap == WTAP_ENCAP_PER_PACKET)
|
|
|
|
return WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED;
|
|
|
|
|
2014-06-16 22:00:23 +00:00
|
|
|
if (encap < 0 || (unsigned int) encap >= NUM_WTAP_ENCAPS || wtap_encap[encap] == -1)
|
2003-07-29 19:42:01 +00:00
|
|
|
return WTAP_ERR_UNSUPPORTED_ENCAP;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on
|
|
|
|
failure */
|
2014-05-09 05:18:49 +00:00
|
|
|
gboolean _5views_dump_open(wtap_dumper *wdh, int *err)
|
2003-07-29 19:42:01 +00:00
|
|
|
{
|
2010-02-26 07:59:54 +00:00
|
|
|
_5views_dump_t *_5views;
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
/* We can't fill in all the fields in the file header, as we
|
|
|
|
haven't yet written any packets. As we'll have to rewrite
|
|
|
|
the header when we've written out all the packets, we just
|
|
|
|
skip over the header for now. */
|
2014-05-09 05:18:49 +00:00
|
|
|
if (wtap_dump_file_seek(wdh, sizeof(t_5VW_Capture_Header), SEEK_SET, err) == -1)
|
2003-07-29 19:42:01 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* This is a 5Views file */
|
|
|
|
wdh->subtype_write = _5views_dump;
|
|
|
|
wdh->subtype_close = _5views_dump_close;
|
2010-02-26 07:59:54 +00:00
|
|
|
_5views = (_5views_dump_t *)g_malloc(sizeof(_5views_dump_t));
|
|
|
|
wdh->priv = (void *)_5views;
|
|
|
|
_5views->nframes = 0;
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write a record for a packet to a dump file.
|
|
|
|
Returns TRUE on success, FALSE on failure. */
|
2014-05-09 05:18:49 +00:00
|
|
|
static gboolean _5views_dump(wtap_dumper *wdh,
|
|
|
|
const struct wtap_pkthdr *phdr,
|
2011-09-01 09:43:10 +00:00
|
|
|
const guint8 *pd, int *err)
|
2003-07-29 19:42:01 +00:00
|
|
|
{
|
2010-02-26 07:59:54 +00:00
|
|
|
_5views_dump_t *_5views = (_5views_dump_t *)wdh->priv;
|
2013-07-29 07:28:28 +00:00
|
|
|
t_5VW_TimeStamped_Header HeaderFrame;
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2014-05-24 18:28:30 +00:00
|
|
|
/* We can only write packet records. */
|
|
|
|
if (phdr->rec_type != REC_TYPE_PACKET) {
|
|
|
|
*err = WTAP_ERR_REC_TYPE_UNSUPPORTED;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-01-22 00:26:36 +00:00
|
|
|
/* Don't write out something bigger than we can read. */
|
|
|
|
if (phdr->caplen > WTAP_MAX_PACKET_SIZE) {
|
|
|
|
*err = WTAP_ERR_PACKET_TOO_LARGE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-07-29 19:42:01 +00:00
|
|
|
/* Frame Header */
|
|
|
|
/* constant fields */
|
2013-11-29 18:44:00 +00:00
|
|
|
HeaderFrame.Key = GUINT32_TO_LE(CST_5VW_RECORDS_HEADER_KEY);
|
|
|
|
HeaderFrame.HeaderSize = GUINT16_TO_LE(sizeof(t_5VW_TimeStamped_Header));
|
|
|
|
HeaderFrame.HeaderType = GUINT16_TO_LE(CST_5VW_TIMESTAMPED_HEADER_TYPE);
|
|
|
|
HeaderFrame.RecType = GUINT32_TO_LE(CST_5VW_CAPTURES_RECORD | CST_5VW_SYSTEM_RECORD);
|
|
|
|
HeaderFrame.RecSubType = GUINT32_TO_LE(CST_5VW_FRAME_RECORD);
|
|
|
|
HeaderFrame.RecNb = GUINT32_TO_LE(1);
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2013-07-29 07:28:28 +00:00
|
|
|
/* record-dependent fields */
|
2013-11-29 18:44:00 +00:00
|
|
|
HeaderFrame.Utc = GUINT32_TO_LE(phdr->ts.secs);
|
|
|
|
HeaderFrame.NanoSecondes = GUINT32_TO_LE(phdr->ts.nsecs);
|
|
|
|
HeaderFrame.RecSize = GUINT32_TO_LE(phdr->len);
|
|
|
|
HeaderFrame.RecInfo = GUINT32_TO_LE(0);
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
/* write the record header */
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &HeaderFrame,
|
2010-06-06 22:19:30 +00:00
|
|
|
sizeof(t_5VW_TimeStamped_Header), err))
|
2003-07-29 19:42:01 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* write the data */
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err))
|
2003-07-29 19:42:01 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2010-02-26 07:59:54 +00:00
|
|
|
_5views->nframes ++;
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
static gboolean _5views_dump_close(wtap_dumper *wdh, int *err)
|
2003-07-29 19:42:01 +00:00
|
|
|
{
|
2010-02-26 07:59:54 +00:00
|
|
|
_5views_dump_t *_5views = (_5views_dump_t *)wdh->priv;
|
2003-07-29 19:42:01 +00:00
|
|
|
t_5VW_Capture_Header file_hdr;
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if (wtap_dump_file_seek(wdh, 0, SEEK_SET, err) == -1)
|
2003-07-29 19:42:01 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* fill in the Info_Header */
|
2013-11-29 18:44:00 +00:00
|
|
|
file_hdr.Info_Header.Signature = GUINT32_TO_LE(CST_5VW_INFO_HEADER_KEY);
|
|
|
|
file_hdr.Info_Header.Size = GUINT32_TO_LE(sizeof(t_5VW_Info_Header)); /* Total size of Header in bytes (included Signature) */
|
|
|
|
file_hdr.Info_Header.Version = GUINT32_TO_LE(CST_5VW_INFO_RECORD_VERSION); /* Identify version and so the format of this record */
|
|
|
|
file_hdr.Info_Header.DataSize = GUINT32_TO_LE(sizeof(t_5VW_Attributes_Header)
|
2003-07-29 20:26:34 +00:00
|
|
|
+ sizeof(guint32)
|
|
|
|
+ sizeof(t_5VW_Attributes_Header)
|
|
|
|
+ sizeof(guint32));
|
|
|
|
/* Total size of data included in the Info Record (except the header size) */
|
2013-11-29 18:44:00 +00:00
|
|
|
file_hdr.Info_Header.FileType = GUINT32_TO_LE(wtap_encap[wdh->encap]); /* Type of the file */
|
2003-07-29 20:26:34 +00:00
|
|
|
file_hdr.Info_Header.Reserved[0] = 0; /* Reserved for future use */
|
|
|
|
file_hdr.Info_Header.Reserved[1] = 0; /* Reserved for future use */
|
|
|
|
file_hdr.Info_Header.Reserved[2] = 0; /* Reserved for future use */
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
/* fill in the HeaderDateCreation */
|
2013-11-29 18:44:00 +00:00
|
|
|
file_hdr.HeaderDateCreation.Type = GUINT32_TO_LE(CST_5VW_IA_DATE_CREATION); /* Id of the attribute */
|
|
|
|
file_hdr.HeaderDateCreation.Size = GUINT16_TO_LE(sizeof(guint32)); /* Size of the data part of the attribute (not including header size) */
|
|
|
|
file_hdr.HeaderDateCreation.Nb = GUINT16_TO_LE(1); /* Number of elements */
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
/* fill in the Time field */
|
|
|
|
#ifdef _WIN32
|
|
|
|
_tzset();
|
|
|
|
#endif
|
2013-11-29 18:44:00 +00:00
|
|
|
file_hdr.Time = GUINT32_TO_LE(time(NULL));
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
/* fill in the Time field */
|
2013-11-29 18:44:00 +00:00
|
|
|
file_hdr.HeaderNbFrames.Type = GUINT32_TO_LE(CST_5VW_IA_CAP_INF_NB_TRAMES_STOCKEES); /* Id of the attribute */
|
|
|
|
file_hdr.HeaderNbFrames.Size = GUINT16_TO_LE(sizeof(guint32)); /* Size of the data part of the attribute (not including header size) */
|
|
|
|
file_hdr.HeaderNbFrames.Nb = GUINT16_TO_LE(1); /* Number of elements */
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
/* fill in the number of frames saved */
|
2013-11-29 18:44:00 +00:00
|
|
|
file_hdr.TramesStockeesInFile = GUINT32_TO_LE(_5views->nframes);
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
/* Write the file header. */
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &file_hdr, sizeof(t_5VW_Capture_Header),
|
2010-06-06 22:19:30 +00:00
|
|
|
err))
|
2003-07-29 19:42:01 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|