1998-11-12 06:01:27 +00:00
|
|
|
/* lanalyzer.c
|
|
|
|
*
|
|
|
|
* Wiretap Library
|
2001-11-13 23:55:44 +00:00
|
|
|
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
|
2002-06-27 22:46:48 +00:00
|
|
|
*
|
1998-11-12 06:01:27 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-06-27 22:46:48 +00:00
|
|
|
*
|
1998-11-12 06:01:27 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2002-06-27 22:46:48 +00:00
|
|
|
*
|
1998-11-12 06:01:27 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
1998-11-12 06:01:27 +00:00
|
|
|
*/
|
2002-03-04 00:25:35 +00:00
|
|
|
|
1999-07-13 02:53:26 +00:00
|
|
|
#include "config.h"
|
1998-11-15 05:29:17 +00:00
|
|
|
#include <stdlib.h>
|
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
|
|
|
#include <errno.h>
|
2000-05-19 23:07:04 +00:00
|
|
|
#include "wtap-int.h"
|
2000-01-13 07:09:20 +00:00
|
|
|
#include "file_wrappers.h"
|
2014-07-15 23:40:46 +00:00
|
|
|
#include <wsutil/buffer.h>
|
1998-11-12 06:01:27 +00:00
|
|
|
#include "lanalyzer.h"
|
|
|
|
|
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 LANalyzer format is documented (at least in part) in Novell document
|
|
|
|
TID022037, which can be found at, among other places:
|
|
|
|
|
2009-10-26 18:41:54 +00:00
|
|
|
http://www.windowsecurity.com/whitepapers/Description_of_the_LANalysers_output_file.html
|
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
|
|
|
*/
|
|
|
|
|
2011-07-10 22:57:59 +00:00
|
|
|
/* Record header format */
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
guint8 record_type[2];
|
|
|
|
guint8 record_length[2];
|
|
|
|
} LA_RecordHeader;
|
|
|
|
|
|
|
|
#define LA_RecordHeaderSize 4
|
|
|
|
|
|
|
|
/* Record type codes: */
|
|
|
|
|
|
|
|
#define RT_HeaderRegular 0x1001
|
|
|
|
#define RT_HeaderCyclic 0x1007
|
|
|
|
#define RT_RxChannelName 0x1006
|
|
|
|
#define RT_TxChannelName 0x100b
|
|
|
|
#define RT_FilterName 0x1032
|
|
|
|
#define RT_RxTemplateName 0x1035
|
|
|
|
#define RT_TxTemplateName 0x1036
|
|
|
|
#define RT_DisplayOptions 0x100a
|
|
|
|
#define RT_Summary 0x1002
|
|
|
|
#define RT_SubfileSummary 0x1003
|
|
|
|
#define RT_CyclicInformation 0x1009
|
|
|
|
#define RT_Index 0x1004
|
|
|
|
#define RT_PacketData 0x1005
|
|
|
|
|
|
|
|
#define LA_ProFileLimit (1024 * 1024 * 32)
|
|
|
|
|
|
|
|
typedef guint8 Eadr[6];
|
|
|
|
typedef guint16 TimeStamp[3]; /* 0.5 microseconds since start of trace */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These records have only 2-byte alignment for 4-byte quantities,
|
|
|
|
* so the structures aren't necessarily valid; they're kept as comments
|
|
|
|
* for reference purposes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* typedef struct {
|
|
|
|
* guint8 day;
|
|
|
|
* guint8 mon;
|
|
|
|
* gint16 year;
|
|
|
|
* } Date;
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* typedef struct {
|
|
|
|
* guint8 second;
|
|
|
|
* guint8 minute;
|
|
|
|
* guint8 hour;
|
|
|
|
* guint8 day;
|
|
|
|
* gint16 reserved;
|
|
|
|
* } Time;
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* RT_Summary:
|
|
|
|
*
|
|
|
|
* typedef struct {
|
|
|
|
* Date datcre;
|
|
|
|
* Date datclo;
|
|
|
|
* Time timeopn;
|
|
|
|
* Time timeclo;
|
|
|
|
* Eadr statadr;
|
|
|
|
* gint16 mxseqno;
|
|
|
|
* gint16 slcoff;
|
|
|
|
* gint16 mxslc;
|
|
|
|
* gint32 totpktt;
|
|
|
|
* gint32 statrg;
|
|
|
|
* gint32 stptrg;
|
|
|
|
* gint32 mxpkta[36];
|
|
|
|
* gint16 board_type;
|
|
|
|
* gint16 board_version;
|
|
|
|
* gint8 reserved[18];
|
|
|
|
* } Summary;
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define SummarySize (18+22+(4*36)+6+6+6+4+4)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* typedef struct {
|
|
|
|
* gint16 rid;
|
|
|
|
* gint16 rlen;
|
|
|
|
* Summary s;
|
|
|
|
* } LA_SummaryRecord;
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LA_SummaryRecordSize (SummarySize + 4)
|
|
|
|
|
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
|
|
|
/* LANalyzer board types (which indicate the type of network on which
|
|
|
|
the capture was done). */
|
|
|
|
#define BOARD_325 226 /* LANalyzer 325 (Ethernet) */
|
|
|
|
#define BOARD_325TR 227 /* LANalyzer 325TR (Token-ring) */
|
|
|
|
|
2002-06-27 22:46:48 +00:00
|
|
|
|
2011-07-10 22:57:59 +00:00
|
|
|
/*
|
|
|
|
* typedef struct {
|
|
|
|
* gint16 rid;
|
|
|
|
* gint16 rlen;
|
|
|
|
* gint16 seqno;
|
|
|
|
* gint32 totpktf;
|
|
|
|
* } LA_SubfileSummaryRecord;
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LA_SubfileSummaryRecordSize 10
|
|
|
|
|
|
|
|
|
|
|
|
#define LA_IndexSize 500
|
|
|
|
|
|
|
|
/*
|
|
|
|
* typedef struct {
|
|
|
|
* gint16 rid;
|
|
|
|
* gint16 rlen;
|
|
|
|
* gint16 idxsp; = LA_IndexSize
|
|
|
|
* gint16 idxct;
|
|
|
|
* gint8 idxgranu;
|
|
|
|
* gint8 idxvd;
|
|
|
|
* gint32 trcidx[LA_IndexSize + 2]; +2 undocumented but used by La 2.2
|
|
|
|
* } LA_IndexRecord;
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LA_IndexRecordSize (10 + 4 * (LA_IndexSize + 2))
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* typedef struct {
|
|
|
|
* guint16 rx_channels;
|
|
|
|
* guint16 rx_errors;
|
|
|
|
* gint16 rx_frm_len;
|
|
|
|
* gint16 rx_frm_sln;
|
|
|
|
* TimeStamp rx_time;
|
|
|
|
* guint32 pktno;
|
|
|
|
* gint16 prvlen;
|
|
|
|
* gint16 offset;
|
|
|
|
* gint16 tx_errs;
|
|
|
|
* gint16 rx_filters;
|
|
|
|
* gint8 unused[2];
|
|
|
|
* gint16 hwcolls;
|
|
|
|
* gint16 hwcollschans;
|
|
|
|
* Packetdata ....;
|
|
|
|
* } LA_PacketRecord;
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LA_PacketRecordSize 32
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
gboolean init;
|
|
|
|
struct timeval start;
|
|
|
|
guint32 pkts;
|
|
|
|
int encap;
|
|
|
|
int lastlen;
|
|
|
|
} LA_TmpInfo;
|
|
|
|
|
2003-12-29 00:25:39 +00:00
|
|
|
static const guint8 LA_HeaderRegularFake[] = {
|
2002-06-27 22:46:48 +00:00
|
|
|
0x01,0x10,0x4c,0x00,0x01,0x05,0x54,0x72,0x61,0x63,0x65,0x20,0x44,0x69,0x73,0x70,
|
|
|
|
0x6c,0x61,0x79,0x20,0x54,0x72,0x61,0x63,0x65,0x20,0x46,0x69,0x6c,0x65,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
|
|
|
|
};
|
|
|
|
|
2003-12-29 00:25:39 +00:00
|
|
|
static const guint8 LA_RxChannelNameFake[] = {
|
|
|
|
0x06,0x10,0x80,0x00,0x43,0x68,0x61,0x6e ,0x6e,0x65,0x6c,0x31,0x00,0x43,0x68,0x61,
|
2002-06-27 22:46:48 +00:00
|
|
|
0x6e,0x6e,0x65,0x6c,0x32,0x00,0x43,0x68 ,0x61,0x6e,0x6e,0x65,0x6c,0x33,0x00,0x43,
|
|
|
|
0x68,0x61,0x6e,0x6e,0x65,0x6c,0x34,0x00 ,0x43,0x68,0x61,0x6e,0x6e,0x65,0x6c,0x35,
|
|
|
|
0x00,0x43,0x68,0x61,0x6e,0x6e,0x65,0x6c ,0x36,0x00,0x43,0x68,0x61,0x6e,0x6e,0x65,
|
|
|
|
0x6c,0x37,0x00,0x43,0x68,0x61,0x6e,0x6e ,0x65,0x6c,0x38,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00
|
|
|
|
};
|
|
|
|
|
2003-12-29 00:25:39 +00:00
|
|
|
static const guint8 LA_TxChannelNameFake[] = {
|
2002-06-27 22:46:48 +00:00
|
|
|
0x0b,0x10,0x36,0x00 ,0x54,0x72,0x61,0x6e,0x73,0x31,0x00,0x00,
|
|
|
|
0x00,0x54,0x72,0x61,0x6e,0x73,0x32,0x00 ,0x00,0x00,0x54,0x72,0x61,0x6e,0x73,0x33,
|
|
|
|
0x00,0x00,0x00,0x54,0x72,0x61,0x6e,0x73 ,0x34,0x00,0x00,0x00,0x54,0x72,0x61,0x6e,
|
|
|
|
0x73,0x35,0x00,0x00,0x00,0x54,0x72,0x61 ,0x6e,0x73,0x36,0x00,0x00,0x00
|
|
|
|
};
|
|
|
|
|
2003-12-29 00:25:39 +00:00
|
|
|
static const guint8 LA_RxTemplateNameFake[] = {
|
2002-06-27 22:46:48 +00:00
|
|
|
0x35,0x10,
|
2003-12-29 00:25:39 +00:00
|
|
|
0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
2002-06-27 22:46:48 +00:00
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00
|
|
|
|
};
|
|
|
|
|
2003-12-29 00:25:39 +00:00
|
|
|
static const guint8 LA_TxTemplateNameFake[] = {
|
2002-06-27 22:46:48 +00:00
|
|
|
0x36,0x10,0x36,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00
|
|
|
|
};
|
|
|
|
|
2003-12-29 00:25:39 +00:00
|
|
|
static const guint8 LA_DisplayOptionsFake[] = {
|
2002-06-27 22:46:48 +00:00
|
|
|
0x0a,0x10,0x0a,0x01,
|
|
|
|
0x00,0x00,0x01,0x00,0x01,0x02,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00
|
|
|
|
};
|
|
|
|
|
2003-12-29 00:25:39 +00:00
|
|
|
static const guint8 LA_CyclicInformationFake[] = {
|
2002-06-27 22:46:48 +00:00
|
|
|
0x09,0x10,0x1a,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
|
|
|
|
};
|
|
|
|
|
2013-03-17 09:20:13 +00:00
|
|
|
static const guint8 z64[64] = {
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
|
|
|
|
};
|
|
|
|
|
2010-02-24 07:21:17 +00:00
|
|
|
typedef struct {
|
|
|
|
time_t start;
|
|
|
|
} lanalyzer_t;
|
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean lanalyzer_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 lanalyzer_seek_read(wtap *wth, gint64 seek_off,
|
2014-05-09 05:18:49 +00:00
|
|
|
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
|
|
|
|
static gboolean lanalyzer_dump_close(wtap_dumper *wdh, int *err);
|
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
|
|
|
|
2014-10-09 23:44:15 +00:00
|
|
|
wtap_open_return_val lanalyzer_open(wtap *wth, int *err, gchar **err_info)
|
1998-11-12 06:01:27 +00:00
|
|
|
{
|
2011-07-10 22:57:59 +00:00
|
|
|
LA_RecordHeader rec_header;
|
2012-02-26 10:20:40 +00:00
|
|
|
char header_fixed[2];
|
|
|
|
char *comment;
|
1998-11-12 06:01:27 +00:00
|
|
|
char summary[210];
|
1998-11-23 04:40:22 +00:00
|
|
|
guint16 board_type, mxslc;
|
1999-08-20 04:49:18 +00:00
|
|
|
guint16 record_type, record_length;
|
2004-01-07 04:50:21 +00:00
|
|
|
guint8 cr_day, cr_month;
|
|
|
|
guint16 cr_year;
|
1998-12-13 05:08:05 +00:00
|
|
|
struct tm tm;
|
2010-02-24 07:21:17 +00:00
|
|
|
lanalyzer_t *lanalyzer;
|
1998-11-12 06:01:27 +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(wth->fh, &rec_header, LA_RecordHeaderSize,
|
|
|
|
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;
|
1998-11-12 06:01:27 +00:00
|
|
|
}
|
2013-12-03 20:35:50 +00:00
|
|
|
record_type = pletoh16(rec_header.record_type);
|
|
|
|
record_length = pletoh16(rec_header.record_length); /* make sure to do this for while() loop */
|
1998-11-12 06:01:27 +00:00
|
|
|
|
2002-06-27 22:46:48 +00:00
|
|
|
if (record_type != RT_HeaderRegular && record_type != RT_HeaderCyclic) {
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_NOT_MINE;
|
1998-11-12 06:01:27 +00:00
|
|
|
}
|
|
|
|
|
2012-02-26 10:20:40 +00:00
|
|
|
/* Read the major and minor version numbers */
|
|
|
|
if (record_length < 2) {
|
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
|
|
|
/*
|
|
|
|
* Not enough room for the major and minor version numbers.
|
|
|
|
* Just treat that as a "not a LANalyzer file" indication.
|
|
|
|
*/
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_NOT_MINE;
|
2012-02-26 10:20:40 +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(wth->fh, &header_fixed, sizeof header_fixed,
|
|
|
|
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;
|
2012-02-26 10:20:40 +00:00
|
|
|
}
|
|
|
|
record_length -= sizeof header_fixed;
|
|
|
|
|
|
|
|
if (record_length != 0) {
|
|
|
|
/* Read the rest of the record as a comment. */
|
2012-06-02 14:13:14 +00:00
|
|
|
comment = (char *)g_malloc(record_length + 1);
|
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, comment, record_length,
|
|
|
|
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;
|
2012-02-26 10:20:40 +00:00
|
|
|
}
|
|
|
|
comment[record_length] = '\0';
|
|
|
|
wth->shb_hdr.opt_comment = comment;
|
|
|
|
}
|
|
|
|
|
1998-11-12 06:01:27 +00:00
|
|
|
/* If we made it this far, then the file is a LANAlyzer file.
|
2014-05-09 05:18:49 +00:00
|
|
|
* Let's get some info from it. Note that we get wth->snapshot_length
|
1999-08-20 04:49:18 +00:00
|
|
|
* from a record later in the file. */
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_LANALYZER;
|
2012-04-13 20:22:31 +00:00
|
|
|
lanalyzer = (lanalyzer_t *)g_malloc(sizeof(lanalyzer_t));
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->priv = (void *)lanalyzer;
|
|
|
|
wth->subtype_read = lanalyzer_read;
|
|
|
|
wth->subtype_seek_read = lanalyzer_seek_read;
|
|
|
|
wth->snapshot_length = 0;
|
2014-09-28 18:37:06 +00:00
|
|
|
wth->file_tsprec = WTAP_TSPREC_NSEC;
|
1998-11-12 06:01:27 +00:00
|
|
|
|
|
|
|
/* Read records until we find the start of packets */
|
|
|
|
while (1) {
|
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(wth->fh, &rec_header,
|
|
|
|
LA_RecordHeaderSize, err, err_info)) {
|
|
|
|
if (*err == 0) {
|
|
|
|
/*
|
|
|
|
* End of file and no packets;
|
|
|
|
* accept this file.
|
|
|
|
*/
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_MINE;
|
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
|
|
|
}
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
1998-11-12 06:01:27 +00:00
|
|
|
}
|
|
|
|
|
2013-12-03 20:35:50 +00:00
|
|
|
record_type = pletoh16(rec_header.record_type);
|
|
|
|
record_length = pletoh16(rec_header.record_length);
|
1998-11-12 06:01:27 +00:00
|
|
|
|
1999-08-20 04:49:18 +00:00
|
|
|
/*g_message("Record 0x%04X Length %d", record_type, record_length);*/
|
|
|
|
switch (record_type) {
|
1998-11-12 06:01:27 +00:00
|
|
|
/* Trace Summary Record */
|
2002-06-27 22:46:48 +00:00
|
|
|
case RT_Summary:
|
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, summary,
|
|
|
|
sizeof summary, err, err_info))
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
1998-11-23 04:40:22 +00:00
|
|
|
|
|
|
|
/* Assume that the date of the creation of the trace file
|
|
|
|
* is the same date of the trace. Lanalyzer doesn't
|
|
|
|
* store the creation date/time of the trace, but only of
|
|
|
|
* the file. Unless you traced at 11:55 PM and saved at 00:05
|
|
|
|
* AM, the assumption that trace.date == file.date is true.
|
|
|
|
*/
|
|
|
|
cr_day = summary[0];
|
|
|
|
cr_month = summary[1];
|
2013-12-03 20:35:50 +00:00
|
|
|
cr_year = pletoh16(&summary[2]);
|
1998-12-13 05:08:05 +00:00
|
|
|
/*g_message("Day %d Month %d Year %d (%04X)", cr_day, cr_month,
|
|
|
|
cr_year, cr_year);*/
|
1998-11-23 04:40:22 +00:00
|
|
|
|
1998-12-13 05:08:05 +00:00
|
|
|
/* Get capture start time. I learned how to do
|
|
|
|
* this from Guy's code in ngsniffer.c
|
|
|
|
*/
|
2004-01-07 04:50:21 +00:00
|
|
|
tm.tm_year = cr_year - 1900;
|
1998-12-13 05:08:05 +00:00
|
|
|
tm.tm_mon = cr_month - 1;
|
|
|
|
tm.tm_mday = cr_day;
|
|
|
|
tm.tm_hour = 0;
|
|
|
|
tm.tm_min = 0;
|
|
|
|
tm.tm_sec = 0;
|
|
|
|
tm.tm_isdst = -1;
|
2010-02-24 07:21:17 +00:00
|
|
|
lanalyzer->start = mktime(&tm);
|
1998-12-13 05:38:13 +00:00
|
|
|
/*g_message("Day %d Month %d Year %d", tm.tm_mday,
|
|
|
|
tm.tm_mon, tm.tm_year);*/
|
2013-12-03 20:35:50 +00:00
|
|
|
mxslc = pletoh16(&summary[30]);
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->snapshot_length = mxslc;
|
1998-11-23 04:40:22 +00:00
|
|
|
|
2013-12-03 20:35:50 +00:00
|
|
|
board_type = pletoh16(&summary[188]);
|
1998-11-12 06:01:27 +00:00
|
|
|
switch (board_type) {
|
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 BOARD_325:
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->file_encap = WTAP_ENCAP_ETHERNET;
|
1998-11-12 06:01:27 +00:00
|
|
|
break;
|
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 BOARD_325TR:
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->file_encap = WTAP_ENCAP_TOKEN_RING;
|
1998-11-12 06:01:27 +00:00
|
|
|
break;
|
|
|
|
default:
|
2004-07-08 07:32:39 +00:00
|
|
|
*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("lanalyzer: board type %u unknown",
|
|
|
|
board_type);
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
1998-11-12 06:01:27 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Trace Packet Data Record */
|
2002-06-27 22:46:48 +00:00
|
|
|
case RT_PacketData:
|
2011-07-10 21:05:19 +00:00
|
|
|
/* Go back header number of bytes so that lanalyzer_read
|
1999-08-20 04:49:18 +00:00
|
|
|
* can read this header */
|
2014-05-09 05:18:49 +00:00
|
|
|
if (file_seek(wth->fh, -LA_RecordHeaderSize, SEEK_CUR, err) == -1) {
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
2002-03-04 00:25:35 +00:00
|
|
|
}
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_MINE;
|
1998-11-12 06:01:27 +00:00
|
|
|
|
1999-08-20 04:49:18 +00:00
|
|
|
default:
|
2014-05-09 05:18:49 +00:00
|
|
|
if (file_seek(wth->fh, record_length, SEEK_CUR, err) == -1) {
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
2012-02-26 10:20:40 +00:00
|
|
|
}
|
|
|
|
break;
|
1998-11-12 06:01:27 +00:00
|
|
|
}
|
2002-06-27 22:46:48 +00:00
|
|
|
}
|
1998-11-12 06:01:27 +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 DESCRIPTOR_LEN 32
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
static gboolean lanalyzer_read_trace_record(wtap *wth, FILE_T fh,
|
2013-06-17 21:18:47 +00:00
|
|
|
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
|
1998-11-12 06:01:27 +00:00
|
|
|
{
|
1999-08-20 04:49:18 +00:00
|
|
|
char LE_record_type[2];
|
|
|
|
char LE_record_length[2];
|
|
|
|
guint16 record_type, record_length;
|
2013-05-18 00:08:43 +00:00
|
|
|
int record_data_size;
|
|
|
|
int packet_size;
|
1999-08-20 04:49:18 +00:00
|
|
|
gchar descriptor[DESCRIPTOR_LEN];
|
2013-05-18 00:08:43 +00:00
|
|
|
lanalyzer_t *lanalyzer;
|
1999-08-20 04:49:18 +00:00
|
|
|
guint16 time_low, time_med, time_high, true_size;
|
2005-08-28 22:52:05 +00:00
|
|
|
guint64 t;
|
|
|
|
time_t tsecs;
|
1999-08-20 04:49:18 +00:00
|
|
|
|
|
|
|
/* read the record type and length. */
|
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, LE_record_type, 2, err, err_info))
|
2000-09-07 05:34:23 +00:00
|
|
|
return FALSE;
|
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(fh, LE_record_length, 2, err, err_info))
|
2000-09-07 05:34:23 +00:00
|
|
|
return FALSE;
|
1998-11-12 06:01:27 +00:00
|
|
|
|
2013-12-03 20:35:50 +00:00
|
|
|
record_type = pletoh16(LE_record_type);
|
|
|
|
record_length = pletoh16(LE_record_length);
|
1998-11-12 06:01:27 +00:00
|
|
|
|
1999-08-20 04:49:18 +00:00
|
|
|
/* Only Trace Packet Data Records should occur now that we're in
|
|
|
|
* the middle of reading packets. If any other record type exists
|
|
|
|
* after a Trace Packet Data Record, mark it as an error. */
|
2002-06-27 22:46:48 +00:00
|
|
|
if (record_type != RT_PacketData) {
|
2011-12-13 09:53:50 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
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("lanalyzer: record type %u seen after trace summary record",
|
|
|
|
record_type);
|
2000-09-07 05:34:23 +00:00
|
|
|
return FALSE;
|
1998-11-12 06:01:27 +00:00
|
|
|
}
|
|
|
|
|
2013-05-18 00:08:43 +00:00
|
|
|
if (record_length < DESCRIPTOR_LEN) {
|
|
|
|
/*
|
|
|
|
* Uh-oh, the record isn't big enough to even have a
|
|
|
|
* descriptor.
|
|
|
|
*/
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup_printf("lanalyzer: file has a %u-byte record, too small to have even a packet descriptor",
|
|
|
|
record_length);
|
2000-09-07 05:34:23 +00:00
|
|
|
return FALSE;
|
1998-11-12 06:01:27 +00:00
|
|
|
}
|
2013-05-18 00:08:43 +00:00
|
|
|
record_data_size = record_length - DESCRIPTOR_LEN;
|
1998-11-12 06:01:27 +00:00
|
|
|
|
2013-05-18 00:08:43 +00:00
|
|
|
/* Read the descriptor data */
|
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(fh, descriptor, DESCRIPTOR_LEN, err, err_info))
|
2000-09-07 05:34:23 +00:00
|
|
|
return FALSE;
|
1998-11-12 06:01:27 +00:00
|
|
|
|
2013-12-03 20:35:50 +00:00
|
|
|
true_size = pletoh16(&descriptor[4]);
|
|
|
|
packet_size = pletoh16(&descriptor[6]);
|
1998-11-23 04:40:22 +00:00
|
|
|
|
2003-06-30 00:41:33 +00:00
|
|
|
/*
|
|
|
|
* OK, is the frame data size greater than than what's left of the
|
|
|
|
* record?
|
|
|
|
*/
|
2013-05-18 00:08:43 +00:00
|
|
|
if (packet_size > record_data_size) {
|
2003-06-30 00:41:33 +00:00
|
|
|
/*
|
|
|
|
* Yes - treat this as an error.
|
|
|
|
*/
|
2011-12-13 09:53:50 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
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("lanalyzer: Record length is less than packet size");
|
2003-06-30 00:41:33 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-05-24 18:28:30 +00:00
|
|
|
phdr->rec_type = REC_TYPE_PACKET;
|
2013-05-18 00:08:43 +00:00
|
|
|
phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
|
2012-02-25 23:24:34 +00:00
|
|
|
|
2013-12-03 20:35:50 +00:00
|
|
|
time_low = pletoh16(&descriptor[8]);
|
|
|
|
time_med = pletoh16(&descriptor[10]);
|
|
|
|
time_high = pletoh16(&descriptor[12]);
|
2005-08-28 22:52:05 +00:00
|
|
|
t = (((guint64)time_low) << 0) + (((guint64)time_med) << 16) +
|
|
|
|
(((guint64)time_high) << 32);
|
|
|
|
tsecs = (time_t) (t/2000000);
|
2014-05-09 05:18:49 +00:00
|
|
|
lanalyzer = (lanalyzer_t *)wth->priv;
|
2013-05-18 00:08:43 +00:00
|
|
|
phdr->ts.secs = tsecs + lanalyzer->start;
|
|
|
|
phdr->ts.nsecs = ((guint32) (t - tsecs*2000000)) * 500;
|
1998-11-23 04:40:22 +00:00
|
|
|
|
2003-06-30 00:41:33 +00:00
|
|
|
if (true_size - 4 >= packet_size) {
|
|
|
|
/*
|
|
|
|
* It appears that the "true size" includes the FCS;
|
|
|
|
* make it reflect the non-FCS size (the "packet size"
|
|
|
|
* appears never to include the FCS, even if no slicing
|
|
|
|
* is done).
|
|
|
|
*/
|
|
|
|
true_size -= 4;
|
|
|
|
}
|
2013-05-18 00:08:43 +00:00
|
|
|
phdr->len = true_size;
|
|
|
|
phdr->caplen = packet_size;
|
1998-11-12 06:01:27 +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-18 00:08:43 +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, packet_size, err, err_info);
|
2003-10-01 07:11:49 +00:00
|
|
|
}
|
|
|
|
|
2013-05-18 00:08:43 +00:00
|
|
|
/* Read the next packet */
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean lanalyzer_read(wtap *wth, int *err, gchar **err_info,
|
2013-05-18 00:08:43 +00:00
|
|
|
gint64 *data_offset)
|
|
|
|
{
|
2014-05-09 05:18:49 +00:00
|
|
|
*data_offset = file_tell(wth->fh);
|
2013-05-18 00:08:43 +00:00
|
|
|
|
2013-06-17 21:18:47 +00:00
|
|
|
/* Read the record */
|
2014-05-23 10:50:02 +00:00
|
|
|
return lanalyzer_read_trace_record(wth, wth->fh, &wth->phdr,
|
|
|
|
wth->frame_buffer, err, err_info);
|
2013-05-18 00:08:43 +00:00
|
|
|
}
|
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean lanalyzer_seek_read(wtap *wth, gint64 seek_off,
|
2014-05-09 05:18:49 +00:00
|
|
|
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
|
2003-10-01 07:11:49 +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 record */
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!lanalyzer_read_trace_record(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;
|
1998-11-12 06:01:27 +00:00
|
|
|
}
|
2000-03-22 07:06:59 +00:00
|
|
|
|
2002-06-27 22:46:48 +00:00
|
|
|
/*---------------------------------------------------
|
2010-06-06 22:19:30 +00:00
|
|
|
* Returns TRUE on success, FALSE on error
|
|
|
|
* Write "cnt" bytes of zero with error control
|
2002-06-27 22:46:48 +00:00
|
|
|
*---------------------------------------------------*/
|
2014-05-09 05:18:49 +00:00
|
|
|
static gboolean s0write(wtap_dumper *wdh, size_t cnt, int *err)
|
2002-06-27 22:46:48 +00:00
|
|
|
{
|
|
|
|
size_t snack;
|
|
|
|
|
|
|
|
while (cnt) {
|
2010-06-06 22:19:30 +00:00
|
|
|
snack = cnt > 64 ? 64 : cnt;
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, z64, snack, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
|
|
|
cnt -= snack;
|
|
|
|
}
|
|
|
|
return TRUE; /* ok */
|
2002-06-27 22:46:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------
|
2010-06-06 22:19:30 +00:00
|
|
|
* Returns TRUE on success, FALSE on error
|
|
|
|
* Write an 8-bit value with error control
|
2002-06-27 22:46:48 +00:00
|
|
|
*---------------------------------------------------*/
|
2014-05-09 05:18:49 +00:00
|
|
|
static gboolean s8write(wtap_dumper *wdh, const guint8 s8, int *err)
|
2002-06-27 22:46:48 +00:00
|
|
|
{
|
2014-05-09 05:18:49 +00:00
|
|
|
return wtap_dump_file_write(wdh, &s8, 1, err);
|
2002-06-27 22:46:48 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------
|
2010-06-06 22:19:30 +00:00
|
|
|
* Returns TRUE on success, FALSE on error
|
|
|
|
* Write a 16-bit value with error control
|
2002-06-27 22:46:48 +00:00
|
|
|
*---------------------------------------------------*/
|
2014-05-09 05:18:49 +00:00
|
|
|
static gboolean s16write(wtap_dumper *wdh, const guint16 s16, int *err)
|
2002-06-27 22:46:48 +00:00
|
|
|
{
|
2014-05-09 05:18:49 +00:00
|
|
|
return wtap_dump_file_write(wdh, &s16, 2, err);
|
2002-06-27 22:46:48 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------
|
2010-06-06 22:19:30 +00:00
|
|
|
* Returns TRUE on success, FALSE on error
|
|
|
|
* Write a 32-bit value with error control
|
2002-06-27 22:46:48 +00:00
|
|
|
*---------------------------------------------------*/
|
2014-05-09 05:18:49 +00:00
|
|
|
static gboolean s32write(wtap_dumper *wdh, const guint32 s32, int *err)
|
2002-06-27 22:46:48 +00:00
|
|
|
{
|
2014-05-09 05:18:49 +00:00
|
|
|
return wtap_dump_file_write(wdh, &s32, 4, err);
|
2002-06-27 22:46:48 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------
|
|
|
|
*
|
|
|
|
* calculates C.c = A.a - B.b
|
|
|
|
*---------------------------------------------------*/
|
|
|
|
static void my_timersub(const struct timeval *a,
|
|
|
|
const struct timeval *b,
|
|
|
|
struct timeval *c)
|
|
|
|
{
|
2013-08-10 21:27:17 +00:00
|
|
|
gint32 usec = (gint32)a->tv_usec;
|
2002-06-27 22:46:48 +00:00
|
|
|
|
|
|
|
c->tv_sec = a->tv_sec - b->tv_sec;
|
|
|
|
if (b->tv_usec > usec) {
|
|
|
|
c->tv_sec--;
|
|
|
|
usec += 1000000;
|
|
|
|
}
|
|
|
|
c->tv_usec = usec - b->tv_usec;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------
|
|
|
|
* 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 lanalyzer_dump(wtap_dumper *wdh,
|
2002-06-27 22:46:48 +00:00
|
|
|
const struct wtap_pkthdr *phdr,
|
2011-09-01 09:43:10 +00:00
|
|
|
const guint8 *pd, int *err)
|
2002-06-27 22:46:48 +00:00
|
|
|
{
|
|
|
|
double x;
|
|
|
|
int i;
|
|
|
|
int len;
|
2014-01-22 00:26:36 +00:00
|
|
|
struct timeval tv;
|
2002-06-27 22:46:48 +00:00
|
|
|
|
2010-02-26 07:59:54 +00:00
|
|
|
LA_TmpInfo *itmp = (LA_TmpInfo*)(wdh->priv);
|
2002-06-27 22:46:48 +00:00
|
|
|
struct timeval td;
|
|
|
|
int thisSize = phdr->caplen + LA_PacketRecordSize + LA_RecordHeaderSize;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2002-06-27 22:46:48 +00:00
|
|
|
if (wdh->bytes_dumped + thisSize > LA_ProFileLimit) {
|
|
|
|
/* printf(" LA_ProFileLimit reached\n"); */
|
|
|
|
*err = EFBIG;
|
|
|
|
return FALSE; /* and don't forget the header */
|
|
|
|
}
|
|
|
|
|
|
|
|
len = phdr->caplen + (phdr->caplen ? LA_PacketRecordSize : 0);
|
|
|
|
|
2014-01-22 00:26:36 +00:00
|
|
|
/* len goes into a 16-bit field, so there's a hard limit of 65535. */
|
|
|
|
if (len > 65535) {
|
|
|
|
*err = WTAP_ERR_PACKET_TOO_LARGE;
|
|
|
|
return FALSE;
|
2014-05-24 18:28:30 +00:00
|
|
|
}
|
2014-01-22 00:26:36 +00:00
|
|
|
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s16write(wdh, GUINT16_TO_LE(0x1005), err))
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s16write(wdh, GUINT16_TO_LE(len), err))
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2010-06-06 22:19:30 +00:00
|
|
|
tv.tv_sec = (long int) phdr->ts.secs;
|
|
|
|
tv.tv_usec = phdr->ts.nsecs / 1000;
|
2002-06-27 22:46:48 +00:00
|
|
|
|
|
|
|
if (!itmp->init) {
|
|
|
|
/* collect some information for the
|
|
|
|
* finally written header
|
|
|
|
*/
|
2005-08-24 21:31:56 +00:00
|
|
|
/* XXX - this conversion could probably improved, if the start uses ns */
|
|
|
|
itmp->start = tv;
|
2002-06-27 22:46:48 +00:00
|
|
|
itmp->pkts = 0;
|
|
|
|
itmp->init = TRUE;
|
|
|
|
itmp->encap = wdh->encap;
|
|
|
|
itmp->lastlen = 0;
|
|
|
|
}
|
|
|
|
|
2005-08-24 21:31:56 +00:00
|
|
|
my_timersub(&(tv),&(itmp->start),&td);
|
2002-06-27 22:46:48 +00:00
|
|
|
|
|
|
|
x = (double) td.tv_usec;
|
|
|
|
x += (double) td.tv_sec * 1000000;
|
|
|
|
x *= 2;
|
|
|
|
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s16write(wdh, GUINT16_TO_LE(0x0001), err)) /* pr.rx_channels */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s16write(wdh, GUINT16_TO_LE(0x0008), err)) /* pr.rx_errors */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s16write(wdh, GUINT16_TO_LE(phdr->len + 4), err)) /* pr.rx_frm_len */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s16write(wdh, GUINT16_TO_LE(phdr->caplen), err)) /* pr.rx_frm_sln */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s16write(wdh, GUINT16_TO_LE((guint16) x), err)) /* pr.rx_time[i] */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
|
|
|
x /= 0xffff;
|
2010-06-06 22:19:30 +00:00
|
|
|
}
|
2002-06-27 22:46:48 +00:00
|
|
|
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s32write(wdh, GUINT32_TO_LE(++itmp->pkts), err)) /* pr.pktno */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s16write(wdh, GUINT16_TO_LE(itmp->lastlen), err)) /* pr.prlen */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
|
|
|
itmp->lastlen = len;
|
|
|
|
|
2010-06-06 22:19:30 +00:00
|
|
|
if (!s0write(wdh, 12, err))
|
|
|
|
return FALSE;
|
2002-06-27 22:46:48 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2002-06-27 22:46:48 +00:00
|
|
|
|
|
|
|
wdh->bytes_dumped += thisSize;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------
|
|
|
|
* Returns 0 if we could write the specified encapsulation type,
|
|
|
|
* an error indication otherwise.
|
|
|
|
*---------------------------------------------------*/
|
|
|
|
int lanalyzer_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;
|
|
|
|
|
|
|
|
if ( encap != WTAP_ENCAP_ETHERNET
|
|
|
|
&& encap != WTAP_ENCAP_TOKEN_RING )
|
|
|
|
return WTAP_ERR_UNSUPPORTED_ENCAP;
|
|
|
|
/*
|
|
|
|
* printf("lanalyzer_dump_can_write_encap(%d)\n",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 lanalyzer_dump_open(wtap_dumper *wdh, int *err)
|
2002-06-27 22:46:48 +00:00
|
|
|
{
|
|
|
|
int jump;
|
|
|
|
void *tmp;
|
|
|
|
|
|
|
|
tmp = g_malloc(sizeof(LA_TmpInfo));
|
|
|
|
if (!tmp) {
|
2014-05-09 05:18:49 +00:00
|
|
|
*err = errno;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-06-27 22:46:48 +00:00
|
|
|
|
|
|
|
((LA_TmpInfo*)tmp)->init = FALSE;
|
2010-02-26 07:59:54 +00:00
|
|
|
wdh->priv = tmp;
|
|
|
|
wdh->subtype_write = lanalyzer_dump;
|
|
|
|
wdh->subtype_close = lanalyzer_dump_close;
|
2002-06-27 22:46:48 +00:00
|
|
|
|
|
|
|
/* Some of the fields in the file header aren't known yet so
|
|
|
|
just skip over it for now. It will be created after all
|
|
|
|
of the packets have been written. */
|
|
|
|
|
|
|
|
jump = sizeof (LA_HeaderRegularFake)
|
|
|
|
+ sizeof (LA_RxChannelNameFake)
|
|
|
|
+ sizeof (LA_TxChannelNameFake)
|
|
|
|
+ sizeof (LA_RxTemplateNameFake)
|
|
|
|
+ sizeof (LA_TxTemplateNameFake)
|
|
|
|
+ sizeof (LA_DisplayOptionsFake)
|
|
|
|
+ LA_SummaryRecordSize
|
|
|
|
+ LA_SubfileSummaryRecordSize
|
|
|
|
+ sizeof (LA_CyclicInformationFake)
|
|
|
|
+ LA_IndexRecordSize;
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if (wtap_dump_file_seek(wdh, jump, SEEK_SET, err) == -1)
|
|
|
|
return FALSE;
|
2013-03-17 09:20:13 +00:00
|
|
|
|
2002-06-27 22:46:48 +00:00
|
|
|
wdh->bytes_dumped = jump;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------
|
|
|
|
*
|
|
|
|
*---------------------------------------------------*/
|
2014-05-09 05:18:49 +00:00
|
|
|
static gboolean lanalyzer_dump_header(wtap_dumper *wdh, int *err)
|
2002-06-27 22:46:48 +00:00
|
|
|
{
|
2010-02-26 07:59:54 +00:00
|
|
|
LA_TmpInfo *itmp = (LA_TmpInfo*)(wdh->priv);
|
2002-06-27 22:46:48 +00:00
|
|
|
guint16 board_type = itmp->encap == WTAP_ENCAP_TOKEN_RING
|
|
|
|
? BOARD_325TR /* LANalyzer Board Type */
|
|
|
|
: BOARD_325; /* LANalyzer Board Type */
|
2011-02-25 00:40:22 +00:00
|
|
|
time_t secs;
|
|
|
|
struct tm *fT;
|
|
|
|
|
|
|
|
/* The secs variable is needed to work around 32/64-bit time_t issues.
|
|
|
|
itmp->start is a timeval struct, which declares its tv_sec field
|
|
|
|
(itmp->start.tv_sec) as a long (typically 32 bits). time_t can be 32
|
|
|
|
or 64 bits, depending on the platform. Invoking as follows could
|
|
|
|
pass a pointer to a 32-bit long where a pointer to a 64-bit time_t
|
|
|
|
is expected: localtime((time_t*) &(itmp->start.tv_sec)) */
|
|
|
|
secs = itmp->start.tv_sec;
|
|
|
|
fT = localtime(&secs);
|
|
|
|
if (fT == NULL)
|
|
|
|
return FALSE;
|
2002-06-27 22:46:48 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if (wtap_dump_file_seek(wdh, 0, SEEK_SET, err) == -1)
|
|
|
|
return FALSE;
|
2002-06-27 22:46:48 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &LA_HeaderRegularFake,
|
2010-06-06 22:19:30 +00:00
|
|
|
sizeof LA_HeaderRegularFake, err))
|
2014-05-09 05:18:49 +00:00
|
|
|
return FALSE;
|
|
|
|
if (!wtap_dump_file_write(wdh, &LA_RxChannelNameFake,
|
2010-06-06 22:19:30 +00:00
|
|
|
sizeof LA_RxChannelNameFake, err))
|
2014-05-09 05:18:49 +00:00
|
|
|
return FALSE;
|
|
|
|
if (!wtap_dump_file_write(wdh, &LA_TxChannelNameFake,
|
2010-06-06 22:19:30 +00:00
|
|
|
sizeof LA_TxChannelNameFake, err))
|
2014-05-09 05:18:49 +00:00
|
|
|
return FALSE;
|
|
|
|
if (!wtap_dump_file_write(wdh, &LA_RxTemplateNameFake,
|
2010-06-06 22:19:30 +00:00
|
|
|
sizeof LA_RxTemplateNameFake, err))
|
2014-05-09 05:18:49 +00:00
|
|
|
return FALSE;
|
|
|
|
if (!wtap_dump_file_write(wdh, &LA_TxTemplateNameFake,
|
2010-06-06 22:19:30 +00:00
|
|
|
sizeof LA_TxTemplateNameFake, err))
|
2014-05-09 05:18:49 +00:00
|
|
|
return FALSE;
|
|
|
|
if (!wtap_dump_file_write(wdh, &LA_DisplayOptionsFake,
|
2010-06-06 22:19:30 +00:00
|
|
|
sizeof LA_DisplayOptionsFake, err))
|
2014-05-09 05:18:49 +00:00
|
|
|
return FALSE;
|
2002-06-27 22:46:48 +00:00
|
|
|
/*-----------------------------------------------------------------*/
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s16write(wdh, GUINT16_TO_LE(RT_Summary), err)) /* rid */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s16write(wdh, GUINT16_TO_LE(SummarySize), err)) /* rlen */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2010-06-06 22:19:30 +00:00
|
|
|
if (!s8write(wdh, (guint8) fT->tm_mday, err)) /* s.datcre.day */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2010-06-06 22:19:30 +00:00
|
|
|
if (!s8write(wdh, (guint8) (fT->tm_mon+1), err)) /* s.datcre.mon */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s16write(wdh, GUINT16_TO_LE(fT->tm_year + 1900), err)) /* s.datcre.year */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2010-06-06 22:19:30 +00:00
|
|
|
if (!s8write(wdh, (guint8) fT->tm_mday, err)) /* s.datclo.day */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2010-06-06 22:19:30 +00:00
|
|
|
if (!s8write(wdh, (guint8) (fT->tm_mon+1), err)) /* s.datclo.mon */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s16write(wdh, GUINT16_TO_LE(fT->tm_year + 1900), err)) /* s.datclo.year */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2010-06-06 22:19:30 +00:00
|
|
|
if (!s8write(wdh, (guint8) fT->tm_sec, err)) /* s.timeopn.second */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2010-06-06 22:19:30 +00:00
|
|
|
if (!s8write(wdh, (guint8) fT->tm_min, err)) /* s.timeopn.minute */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2010-06-06 22:19:30 +00:00
|
|
|
if (!s8write(wdh, (guint8) fT->tm_hour, err)) /* s.timeopn.hour */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2010-06-06 22:19:30 +00:00
|
|
|
if (!s8write(wdh, (guint8) fT->tm_mday, err)) /* s.timeopn.mday */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2010-06-06 22:19:30 +00:00
|
|
|
if (!s0write(wdh, 2, err))
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2010-06-06 22:19:30 +00:00
|
|
|
if (!s8write(wdh, (guint8) fT->tm_sec, err)) /* s.timeclo.second */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2010-06-06 22:19:30 +00:00
|
|
|
if (!s8write(wdh, (guint8) fT->tm_min, err)) /* s.timeclo.minute */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2010-06-06 22:19:30 +00:00
|
|
|
if (!s8write(wdh, (guint8) fT->tm_hour, err)) /* s.timeclo.hour */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2010-06-06 22:19:30 +00:00
|
|
|
if (!s8write(wdh, (guint8) fT->tm_mday, err)) /* s.timeclo.mday */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2010-06-06 22:19:30 +00:00
|
|
|
if (!s0write(wdh, 2, err))
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2010-06-06 22:19:30 +00:00
|
|
|
if (!s0write(wdh, 6, err)) /* EAddr == 0 */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s16write(wdh, GUINT16_TO_LE(1), err)) /* s.mxseqno */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s16write(wdh, GUINT16_TO_LE(0), err)) /* s.slcoffo */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s16write(wdh, GUINT16_TO_LE(1514), err)) /* s.mxslc */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s32write(wdh, GUINT32_TO_LE(itmp->pkts), err)) /* s.totpktt */
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
|
|
|
/*
|
|
|
|
* statrg == 0; ? -1
|
|
|
|
* stptrg == 0; ? -1
|
|
|
|
* s.mxpkta[0]=0
|
|
|
|
*/
|
|
|
|
if (!s0write(wdh, 12, err))
|
|
|
|
return FALSE;
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s32write(wdh, GUINT32_TO_LE(itmp->pkts), err)) /* sr.s.mxpkta[1] */
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
|
|
|
if (!s0write(wdh, 34*4, err)) /* s.mxpkta[2-33]=0 */
|
|
|
|
return FALSE;
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s16write(wdh, GUINT16_TO_LE(board_type), err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
|
|
|
if (!s0write(wdh, 20, err)) /* board_version == 0 */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
|
|
|
/*-----------------------------------------------------------------*/
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s16write(wdh, GUINT16_TO_LE(RT_SubfileSummary), err)) /* ssr.rid */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s16write(wdh, GUINT16_TO_LE(LA_SubfileSummaryRecordSize-4), err)) /* ssr.rlen */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s16write(wdh, GUINT16_TO_LE(1), err)) /* ssr.seqno */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s32write(wdh, GUINT32_TO_LE(itmp->pkts), err)) /* ssr.totpkts */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
|
|
|
/*-----------------------------------------------------------------*/
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &LA_CyclicInformationFake,
|
2010-06-06 22:19:30 +00:00
|
|
|
sizeof LA_CyclicInformationFake, err))
|
|
|
|
return FALSE;
|
2002-06-27 22:46:48 +00:00
|
|
|
/*-----------------------------------------------------------------*/
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s16write(wdh, GUINT16_TO_LE(RT_Index), err)) /* rid */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s16write(wdh, GUINT16_TO_LE(LA_IndexRecordSize -4), err)) /* rlen */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2013-11-29 18:44:00 +00:00
|
|
|
if (!s16write(wdh, GUINT16_TO_LE(LA_IndexSize), err)) /* idxsp */
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
2010-06-06 22:19:30 +00:00
|
|
|
if (!s0write(wdh, LA_IndexRecordSize - 6, err))
|
2002-06-27 22:46:48 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------
|
|
|
|
* Finish writing to a dump file.
|
|
|
|
* Returns TRUE on success, FALSE on failure.
|
|
|
|
*---------------------------------------------------*/
|
2014-05-09 05:18:49 +00:00
|
|
|
static gboolean lanalyzer_dump_close(wtap_dumper *wdh, int *err)
|
2002-06-27 22:46:48 +00:00
|
|
|
{
|
2003-07-29 20:30:00 +00:00
|
|
|
lanalyzer_dump_header(wdh,err);
|
2002-06-27 22:46:48 +00:00
|
|
|
return *err ? FALSE : TRUE;
|
|
|
|
}
|