2012-07-09 23:07:28 +00:00
|
|
|
/* peekclassic.c
|
|
|
|
* Routines for opening files in what WildPackets calls the classic file
|
|
|
|
* format in the description of their "PeekRdr Sample Application" (C++
|
|
|
|
* source code to read their capture files, downloading of which requires
|
|
|
|
* a maintenance contract, so it's not free as in beer and probably not
|
|
|
|
* as in speech, either).
|
|
|
|
*
|
|
|
|
* As that description says, it's used by AiroPeek and AiroPeek NX prior
|
|
|
|
* to 2.0, EtherPeek prior to 6.0, and EtherPeek NX prior to 3.0. It
|
|
|
|
* was probably also used by TokenPeek.
|
|
|
|
*
|
|
|
|
* This handles versions 5, 6, and 7 of that format (the format version
|
|
|
|
* number is what appears in the file, and is distinct from the application
|
|
|
|
* version number).
|
|
|
|
*
|
2001-02-22 22:03:31 +00:00
|
|
|
* Copyright (c) 2001, Daniel Thompson <d.thompson@gmx.net>
|
|
|
|
*
|
|
|
|
* Wiretap Library
|
2001-11-13 23:55:44 +00:00
|
|
|
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
|
2002-08-28 20:30:45 +00:00
|
|
|
*
|
2001-02-22 22:03:31 +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-08-28 20:30:45 +00:00
|
|
|
*
|
2001-02-22 22:03:31 +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-08-28 20:30:45 +00:00
|
|
|
*
|
2001-02-22 22:03:31 +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.
|
2001-02-22 22:03:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "wtap-int.h"
|
|
|
|
#include "file_wrappers.h"
|
2014-07-15 23:40:46 +00:00
|
|
|
#include <wsutil/buffer.h>
|
2012-07-09 23:07:28 +00:00
|
|
|
#include "peekclassic.h"
|
2001-02-22 22:03:31 +00:00
|
|
|
/* CREDITS
|
|
|
|
*
|
|
|
|
* This file decoder could not have been writen without examining how
|
2002-01-18 00:48:37 +00:00
|
|
|
* tcptrace (http://www.tcptrace.org/) handles EtherPeek files.
|
2001-02-22 22:03:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* master header */
|
2012-07-09 23:07:28 +00:00
|
|
|
typedef struct peekclassic_master_header {
|
2001-02-22 22:03:31 +00:00
|
|
|
guint8 version;
|
|
|
|
guint8 status;
|
2012-07-09 23:07:28 +00:00
|
|
|
} peekclassic_master_header_t;
|
|
|
|
#define PEEKCLASSIC_MASTER_HDR_SIZE 2
|
2001-02-22 22:03:31 +00:00
|
|
|
|
2002-01-23 06:32:52 +00:00
|
|
|
/* secondary header (V5,V6,V7) */
|
2012-07-09 23:07:28 +00:00
|
|
|
typedef struct peekclassic_v567_header {
|
2001-02-22 22:03:31 +00:00
|
|
|
guint32 filelength;
|
|
|
|
guint32 numPackets;
|
|
|
|
guint32 timeDate;
|
|
|
|
guint32 timeStart;
|
|
|
|
guint32 timeStop;
|
2002-08-28 20:30:45 +00:00
|
|
|
guint32 mediaType; /* Media Type Ethernet=0 Token Ring = 1 */
|
2002-01-21 23:45:58 +00:00
|
|
|
guint32 physMedium; /* Physical Medium native=0 802.1=1 */
|
|
|
|
guint32 appVers; /* App Version Number Maj.Min.Bug.Build */
|
|
|
|
guint32 linkSpeed; /* Link Speed Bits/sec */
|
2002-08-28 20:30:45 +00:00
|
|
|
guint32 reserved[3];
|
2012-07-09 23:07:28 +00:00
|
|
|
} peekclassic_v567_header_t;
|
|
|
|
#define PEEKCLASSIC_V567_HDR_SIZE 48
|
2001-02-22 22:03:31 +00:00
|
|
|
|
|
|
|
/* full header */
|
2012-07-09 23:07:28 +00:00
|
|
|
typedef struct peekclassic_header {
|
|
|
|
peekclassic_master_header_t master;
|
2001-02-22 22:03:31 +00:00
|
|
|
union {
|
2012-07-09 23:07:28 +00:00
|
|
|
peekclassic_v567_header_t v567;
|
2001-02-22 22:03:31 +00:00
|
|
|
} secondary;
|
2012-07-09 23:07:28 +00:00
|
|
|
} peekclassic_header_t;
|
2001-02-22 22:03:31 +00:00
|
|
|
|
2001-12-05 07:19:11 +00:00
|
|
|
/*
|
2002-01-23 06:32:52 +00:00
|
|
|
* Packet header (V5, V6).
|
2001-12-05 07:19:11 +00:00
|
|
|
*
|
|
|
|
* NOTE: the time stamp, although it's a 32-bit number, is only aligned
|
|
|
|
* on a 16-bit boundary. (Does this date back to 68K Macs? The 68000
|
|
|
|
* only required 16-bit alignment of 32-bit quantities, as did the 68010,
|
|
|
|
* and the 68020/68030/68040 required no alignment.)
|
|
|
|
*
|
|
|
|
* As such, we cannot declare this as a C structure, as compilers on
|
|
|
|
* most platforms will put 2 bytes of padding before the time stamp to
|
|
|
|
* align it on a 32-bit boundary.
|
|
|
|
*
|
|
|
|
* So, instead, we #define numbers as the offsets of the fields.
|
|
|
|
*/
|
2012-07-09 23:07:28 +00:00
|
|
|
#define PEEKCLASSIC_V56_LENGTH_OFFSET 0
|
|
|
|
#define PEEKCLASSIC_V56_SLICE_LENGTH_OFFSET 2
|
|
|
|
#define PEEKCLASSIC_V56_FLAGS_OFFSET 4
|
|
|
|
#define PEEKCLASSIC_V56_STATUS_OFFSET 5
|
|
|
|
#define PEEKCLASSIC_V56_TIMESTAMP_OFFSET 6
|
|
|
|
#define PEEKCLASSIC_V56_DESTNUM_OFFSET 10
|
|
|
|
#define PEEKCLASSIC_V56_SRCNUM_OFFSET 12
|
|
|
|
#define PEEKCLASSIC_V56_PROTONUM_OFFSET 14
|
|
|
|
#define PEEKCLASSIC_V56_PROTOSTR_OFFSET 16
|
|
|
|
#define PEEKCLASSIC_V56_FILTERNUM_OFFSET 24
|
|
|
|
#define PEEKCLASSIC_V56_PKT_SIZE 26
|
2001-02-22 22:03:31 +00:00
|
|
|
|
|
|
|
/* 64-bit time in micro seconds from the (Mac) epoch */
|
2012-07-09 23:07:28 +00:00
|
|
|
typedef struct peekclassic_utime {
|
2001-02-22 22:03:31 +00:00
|
|
|
guint32 upper;
|
|
|
|
guint32 lower;
|
2012-07-09 23:07:28 +00:00
|
|
|
} peekclassic_utime;
|
2001-02-22 22:03:31 +00:00
|
|
|
|
2001-12-05 07:19:11 +00:00
|
|
|
/*
|
2002-01-23 06:32:52 +00:00
|
|
|
* Packet header (V7).
|
2001-12-05 07:19:11 +00:00
|
|
|
*
|
|
|
|
* This doesn't have the same alignment problem, but we do it with
|
|
|
|
* #defines anyway.
|
|
|
|
*/
|
2012-07-09 23:07:28 +00:00
|
|
|
#define PEEKCLASSIC_V7_PROTONUM_OFFSET 0
|
|
|
|
#define PEEKCLASSIC_V7_LENGTH_OFFSET 2
|
|
|
|
#define PEEKCLASSIC_V7_SLICE_LENGTH_OFFSET 4
|
|
|
|
#define PEEKCLASSIC_V7_FLAGS_OFFSET 6
|
|
|
|
#define PEEKCLASSIC_V7_STATUS_OFFSET 7
|
|
|
|
#define PEEKCLASSIC_V7_TIMESTAMP_OFFSET 8
|
|
|
|
#define PEEKCLASSIC_V7_PKT_SIZE 16
|
|
|
|
|
|
|
|
typedef struct peekclassic_encap_lookup {
|
2001-02-22 22:03:31 +00:00
|
|
|
guint16 protoNum;
|
|
|
|
int encap;
|
2012-07-09 23:07:28 +00:00
|
|
|
} peekclassic_encap_lookup_t;
|
2001-02-22 22:03:31 +00:00
|
|
|
|
|
|
|
static const unsigned int mac2unix = 2082844800u;
|
2012-07-09 23:07:28 +00:00
|
|
|
static const peekclassic_encap_lookup_t peekclassic_encap[] = {
|
2001-02-22 22:03:31 +00:00
|
|
|
{ 1400, WTAP_ENCAP_ETHERNET }
|
|
|
|
};
|
2012-07-09 23:07:28 +00:00
|
|
|
#define NUM_PEEKCLASSIC_ENCAPS \
|
|
|
|
(sizeof (peekclassic_encap) / sizeof (peekclassic_encap[0]))
|
2001-02-22 22:03:31 +00:00
|
|
|
|
2010-02-26 07:59:54 +00:00
|
|
|
typedef struct {
|
|
|
|
struct timeval reference_time;
|
2012-07-09 23:07:28 +00:00
|
|
|
} peekclassic_t;
|
2010-02-26 07:59:54 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
static gboolean peekclassic_read_v7(wtap *wth, int *err, gchar **err_info,
|
2006-11-05 22:46:44 +00:00
|
|
|
gint64 *data_offset);
|
2014-05-09 05:18:49 +00:00
|
|
|
static gboolean peekclassic_seek_read_v7(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 peekclassic_read_packet_v7(wtap *wth, FILE_T fh,
|
|
|
|
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
|
|
|
|
static gboolean peekclassic_read_v56(wtap *wth, int *err, gchar **err_info,
|
2006-11-05 22:46:44 +00:00
|
|
|
gint64 *data_offset);
|
2014-05-09 05:18:49 +00:00
|
|
|
static gboolean peekclassic_seek_read_v56(wtap *wth, gint64 seek_off,
|
|
|
|
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
|
|
|
|
static gboolean peekclassic_read_packet_v56(wtap *wth, FILE_T fh,
|
2013-06-17 21:18:47 +00:00
|
|
|
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
|
2001-02-22 22:03:31 +00:00
|
|
|
|
2014-10-09 23:44:15 +00:00
|
|
|
wtap_open_return_val peekclassic_open(wtap *wth, int *err, gchar **err_info)
|
2001-02-22 22:03:31 +00:00
|
|
|
{
|
2012-07-09 23:07:28 +00:00
|
|
|
peekclassic_header_t ep_hdr;
|
2002-01-18 01:08:36 +00:00
|
|
|
struct timeval reference_time;
|
2002-01-21 23:45:58 +00:00
|
|
|
int file_encap;
|
2012-07-09 23:07:28 +00:00
|
|
|
peekclassic_t *peekclassic;
|
2001-02-22 22:03:31 +00:00
|
|
|
|
2012-07-09 23:07:28 +00:00
|
|
|
/* Peek classic files do not start with a magic value large enough
|
2002-01-18 00:48:37 +00:00
|
|
|
* to be unique; hence we use the following algorithm to determine
|
|
|
|
* the type of an unknown file:
|
2001-02-22 22:03:31 +00:00
|
|
|
* - populate the master header and reject file if there is no match
|
|
|
|
* - populate the secondary header and check that the reserved space
|
2002-01-23 06:32:52 +00:00
|
|
|
* is zero, and check some other fields; this isn't perfect,
|
|
|
|
* and we may have to add more checks at some point.
|
2001-02-22 22:03:31 +00:00
|
|
|
*/
|
2012-07-09 23:07:28 +00:00
|
|
|
g_assert(sizeof(ep_hdr.master) == PEEKCLASSIC_MASTER_HDR_SIZE);
|
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, &ep_hdr.master,
|
|
|
|
(int)sizeof(ep_hdr.master), 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;
|
Do not call wtap_file_read_unknown_bytes() or
wtap_file_read_expected_bytes() from an open routine - open routines are
supposed to return -1 on error, 0 if the file doesn't appear to be a
file of the specified type, or 1 if the file does appear to be a file of
the specified type, but those macros will cause the caller to return
FALSE on errors (so that, even if there's an I/O error, it reports "the
file isn't a file of the specified type" rather than "we got an error
trying to read the file").
When doing reads in an open routine before we've concluded that the file
is probably of the right type, return 0, rather than -1, if we get
WTAP_ERR_SHORT_READ - if we don't have enough data to check whether a
file is of a given type, we should keep trying other types, not give up.
For reads done *after* we've concluded the file is probably of the right
type, if a read doesn't return the number of bytes we asked for, but
returns an error of 0, return WTAP_ERR_SHORT_READ - the file is
apparently cut short.
For NetMon and NetXRay/Windows Sniffer files, use a #define for the
magic number size, and use that for both magic numbers.
svn path=/trunk/; revision=46803
2012-12-27 12:19:25 +00:00
|
|
|
}
|
2001-02-22 22:03:31 +00:00
|
|
|
|
2003-12-18 03:43:40 +00:00
|
|
|
/*
|
|
|
|
* It appears that EtherHelp (a free application from WildPackets
|
|
|
|
* that did blind capture, saving to a file, so that you could
|
|
|
|
* give the resulting file to somebody with EtherPeek) saved
|
|
|
|
* captures in EtherPeek format except that it ORed the 0x80
|
|
|
|
* bit on in the version number.
|
|
|
|
*
|
|
|
|
* We therefore strip off the 0x80 bit in the version number.
|
|
|
|
* Perhaps there's some reason to care whether the capture
|
|
|
|
* came from EtherHelp; if we discover one, we should check
|
|
|
|
* that bit.
|
|
|
|
*/
|
|
|
|
ep_hdr.master.version &= ~0x80;
|
|
|
|
|
2001-02-22 22:03:31 +00:00
|
|
|
/* switch on the file version */
|
|
|
|
switch (ep_hdr.master.version) {
|
2002-01-18 00:25:50 +00:00
|
|
|
|
|
|
|
case 5:
|
|
|
|
case 6:
|
|
|
|
case 7:
|
|
|
|
/* get the secondary header */
|
2002-01-23 06:32:52 +00:00
|
|
|
g_assert(sizeof(ep_hdr.secondary.v567) ==
|
2012-07-09 23:07:28 +00:00
|
|
|
PEEKCLASSIC_V567_HDR_SIZE);
|
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, &ep_hdr.secondary.v567,
|
|
|
|
(int)sizeof(ep_hdr.secondary.v567), err, err_info)) {
|
2014-10-07 19:49:14 +00:00
|
|
|
if (*err != WTAP_ERR_SHORT_READ)
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
|
|
|
return WTAP_OPEN_NOT_MINE;
|
Do not call wtap_file_read_unknown_bytes() or
wtap_file_read_expected_bytes() from an open routine - open routines are
supposed to return -1 on error, 0 if the file doesn't appear to be a
file of the specified type, or 1 if the file does appear to be a file of
the specified type, but those macros will cause the caller to return
FALSE on errors (so that, even if there's an I/O error, it reports "the
file isn't a file of the specified type" rather than "we got an error
trying to read the file").
When doing reads in an open routine before we've concluded that the file
is probably of the right type, return 0, rather than -1, if we get
WTAP_ERR_SHORT_READ - if we don't have enough data to check whether a
file is of a given type, we should keep trying other types, not give up.
For reads done *after* we've concluded the file is probably of the right
type, if a read doesn't return the number of bytes we asked for, but
returns an error of 0, return WTAP_ERR_SHORT_READ - the file is
apparently cut short.
For NetMon and NetXRay/Windows Sniffer files, use a #define for the
magic number size, and use that for both magic numbers.
svn path=/trunk/; revision=46803
2012-12-27 12:19:25 +00:00
|
|
|
}
|
2002-01-18 01:08:36 +00:00
|
|
|
|
2002-01-23 06:32:52 +00:00
|
|
|
if ((0 != ep_hdr.secondary.v567.reserved[0]) ||
|
|
|
|
(0 != ep_hdr.secondary.v567.reserved[1]) ||
|
|
|
|
(0 != ep_hdr.secondary.v567.reserved[2])) {
|
2002-01-18 00:25:50 +00:00
|
|
|
/* still unknown */
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_NOT_MINE;
|
2002-01-18 00:25:50 +00:00
|
|
|
}
|
|
|
|
|
2002-01-23 06:32:52 +00:00
|
|
|
/*
|
|
|
|
* Check the mediaType and physMedium fields.
|
2012-07-09 23:07:28 +00:00
|
|
|
* We assume it's not a Peek classic file if
|
|
|
|
* these aren't values we know, rather than
|
|
|
|
* reporting them as invalid Peek classic files,
|
|
|
|
* as, given the lack of a magic number, we need
|
|
|
|
* all the checks we can get.
|
2002-01-18 00:25:50 +00:00
|
|
|
*/
|
2002-01-23 06:32:52 +00:00
|
|
|
ep_hdr.secondary.v567.mediaType =
|
2002-07-29 06:09:59 +00:00
|
|
|
g_ntohl(ep_hdr.secondary.v567.mediaType);
|
2002-01-23 06:32:52 +00:00
|
|
|
ep_hdr.secondary.v567.physMedium =
|
2002-07-29 06:09:59 +00:00
|
|
|
g_ntohl(ep_hdr.secondary.v567.physMedium);
|
2002-01-23 06:32:52 +00:00
|
|
|
|
|
|
|
switch (ep_hdr.secondary.v567.physMedium) {
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
/*
|
|
|
|
* "Native" format, presumably meaning
|
|
|
|
* Ethernet or Token Ring.
|
|
|
|
*/
|
|
|
|
switch (ep_hdr.secondary.v567.mediaType) {
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
file_encap = WTAP_ENCAP_ETHERNET;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
file_encap = WTAP_ENCAP_TOKEN_RING;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/*
|
2012-07-09 23:14:50 +00:00
|
|
|
* Assume this isn't a Peek classic file.
|
2002-01-23 06:32:52 +00:00
|
|
|
*/
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_NOT_MINE;
|
2002-01-23 06:32:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
switch (ep_hdr.secondary.v567.mediaType) {
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
/*
|
|
|
|
* 802.11, with a private header giving
|
|
|
|
* some radio information. Presumably
|
|
|
|
* this is from AiroPeek.
|
|
|
|
*/
|
2012-05-02 03:11:00 +00:00
|
|
|
file_encap = WTAP_ENCAP_IEEE_802_11_AIROPEEK;
|
2002-01-29 09:45:58 +00:00
|
|
|
break;
|
2002-01-23 06:32:52 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
/*
|
2012-07-09 23:14:50 +00:00
|
|
|
* Assume this isn't a Peek classic file.
|
2002-01-23 06:32:52 +00:00
|
|
|
*/
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_NOT_MINE;
|
2002-01-23 06:32:52 +00:00
|
|
|
}
|
2002-02-15 11:35:13 +00:00
|
|
|
break;
|
2002-01-23 06:32:52 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
/*
|
2012-07-09 23:14:50 +00:00
|
|
|
* Assume this isn't a Peek classic file.
|
2002-01-23 06:32:52 +00:00
|
|
|
*/
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_NOT_MINE;
|
2002-01-21 23:45:58 +00:00
|
|
|
}
|
2002-08-28 20:30:45 +00:00
|
|
|
|
2002-01-23 06:32:52 +00:00
|
|
|
|
|
|
|
/*
|
2012-07-09 23:14:50 +00:00
|
|
|
* Assume this is a V5, V6 or V7 Peek classic file, and
|
|
|
|
* byte swap the rest of the fields in the secondary header.
|
2002-01-23 06:32:52 +00:00
|
|
|
*
|
|
|
|
* XXX - we could check the file length if the file were
|
|
|
|
* uncompressed, but it might be compressed.
|
|
|
|
*/
|
|
|
|
ep_hdr.secondary.v567.filelength =
|
2002-07-29 06:09:59 +00:00
|
|
|
g_ntohl(ep_hdr.secondary.v567.filelength);
|
2002-01-23 06:32:52 +00:00
|
|
|
ep_hdr.secondary.v567.numPackets =
|
2002-07-29 06:09:59 +00:00
|
|
|
g_ntohl(ep_hdr.secondary.v567.numPackets);
|
2002-01-23 06:32:52 +00:00
|
|
|
ep_hdr.secondary.v567.timeDate =
|
2002-07-29 06:09:59 +00:00
|
|
|
g_ntohl(ep_hdr.secondary.v567.timeDate);
|
2002-01-23 06:32:52 +00:00
|
|
|
ep_hdr.secondary.v567.timeStart =
|
2002-07-29 06:09:59 +00:00
|
|
|
g_ntohl(ep_hdr.secondary.v567.timeStart);
|
2002-01-23 06:32:52 +00:00
|
|
|
ep_hdr.secondary.v567.timeStop =
|
2002-07-29 06:09:59 +00:00
|
|
|
g_ntohl(ep_hdr.secondary.v567.timeStop);
|
2002-01-23 06:32:52 +00:00
|
|
|
ep_hdr.secondary.v567.appVers =
|
2002-07-29 06:09:59 +00:00
|
|
|
g_ntohl(ep_hdr.secondary.v567.appVers);
|
2002-01-23 06:32:52 +00:00
|
|
|
ep_hdr.secondary.v567.linkSpeed =
|
2002-07-29 06:09:59 +00:00
|
|
|
g_ntohl(ep_hdr.secondary.v567.linkSpeed);
|
2002-01-18 00:25:50 +00:00
|
|
|
|
2002-01-18 01:08:36 +00:00
|
|
|
/* Get the reference time as a "struct timeval" */
|
|
|
|
reference_time.tv_sec =
|
2002-01-23 06:32:52 +00:00
|
|
|
ep_hdr.secondary.v567.timeDate - mac2unix;
|
2002-01-18 01:08:36 +00:00
|
|
|
reference_time.tv_usec = 0;
|
2002-01-18 00:25:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2002-01-23 06:32:52 +00:00
|
|
|
/*
|
2012-07-09 23:14:50 +00:00
|
|
|
* Assume this isn't a Peek classic file.
|
2002-01-23 06:32:52 +00:00
|
|
|
*/
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_NOT_MINE;
|
2001-02-22 22:03:31 +00:00
|
|
|
}
|
|
|
|
|
2002-01-18 00:25:50 +00:00
|
|
|
/*
|
2012-07-09 23:07:28 +00:00
|
|
|
* This is a Peek classic file.
|
2002-01-18 00:25:50 +00:00
|
|
|
*
|
|
|
|
* At this point we have recognised the file type and have populated
|
|
|
|
* the whole ep_hdr structure in host byte order.
|
2001-02-22 22:03:31 +00:00
|
|
|
*/
|
2012-07-09 23:07:28 +00:00
|
|
|
peekclassic = (peekclassic_t *)g_malloc(sizeof(peekclassic_t));
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->priv = (void *)peekclassic;
|
2012-07-09 23:07:28 +00:00
|
|
|
peekclassic->reference_time = reference_time;
|
2001-02-22 22:03:31 +00:00
|
|
|
switch (ep_hdr.master.version) {
|
2002-01-18 00:25:50 +00:00
|
|
|
|
|
|
|
case 5:
|
|
|
|
case 6:
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_PEEKCLASSIC_V56;
|
2002-01-23 06:32:52 +00:00
|
|
|
/*
|
|
|
|
* XXX - can we get the file encapsulation from the
|
|
|
|
* header in the same way we do for V7 files?
|
|
|
|
*/
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->file_encap = WTAP_ENCAP_PER_PACKET;
|
|
|
|
wth->subtype_read = peekclassic_read_v56;
|
|
|
|
wth->subtype_seek_read = peekclassic_seek_read_v56;
|
2002-01-18 00:25:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 7:
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_PEEKCLASSIC_V7;
|
|
|
|
wth->file_encap = file_encap;
|
|
|
|
wth->subtype_read = peekclassic_read_v7;
|
|
|
|
wth->subtype_seek_read = peekclassic_seek_read_v7;
|
2002-01-18 00:25:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* this is impossible */
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
2001-02-22 22:03:31 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->snapshot_length = 0; /* not available in header */
|
2014-09-28 18:37:06 +00:00
|
|
|
wth->file_tsprec = WTAP_TSPREC_USEC;
|
2001-02-22 22:03:31 +00:00
|
|
|
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_MINE;
|
2001-02-22 22:03:31 +00:00
|
|
|
}
|
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean peekclassic_read_v7(wtap *wth, int *err, gchar **err_info,
|
2013-06-02 23:12:58 +00:00
|
|
|
gint64 *data_offset)
|
|
|
|
{
|
2013-06-17 21:18:47 +00:00
|
|
|
int sliceLength;
|
2013-06-03 00:26:16 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
*data_offset = file_tell(wth->fh);
|
2013-06-02 23:12:58 +00:00
|
|
|
|
2013-06-17 21:18:47 +00:00
|
|
|
/* Read the packet. */
|
2014-05-09 05:18:49 +00:00
|
|
|
sliceLength = peekclassic_read_packet_v7(wth, wth->fh, &wth->phdr,
|
|
|
|
wth->frame_buffer, err, err_info);
|
2013-06-17 21:18:47 +00:00
|
|
|
if (sliceLength < 0)
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2013-06-02 23:12:58 +00:00
|
|
|
|
2013-06-03 00:26:16 +00:00
|
|
|
/* Skip extra ignored data at the end of the packet. */
|
2013-06-17 21:18:47 +00:00
|
|
|
if ((guint32)sliceLength > wth->phdr.caplen) {
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!file_skip(wth->fh, sliceLength - wth->phdr.caplen, err))
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2013-06-03 00:26:16 +00:00
|
|
|
}
|
|
|
|
|
2013-06-02 23:12:58 +00:00
|
|
|
/* Records are padded to an even length, so if the slice length
|
|
|
|
is odd, read the padding byte. */
|
2013-06-03 00:26:16 +00:00
|
|
|
if (sliceLength & 0x01) {
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!file_skip(wth->fh, 1, err))
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2013-06-02 23:12:58 +00:00
|
|
|
}
|
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
return TRUE;
|
2013-06-02 23:12:58 +00:00
|
|
|
}
|
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean peekclassic_seek_read_v7(wtap *wth, gint64 seek_off,
|
2014-05-09 05:18:49 +00:00
|
|
|
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
|
2013-06-02 23:12:58 +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;
|
2013-06-02 23:12:58 +00:00
|
|
|
|
2013-06-17 21:18:47 +00:00
|
|
|
/* Read the packet. */
|
2014-05-09 05:18:49 +00:00
|
|
|
if (peekclassic_read_packet_v7(wth, wth->random_fh, phdr, buf,
|
2013-06-17 21:18:47 +00:00
|
|
|
err, err_info) == -1) {
|
|
|
|
if (*err == 0)
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2013-06-17 21:18:47 +00:00
|
|
|
}
|
2014-05-23 10:50:02 +00:00
|
|
|
return TRUE;
|
2013-06-02 23:12:58 +00:00
|
|
|
}
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
static int peekclassic_read_packet_v7(wtap *wth, FILE_T fh,
|
2013-06-17 21:18:47 +00:00
|
|
|
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
|
2001-02-22 22:03:31 +00:00
|
|
|
{
|
2012-07-09 23:07:28 +00:00
|
|
|
guint8 ep_pkt[PEEKCLASSIC_V7_PKT_SIZE];
|
2011-04-12 18:21:05 +00:00
|
|
|
#if 0
|
2001-12-05 07:19:11 +00:00
|
|
|
guint16 protoNum;
|
2011-04-12 18:21:05 +00:00
|
|
|
#endif
|
2001-12-05 07:19:11 +00:00
|
|
|
guint16 length;
|
|
|
|
guint16 sliceLength;
|
2011-04-12 18:21:05 +00:00
|
|
|
#if 0
|
2001-12-05 07:19:11 +00:00
|
|
|
guint8 flags;
|
2011-04-12 18:21:05 +00:00
|
|
|
#endif
|
2001-12-05 07:19:11 +00:00
|
|
|
guint8 status;
|
2005-08-26 19:40:46 +00:00
|
|
|
guint64 timestamp;
|
|
|
|
time_t tsecs;
|
|
|
|
guint32 tusecs;
|
2001-02-22 22:03:31 +00:00
|
|
|
|
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, ep_pkt, sizeof(ep_pkt), err, err_info))
|
2013-06-17 21:18:47 +00:00
|
|
|
return -1;
|
2001-02-22 22:03:31 +00:00
|
|
|
|
2001-12-05 07:19:11 +00:00
|
|
|
/* Extract the fields from the packet */
|
2011-04-12 18:21:05 +00:00
|
|
|
#if 0
|
2013-12-03 20:35:50 +00:00
|
|
|
protoNum = pntoh16(&ep_pkt[PEEKCLASSIC_V7_PROTONUM_OFFSET]);
|
2011-04-12 18:21:05 +00:00
|
|
|
#endif
|
2013-12-03 20:35:50 +00:00
|
|
|
length = pntoh16(&ep_pkt[PEEKCLASSIC_V7_LENGTH_OFFSET]);
|
|
|
|
sliceLength = pntoh16(&ep_pkt[PEEKCLASSIC_V7_SLICE_LENGTH_OFFSET]);
|
2011-04-12 18:21:05 +00:00
|
|
|
#if 0
|
2012-07-09 23:07:28 +00:00
|
|
|
flags = ep_pkt[PEEKCLASSIC_V7_FLAGS_OFFSET];
|
2011-04-12 18:21:05 +00:00
|
|
|
#endif
|
2012-07-09 23:07:28 +00:00
|
|
|
status = ep_pkt[PEEKCLASSIC_V7_STATUS_OFFSET];
|
2013-12-03 20:35:50 +00:00
|
|
|
timestamp = pntoh64(&ep_pkt[PEEKCLASSIC_V7_TIMESTAMP_OFFSET]);
|
2001-02-22 22:03:31 +00:00
|
|
|
|
|
|
|
/* force sliceLength to be the actual length of the packet */
|
2001-12-05 07:19:11 +00:00
|
|
|
if (0 == sliceLength) {
|
|
|
|
sliceLength = length;
|
2001-02-22 22:03:31 +00:00
|
|
|
}
|
|
|
|
|
2013-06-02 23:12:58 +00:00
|
|
|
/* fill in packet header values */
|
2014-05-24 18:28:30 +00:00
|
|
|
phdr->rec_type = REC_TYPE_PACKET;
|
2013-06-02 23:12:58 +00:00
|
|
|
phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
|
|
|
|
tsecs = (time_t) (timestamp/1000000);
|
|
|
|
tusecs = (guint32) (timestamp - tsecs*1000000);
|
|
|
|
phdr->ts.secs = tsecs - mac2unix;
|
|
|
|
phdr->ts.nsecs = tusecs * 1000;
|
|
|
|
phdr->len = length;
|
|
|
|
phdr->caplen = sliceLength;
|
2002-01-21 23:45:58 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
switch (wth->file_encap) {
|
2003-10-01 07:11:49 +00:00
|
|
|
|
2012-05-02 03:11:00 +00:00
|
|
|
case WTAP_ENCAP_IEEE_802_11_AIROPEEK:
|
2013-06-02 23:12:58 +00:00
|
|
|
phdr->pseudo_header.ieee_802_11.fcs_len = 0; /* no FCS */
|
|
|
|
phdr->pseudo_header.ieee_802_11.decrypted = FALSE;
|
2001-02-22 22:03:31 +00:00
|
|
|
|
2002-04-08 09:44:42 +00:00
|
|
|
/*
|
|
|
|
* The last 4 bytes appear to be random data - the length
|
|
|
|
* might include the FCS - so we reduce the length by 4.
|
|
|
|
*
|
|
|
|
* Or maybe this is just the same kind of random 4 bytes
|
|
|
|
* of junk at the end you get in Wireless Sniffer
|
|
|
|
* captures.
|
|
|
|
*/
|
2013-06-02 23:12:58 +00:00
|
|
|
if (phdr->len < 4 || phdr->caplen < 4) {
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup_printf("peekclassic: 802.11 packet has length < 4");
|
2013-06-17 21:18:47 +00:00
|
|
|
return -1;
|
2013-06-02 23:12:58 +00:00
|
|
|
}
|
|
|
|
phdr->len -= 4;
|
|
|
|
phdr->caplen -= 4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WTAP_ENCAP_ETHERNET:
|
|
|
|
/* XXX - it appears that if the low-order bit of
|
|
|
|
"status" is 0, there's an FCS in this frame,
|
|
|
|
and if it's 1, there's 4 bytes of 0. */
|
|
|
|
phdr->pseudo_header.eth.fcs_len = (status & 0x01) ? 0 : 4;
|
|
|
|
break;
|
2002-04-08 09:44:42 +00:00
|
|
|
}
|
|
|
|
|
2013-06-17 21:18:47 +00:00
|
|
|
/* read the packet data */
|
|
|
|
if (!wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return sliceLength;
|
2001-02-22 22:03:31 +00:00
|
|
|
}
|
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean peekclassic_read_v56(wtap *wth, int *err, gchar **err_info,
|
2013-06-02 23:12:58 +00:00
|
|
|
gint64 *data_offset)
|
2002-04-08 09:44:42 +00:00
|
|
|
{
|
2014-05-09 05:18:49 +00:00
|
|
|
*data_offset = file_tell(wth->fh);
|
2002-04-08 09:44:42 +00:00
|
|
|
|
2013-06-17 21:18:47 +00:00
|
|
|
/* read the packet */
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!peekclassic_read_packet_v56(wth, wth->fh, &wth->phdr,
|
|
|
|
wth->frame_buffer, err, err_info))
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2003-10-01 07:11:49 +00:00
|
|
|
|
2013-06-02 23:12:58 +00:00
|
|
|
/*
|
|
|
|
* XXX - is the captured packet data padded to a multiple
|
|
|
|
* of 2 bytes?
|
|
|
|
*/
|
2014-05-23 10:50:02 +00:00
|
|
|
return TRUE;
|
2013-06-02 23:12:58 +00:00
|
|
|
}
|
2003-10-01 07:11:49 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
static gboolean peekclassic_seek_read_v56(wtap *wth, gint64 seek_off,
|
|
|
|
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
|
2013-06-02 23:12:58 +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-10-01 07:11:49 +00:00
|
|
|
|
2013-06-17 21:18:47 +00:00
|
|
|
/* read the packet */
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!peekclassic_read_packet_v56(wth, wth->random_fh, phdr, buf,
|
2013-06-17 21:18:47 +00:00
|
|
|
err, err_info)) {
|
|
|
|
if (*err == 0)
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2013-06-17 21:18:47 +00:00
|
|
|
}
|
2014-05-23 10:50:02 +00:00
|
|
|
return TRUE;
|
2002-04-08 09:44:42 +00:00
|
|
|
}
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
static gboolean peekclassic_read_packet_v56(wtap *wth, FILE_T fh,
|
2013-06-17 21:18:47 +00:00
|
|
|
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
|
2001-02-22 22:03:31 +00:00
|
|
|
{
|
2014-05-09 05:18:49 +00:00
|
|
|
peekclassic_t *peekclassic = (peekclassic_t *)wth->priv;
|
2012-07-09 23:07:28 +00:00
|
|
|
guint8 ep_pkt[PEEKCLASSIC_V56_PKT_SIZE];
|
2001-12-05 07:19:11 +00:00
|
|
|
guint16 length;
|
|
|
|
guint16 sliceLength;
|
2011-04-12 18:21:05 +00:00
|
|
|
#if 0
|
2001-12-05 07:19:11 +00:00
|
|
|
guint8 flags;
|
|
|
|
guint8 status;
|
2011-04-12 18:21:05 +00:00
|
|
|
#endif
|
2001-12-05 07:19:11 +00:00
|
|
|
guint32 timestamp;
|
2011-04-12 18:21:05 +00:00
|
|
|
#if 0
|
2001-12-05 07:19:11 +00:00
|
|
|
guint16 destNum;
|
|
|
|
guint16 srcNum;
|
2011-04-12 18:21:05 +00:00
|
|
|
#endif
|
2001-12-05 07:19:11 +00:00
|
|
|
guint16 protoNum;
|
2013-06-02 23:12:58 +00:00
|
|
|
#if 0
|
2001-12-05 07:19:11 +00:00
|
|
|
char protoStr[8];
|
2013-06-02 23:12:58 +00:00
|
|
|
#endif
|
2001-07-13 00:55:58 +00:00
|
|
|
unsigned int i;
|
2001-02-22 22:03:31 +00:00
|
|
|
|
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, ep_pkt, sizeof(ep_pkt), err, err_info))
|
2014-09-23 01:37:50 +00:00
|
|
|
return FALSE;
|
2001-02-22 22:03:31 +00:00
|
|
|
|
2001-12-05 07:19:11 +00:00
|
|
|
/* Extract the fields from the packet */
|
2013-12-03 20:35:50 +00:00
|
|
|
length = pntoh16(&ep_pkt[PEEKCLASSIC_V56_LENGTH_OFFSET]);
|
|
|
|
sliceLength = pntoh16(&ep_pkt[PEEKCLASSIC_V56_SLICE_LENGTH_OFFSET]);
|
2011-04-12 18:21:05 +00:00
|
|
|
#if 0
|
2012-07-09 23:07:28 +00:00
|
|
|
flags = ep_pkt[PEEKCLASSIC_V56_FLAGS_OFFSET];
|
|
|
|
status = ep_pkt[PEEKCLASSIC_V56_STATUS_OFFSET];
|
2011-04-12 18:21:05 +00:00
|
|
|
#endif
|
2013-12-03 20:35:50 +00:00
|
|
|
timestamp = pntoh32(&ep_pkt[PEEKCLASSIC_V56_TIMESTAMP_OFFSET]);
|
2011-04-12 18:21:05 +00:00
|
|
|
#if 0
|
2013-12-03 20:35:50 +00:00
|
|
|
destNum = pntoh16(&ep_pkt[PEEKCLASSIC_V56_DESTNUM_OFFSET]);
|
|
|
|
srcNum = pntoh16(&ep_pkt[PEEKCLASSIC_V56_SRCNUM_OFFSET]);
|
2011-04-12 18:21:05 +00:00
|
|
|
#endif
|
2013-12-03 20:35:50 +00:00
|
|
|
protoNum = pntoh16(&ep_pkt[PEEKCLASSIC_V56_PROTONUM_OFFSET]);
|
2013-06-02 23:12:58 +00:00
|
|
|
#if 0
|
2012-07-09 23:07:28 +00:00
|
|
|
memcpy(protoStr, &ep_pkt[PEEKCLASSIC_V56_PROTOSTR_OFFSET],
|
2001-12-05 07:19:11 +00:00
|
|
|
sizeof protoStr);
|
2013-06-02 23:12:58 +00:00
|
|
|
#endif
|
2001-02-22 22:03:31 +00:00
|
|
|
|
2002-01-23 06:32:52 +00:00
|
|
|
/*
|
|
|
|
* XXX - is the captured packet data padded to a multiple
|
|
|
|
* of 2 bytes?
|
|
|
|
*/
|
|
|
|
|
2001-02-22 22:03:31 +00:00
|
|
|
/* force sliceLength to be the actual length of the packet */
|
2001-12-05 07:19:11 +00:00
|
|
|
if (0 == sliceLength) {
|
|
|
|
sliceLength = length;
|
2001-02-22 22:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* fill in packet header values */
|
2014-05-24 18:28:30 +00:00
|
|
|
phdr->rec_type = REC_TYPE_PACKET;
|
2013-06-02 23:12:58 +00:00
|
|
|
phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
|
2001-02-22 22:03:31 +00:00
|
|
|
/* timestamp is in milliseconds since reference_time */
|
2013-06-02 23:12:58 +00:00
|
|
|
phdr->ts.secs = peekclassic->reference_time.tv_sec
|
2002-01-18 00:25:50 +00:00
|
|
|
+ (timestamp / 1000);
|
2013-06-02 23:12:58 +00:00
|
|
|
phdr->ts.nsecs = 1000 * (timestamp % 1000) * 1000;
|
|
|
|
phdr->len = length;
|
|
|
|
phdr->caplen = sliceLength;
|
2003-10-01 07:11:49 +00:00
|
|
|
|
2013-06-02 23:12:58 +00:00
|
|
|
phdr->pkt_encap = WTAP_ENCAP_UNKNOWN;
|
2012-07-09 23:07:28 +00:00
|
|
|
for (i=0; i<NUM_PEEKCLASSIC_ENCAPS; i++) {
|
|
|
|
if (peekclassic_encap[i].protoNum == protoNum) {
|
2013-06-02 23:12:58 +00:00
|
|
|
phdr->pkt_encap = peekclassic_encap[i].encap;
|
2003-10-01 07:11:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-02 23:12:58 +00:00
|
|
|
switch (phdr->pkt_encap) {
|
2003-10-01 07:11:49 +00:00
|
|
|
|
|
|
|
case WTAP_ENCAP_ETHERNET:
|
|
|
|
/* We assume there's no FCS in this frame. */
|
2013-06-02 23:12:58 +00:00
|
|
|
phdr->pseudo_header.eth.fcs_len = 0;
|
2003-10-01 07:11:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-06-17 21:18:47 +00:00
|
|
|
/* read the packet data */
|
|
|
|
return wtap_read_packet_bytes(fh, buf, sliceLength, err, err_info);
|
2001-02-22 22:03:31 +00:00
|
|
|
}
|