2005-06-10 16:01:16 +00:00
|
|
|
/*
|
|
|
|
* k12.c
|
|
|
|
*
|
|
|
|
* routines for importing tektronix k12xx *.rf5 files
|
|
|
|
*
|
2008-08-05 21:03:46 +00:00
|
|
|
* Copyright (c) 2005, Luis E. Garia Ontanon <luis@ontanon.org>
|
2005-06-10 16:01:16 +00:00
|
|
|
*
|
|
|
|
* Wiretap Library
|
|
|
|
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2005-06-10 16:01:16 +00:00
|
|
|
*/
|
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2008-09-03 19:14:52 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
#include "wtap-int.h"
|
|
|
|
#include "file_wrappers.h"
|
|
|
|
#include "k12.h"
|
2005-10-13 18:37:42 +00:00
|
|
|
|
2008-09-03 19:14:52 +00:00
|
|
|
#include <wsutil/str_util.h>
|
|
|
|
|
2011-02-10 18:27:39 +00:00
|
|
|
/*
|
|
|
|
* See
|
|
|
|
*
|
2013-11-19 22:22:16 +00:00
|
|
|
* http://www.tek.com/manual/record-file-api-programmer-manual
|
2011-02-10 18:27:39 +00:00
|
|
|
*
|
|
|
|
* for some information about the file format. You may have to fill in
|
2013-11-19 22:22:16 +00:00
|
|
|
* a form to download the document ("Record File API Programmer Manual").
|
2011-02-10 18:27:39 +00:00
|
|
|
*
|
|
|
|
* Unfortunately, it describes an API that delivers records from an rf5
|
|
|
|
* file, not the raw format of an rf5 file, so, while it gives the formats
|
|
|
|
* of the records with various types, it does not indicate how those records
|
|
|
|
* are stored in the file.
|
|
|
|
*/
|
|
|
|
|
2009-03-31 22:51:59 +00:00
|
|
|
/* #define DEBUG_K12 */
|
2005-10-13 18:37:42 +00:00
|
|
|
#ifdef DEBUG_K12
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
2009-03-31 22:51:59 +00:00
|
|
|
#include <wsutil/file_util.h>
|
2007-03-17 14:56:04 +00:00
|
|
|
|
2005-10-24 21:20:03 +00:00
|
|
|
FILE* dbg_out = NULL;
|
|
|
|
char* env_file = NULL;
|
2005-10-13 18:37:42 +00:00
|
|
|
|
2012-10-10 19:33:49 +00:00
|
|
|
static unsigned int debug_level = 0;
|
2005-10-24 21:20:03 +00:00
|
|
|
|
2013-11-19 20:12:51 +00:00
|
|
|
void k12_fprintf(const char* fmt, ...) {
|
2005-10-13 18:37:42 +00:00
|
|
|
va_list ap;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2005-10-13 18:37:42 +00:00
|
|
|
va_start(ap,fmt);
|
|
|
|
vfprintf(dbg_out, fmt, ap);
|
2007-10-16 15:43:18 +00:00
|
|
|
va_end(ap);
|
2005-10-13 18:37:42 +00:00
|
|
|
}
|
|
|
|
|
2007-03-17 14:56:04 +00:00
|
|
|
#define CAT(a,b) a##b
|
|
|
|
#define K12_DBG(level,args) do { if (level <= debug_level) { \
|
2015-01-02 00:45:22 +00:00
|
|
|
fprintf(dbg_out,"%s:%d: ",CAT(__FI,LE__),CAT(__LI,NE__)); \
|
|
|
|
k12_fprintf args ; \
|
|
|
|
fprintf(dbg_out,"\n"); \
|
2007-03-17 14:56:04 +00:00
|
|
|
} } while(0)
|
2005-10-24 21:20:03 +00:00
|
|
|
|
2013-11-19 22:22:16 +00:00
|
|
|
void k12_hex_ascii_dump(guint level, gint64 offset, const char* label, const unsigned char* b, unsigned int len) {
|
2005-10-24 21:20:03 +00:00
|
|
|
static const char* c2t[] = {
|
2007-10-16 15:43:18 +00:00
|
|
|
"00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f",
|
|
|
|
"10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f",
|
|
|
|
"20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f",
|
|
|
|
"30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f",
|
|
|
|
"40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f",
|
|
|
|
"50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f",
|
|
|
|
"60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f",
|
|
|
|
"70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f",
|
|
|
|
"80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f",
|
|
|
|
"90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f",
|
|
|
|
"a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af",
|
|
|
|
"b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf",
|
|
|
|
"c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf",
|
|
|
|
"d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df",
|
|
|
|
"e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef",
|
2005-10-24 21:20:03 +00:00
|
|
|
"f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"
|
|
|
|
};
|
2013-11-19 22:22:16 +00:00
|
|
|
unsigned int i, j;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-17 14:56:04 +00:00
|
|
|
if (debug_level < level) return;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2013-11-19 22:22:16 +00:00
|
|
|
fprintf(dbg_out,"%s(%.8" G_GINT64_MODIFIER "x,%.4x):\n",label,offset,len);
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2013-11-19 22:22:16 +00:00
|
|
|
for (i=0 ; i<len ; i += 16) {
|
|
|
|
for (j=0; j<16; j++) {
|
|
|
|
if ((j%4)==0)
|
|
|
|
fprintf(dbg_out," ");
|
|
|
|
if ((i+j)<len)
|
|
|
|
fprintf(dbg_out, "%s", c2t[b[i+j]]);
|
|
|
|
else
|
|
|
|
fprintf(dbg_out, " ");
|
|
|
|
}
|
|
|
|
fprintf(dbg_out, " ");
|
|
|
|
for (j=0; j<16; j++) {
|
|
|
|
if ((i+j)<len)
|
2013-12-21 15:12:11 +00:00
|
|
|
fprintf(dbg_out, "%c", g_ascii_isprint(b[i+j]) ? b[i+j] : '.');
|
2013-11-19 22:22:16 +00:00
|
|
|
}
|
|
|
|
fprintf(dbg_out,"\n");
|
2005-10-24 21:20:03 +00:00
|
|
|
}
|
|
|
|
}
|
2007-03-17 14:56:04 +00:00
|
|
|
|
2013-11-19 22:22:16 +00:00
|
|
|
#define K12_HEX_ASCII_DUMP(x,a,b,c,d) k12_hex_ascii_dump(x,a,b,c,d)
|
2005-10-13 18:37:42 +00:00
|
|
|
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
void k12_ascii_dump(guint level, guint8 *buf, guint32 len, guint32 buf_offset) {
|
|
|
|
guint32 i;
|
|
|
|
|
|
|
|
if (debug_level < level) return;
|
|
|
|
|
|
|
|
for (i = buf_offset; i < len; i++) {
|
2014-05-13 12:44:47 +00:00
|
|
|
if (g_ascii_isprint(buf[i]) || buf[i] == '\n' || buf[i] == '\t')
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
putc(buf[i], dbg_out);
|
|
|
|
else if (buf[i] == '\0')
|
|
|
|
fprintf(dbg_out, "(NUL)\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define K12_ASCII_DUMP(x,a,b,c) k12_ascii_dump(x,a,b,c)
|
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
#else
|
2007-03-17 14:56:04 +00:00
|
|
|
#define K12_DBG(level,args) (void)0
|
2013-11-19 22:22:16 +00:00
|
|
|
#define K12_HEX_ASCII_DUMP(x,a,b,c,d)
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
#define K12_ASCII_DUMP(x,a,b,c)
|
2005-06-10 16:01:16 +00:00
|
|
|
#endif
|
2007-03-10 02:04:57 +00:00
|
|
|
|
|
|
|
|
2005-06-10 16:01:16 +00:00
|
|
|
|
2005-06-13 19:45:21 +00:00
|
|
|
/*
|
2014-10-11 20:10:14 +00:00
|
|
|
* A 32-bit .rf5 file begins with a 512-byte file header, containing:
|
2014-10-05 05:18:27 +00:00
|
|
|
*
|
2014-10-11 20:10:14 +00:00
|
|
|
* a 32-bit big-endian file header length, in bytes - always 512 in
|
|
|
|
* the files we've seen;
|
2014-10-05 05:18:27 +00:00
|
|
|
*
|
|
|
|
* 4 unknown bytes, always 0x12 0x05 0x00 0x10;
|
|
|
|
*
|
|
|
|
* a 32-bit big-endian file length, giving the total length of the file,
|
|
|
|
* in bytes;
|
|
|
|
*
|
2014-10-11 20:10:14 +00:00
|
|
|
* a 32-bit big-endian number giving the "page size" of the file, in
|
|
|
|
* bytes, which is normally 8192;
|
2014-10-05 05:18:27 +00:00
|
|
|
*
|
2014-10-11 20:10:14 +00:00
|
|
|
* 20 unknown bytes;
|
|
|
|
*
|
|
|
|
* a 32-bit count of the number of records in the file;
|
|
|
|
*
|
|
|
|
* 4 unknown bytes;
|
|
|
|
*
|
|
|
|
* a 32-bit count of the number of records in the file;
|
|
|
|
*
|
|
|
|
* 464 unknown bytes;
|
2014-10-05 05:18:27 +00:00
|
|
|
*
|
|
|
|
* followed by a sequence of records containing:
|
|
|
|
*
|
|
|
|
* a 32-bit big-endian record length;
|
|
|
|
*
|
|
|
|
* a 32-bit big-endian record type;
|
|
|
|
*
|
|
|
|
* a 32-bit big-endian frame length;
|
|
|
|
*
|
|
|
|
* a 32-bit big-endian source ID.
|
|
|
|
*
|
|
|
|
* Every 8192 bytes, starting immediately after the 512-byte header,
|
|
|
|
* there's a 16-byte blob; it's not part of the record data.
|
|
|
|
* There's no obvious pattern to the data; it might be junk left
|
|
|
|
* in memory as the file was being written.
|
|
|
|
*
|
|
|
|
* There's a 16-bit terminator FFFF at the end.
|
2014-10-11 20:10:14 +00:00
|
|
|
*
|
|
|
|
* Older versions of the Wireshark .rf5 writing code incorrectly wrote
|
|
|
|
* the header - they put 512 in the file length field (counting only the
|
|
|
|
* header), put a count of records into the "page size" field, and wrote
|
|
|
|
* out zeroes in the rest of the header. We detect those files by
|
|
|
|
* checking whether the rest of the header is zero.
|
2005-06-13 19:45:21 +00:00
|
|
|
*/
|
2005-06-10 16:01:16 +00:00
|
|
|
|
2014-10-05 05:18:27 +00:00
|
|
|
/*
|
|
|
|
* We use the first 8 bytes of the file header as a magic number.
|
|
|
|
*/
|
2005-06-10 16:01:16 +00:00
|
|
|
static const guint8 k12_file_magic[] = { 0x00, 0x00, 0x02, 0x00 ,0x12, 0x05, 0x00, 0x10 };
|
|
|
|
|
2014-10-05 05:18:27 +00:00
|
|
|
#define K12_FILE_HDR_LEN 512
|
2014-10-11 20:10:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Offsets in the file header.
|
|
|
|
*/
|
|
|
|
#define K12_FILE_HDR_MAGIC_NUMBER 0x00
|
|
|
|
#define K12_FILE_HDR_FILE_SIZE 0x08
|
|
|
|
#define K12_FILE_HDR_PAGE_SIZE 0x0C
|
|
|
|
#define K12_FILE_HDR_RECORD_COUNT_1 0x24
|
|
|
|
#define K12_FILE_HDR_RECORD_COUNT_2 0x2C
|
|
|
|
|
2014-10-05 05:18:27 +00:00
|
|
|
#define K12_FILE_BLOB_LEN 16
|
|
|
|
|
2010-02-26 07:59:54 +00:00
|
|
|
typedef struct {
|
2007-03-10 02:04:57 +00:00
|
|
|
guint32 file_len;
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
guint32 num_of_records; /* XXX: not sure about this */
|
2007-10-16 15:43:18 +00:00
|
|
|
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
GHashTable* src_by_id; /* k12_srcdsc_recs by input */
|
|
|
|
GHashTable* src_by_name; /* k12_srcdsc_recs by stack_name */
|
2007-02-08 17:35:03 +00:00
|
|
|
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
guint8 *seq_read_buff; /* read buffer for sequential reading */
|
|
|
|
guint seq_read_buff_len; /* length of that buffer */
|
|
|
|
guint8 *rand_read_buff; /* read buffer for random reading */
|
|
|
|
guint rand_read_buff_len; /* length of that buffer */
|
|
|
|
|
|
|
|
Buffer extra_info; /* Buffer to hold per packet extra information */
|
2010-02-26 07:59:54 +00:00
|
|
|
} k12_t;
|
2005-06-10 16:01:16 +00:00
|
|
|
|
2005-06-16 02:27:30 +00:00
|
|
|
typedef struct _k12_src_desc_t {
|
2007-03-10 02:04:57 +00:00
|
|
|
guint32 input;
|
|
|
|
guint32 input_type;
|
|
|
|
gchar* input_name;
|
|
|
|
gchar* stack_file;
|
|
|
|
k12_input_info_t input_info;
|
2005-06-16 02:27:30 +00:00
|
|
|
} k12_src_desc_t;
|
|
|
|
|
2005-06-10 16:01:16 +00:00
|
|
|
|
2011-02-10 18:27:39 +00:00
|
|
|
/*
|
|
|
|
* According to the Tektronix documentation, this value is a combination of
|
|
|
|
* a "group" code and a "type" code, with both being 2-byte values and
|
|
|
|
* with the "group" code followe by the "type" code. The "group" values
|
|
|
|
* are:
|
|
|
|
*
|
2015-01-02 00:45:22 +00:00
|
|
|
* 0x0001 - "data event"
|
|
|
|
* 0x0002 - "text or L1 event"
|
|
|
|
* 0x0007 - "configuration event"
|
2011-02-10 18:27:39 +00:00
|
|
|
*
|
|
|
|
* and the "type" values are:
|
|
|
|
*
|
|
|
|
* data events:
|
2015-01-02 00:45:22 +00:00
|
|
|
* 0x0020 - "frame" (i.e., "an actual packet")
|
|
|
|
* 0x0021 - "transparent frame"
|
|
|
|
* 0x0022 - "bit data (TRAU frame)"
|
|
|
|
* 0x0024 - "used to mark the frame which is a fragment"
|
|
|
|
* 0x0026 - "used to mark the frame which is a fragment"
|
|
|
|
* 0x0028 - "used to mark the frame which is generated by the LSA"
|
|
|
|
* 0x002A - "used to mark the frame which is generated by the LSA"
|
2011-02-10 18:27:39 +00:00
|
|
|
*
|
|
|
|
* text or L1 events:
|
2015-01-02 00:45:22 +00:00
|
|
|
* 0x0030 - "text event"
|
|
|
|
* 0x0031 - "L1 event"
|
|
|
|
* 0x0032 - "L1 event (BAI)"
|
|
|
|
* 0x0033 - "L1 event (VX)"
|
2011-02-10 18:27:39 +00:00
|
|
|
*
|
|
|
|
* configuration events:
|
2015-01-02 00:45:22 +00:00
|
|
|
* 0x0040 - Logical Data Source configuration event
|
|
|
|
* 0x0041 - Logical Link configuration event
|
2011-02-10 18:27:39 +00:00
|
|
|
*/
|
2007-03-17 17:40:21 +00:00
|
|
|
/* so far we've seen these types of records */
|
2007-03-17 14:56:04 +00:00
|
|
|
#define K12_REC_PACKET 0x00010020 /* an actual packet */
|
2013-11-20 21:00:55 +00:00
|
|
|
#define K12_REC_D0020 0x000d0020 /* an actual packet, seen in a k18 file */
|
2007-03-17 14:56:04 +00:00
|
|
|
#define K12_REC_SCENARIO 0x00070040 /* what appears as the window's title */
|
2013-11-19 22:22:16 +00:00
|
|
|
#define K12_REC_SRCDSC 0x00070041 /* port-stack mapping + more, the key of the whole thing */
|
2007-03-17 17:40:21 +00:00
|
|
|
#define K12_REC_STK_FILE 0x00070042 /* a dump of an stk file */
|
|
|
|
#define K12_REC_SRCDSC2 0x00070043 /* another port-stack mapping */
|
2007-03-17 14:56:04 +00:00
|
|
|
#define K12_REC_TEXT 0x00070044 /* a string containing something with a grammar (conditions/responses?) */
|
2007-10-16 15:43:18 +00:00
|
|
|
#define K12_REC_START 0x00020030 /* a string containing human readable start time */
|
2007-03-17 14:56:04 +00:00
|
|
|
#define K12_REC_STOP 0x00020031 /* a string containing human readable stop time */
|
2005-06-10 16:01:16 +00:00
|
|
|
|
2011-02-10 18:27:39 +00:00
|
|
|
/*
|
|
|
|
* According to the Tektronix documentation, packets, i.e. "data events",
|
|
|
|
* have several different group/type values, which differ in the last
|
|
|
|
* nibble of the type code. For now, we just mask that nibble off; the
|
|
|
|
* format of the items are different, so we might have to treat different
|
|
|
|
* data event types differently.
|
|
|
|
*/
|
|
|
|
#define K12_MASK_PACKET 0xfffffff0
|
2005-08-22 23:11:48 +00:00
|
|
|
|
2007-03-17 14:56:04 +00:00
|
|
|
/* offsets of elements in the records */
|
2007-10-16 15:43:18 +00:00
|
|
|
#define K12_RECORD_LEN 0x0 /* uint32, in bytes */
|
2007-03-17 14:56:04 +00:00
|
|
|
#define K12_RECORD_TYPE 0x4 /* uint32, see above */
|
|
|
|
#define K12_RECORD_FRAME_LEN 0x8 /* uint32, in bytes */
|
|
|
|
#define K12_RECORD_SRC_ID 0xc /* uint32 */
|
2005-08-22 23:11:48 +00:00
|
|
|
|
2007-04-02 22:17:15 +00:00
|
|
|
/*
|
|
|
|
* Some records from K15 files have a port ID of an undeclared
|
|
|
|
* interface which happens to be the only one with the first byte changed.
|
|
|
|
* It is still unknown how to recognize when this happens.
|
|
|
|
* If the lookup of the interface record fails we'll mask it
|
|
|
|
* and retry.
|
|
|
|
*/
|
|
|
|
#define K12_RECORD_SRC_ID_MASK 0x00ffffff
|
|
|
|
|
2007-03-17 14:56:04 +00:00
|
|
|
/* elements of packet records */
|
|
|
|
#define K12_PACKET_TIMESTAMP 0x18 /* int64 (8b) representing 1/2us since 01-01-1990 Z00:00:00 */
|
2005-06-10 16:23:22 +00:00
|
|
|
|
2007-03-17 14:56:04 +00:00
|
|
|
#define K12_PACKET_FRAME 0x20 /* start of the actual frame in the record */
|
2013-11-20 21:00:55 +00:00
|
|
|
#define K12_PACKET_FRAME_D0020 0x34 /* start of the actual frame in the record */
|
2005-06-10 16:01:16 +00:00
|
|
|
|
2007-10-16 15:43:18 +00:00
|
|
|
#define K12_PACKET_OFFSET_VP 0x08 /* 2 bytes, big endian */
|
|
|
|
#define K12_PACKET_OFFSET_VC 0x0a /* 2 bytes, big endian */
|
2007-03-17 14:56:04 +00:00
|
|
|
#define K12_PACKET_OFFSET_CID 0x0c /* 1 byte */
|
2005-10-24 21:20:03 +00:00
|
|
|
|
2007-03-17 14:56:04 +00:00
|
|
|
/* elements of the source description records */
|
2007-02-04 02:13:12 +00:00
|
|
|
#define K12_SRCDESC_COLOR_FOREGROUND 0x12 /* 1 byte */
|
|
|
|
#define K12_SRCDESC_COLOR_BACKGROUND 0x13 /* 1 byte */
|
|
|
|
|
2014-12-06 04:53:39 +00:00
|
|
|
#define K12_SRCDESC_PORT_TYPE 0x1a /* 1 byte */
|
|
|
|
#define K12_SRCDESC_HWPARTLEN 0x1e /* uint16, big endian */
|
|
|
|
#define K12_SRCDESC_NAMELEN 0x20 /* uint16, big endian */
|
|
|
|
#define K12_SRCDESC_STACKLEN 0x22 /* uint16, big endian */
|
2005-06-16 02:27:30 +00:00
|
|
|
|
2014-12-06 04:53:39 +00:00
|
|
|
/* Hardware part of the record */
|
|
|
|
#define K12_SRCDESC_HWPART 0x24 /* offset of the hardware part */
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
|
2014-12-06 04:53:39 +00:00
|
|
|
/* Offsets relative to the beginning of the hardware part */
|
|
|
|
#define K12_SRCDESC_HWPARTTYPE 0 /* uint32, big endian */
|
2007-02-04 02:13:12 +00:00
|
|
|
|
2014-12-06 04:53:39 +00:00
|
|
|
#define K12_SRCDESC_DS0_MASK 24 /* variable-length */
|
|
|
|
|
|
|
|
#define K12_SRCDESC_ATM_VPI 20 /* uint16, big endian */
|
|
|
|
#define K12_SRCDESC_ATM_VCI 22 /* uint16, big endian */
|
|
|
|
#define K12_SRCDESC_ATM_AAL 24 /* 1 byte */
|
2005-06-10 16:01:16 +00:00
|
|
|
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
/*
|
|
|
|
* A "stack file", as appears in a K12_REC_STK_FILE record, is a text
|
|
|
|
* file (with CR-LF line endings) with a sequence of lines, each of
|
|
|
|
* which begins with a keyword, and has white-space-separated tokens
|
|
|
|
* after that.
|
|
|
|
*
|
|
|
|
* They appear to be:
|
|
|
|
*
|
|
|
|
* STKVER, which is followed by a number (presumably a version number
|
|
|
|
* for the stack file format)
|
|
|
|
*
|
|
|
|
* STACK, which is followed by a quoted string ("ProtocolStack" in one
|
|
|
|
* file) and two numbers
|
|
|
|
*
|
|
|
|
* PATH, which is followed by a non-quoted string giving the pathname
|
|
|
|
* of the directory containing the stack file
|
|
|
|
*
|
|
|
|
* HLAYER, which is followed by a quoted string, a path for something
|
|
|
|
* (protocol module?), a keyword ("LOADED", in one file), and a
|
|
|
|
* quoted string giving a description - this is probably a protocol
|
|
|
|
* layer of some sort
|
|
|
|
*
|
|
|
|
* LAYER, which has a similar syntax to HLAYER - the first quoted
|
|
|
|
* string is a protocol name
|
|
|
|
*
|
|
|
|
* RELATION, which has a quoted string giving a protocol name,
|
|
|
|
* another quoted string giving a protocol name, and a condition
|
|
|
|
* specifier of some sort, which probably says the second protocol
|
|
|
|
* is layered atop the first protocol if the condition is true.
|
|
|
|
* The first protocol can also be "BASE", which means that the
|
|
|
|
* second protocol is the lowest-level protocol.
|
|
|
|
* The conditions are:
|
|
|
|
*
|
|
|
|
* CPLX, which may mean "complex" - it has parenthesized expressions
|
|
|
|
* including "&", presumably a boolean AND, with the individual
|
|
|
|
* tests being L:expr, where L is a letter such as "L", "D", or "P",
|
|
|
|
* and expr is:
|
|
|
|
*
|
|
|
|
* 0x........ for L, where each . is a hex digit or a ?, presumably
|
|
|
|
* meaning "don't care"
|
|
|
|
*
|
|
|
|
* 0;0{=,!=}0b........ for D, where . is presumably a bit or a ?
|
|
|
|
*
|
|
|
|
* param=value for P, where param is something such as "src_port"
|
|
|
|
* and value is a value, presumably to test, for example, TCP or
|
|
|
|
* UDP ports
|
|
|
|
*
|
|
|
|
* UNCOND, presumably meaning "always"
|
|
|
|
*
|
|
|
|
* PARAM, followed by a parameter name (as with P:) and a value,
|
|
|
|
* possibly followed by LAYPARAM and a hex value
|
|
|
|
*
|
|
|
|
* DECKRNL, followed by a quoted string protocol name, un-quoted
|
|
|
|
* "LSBF" or "MSBF" (Least/Most Significant Byte First?), and
|
|
|
|
* an un-quoted string ending with _DK
|
|
|
|
*
|
|
|
|
* LAYPARAM, followed by a quoted protocol name and a number (-2147221504
|
|
|
|
* in one file, which is 0x80040000)
|
|
|
|
*
|
|
|
|
* SPC_CONF, folloed by a number, a quoted string with numbers separated
|
|
|
|
* by hyphens, and another number
|
|
|
|
*
|
|
|
|
* CIC_CONF, with a similar syntax to SPC_CONF
|
|
|
|
*
|
|
|
|
* LAYPOS, followed by a protocol name or "BASE" and 3 numbers.
|
|
|
|
*
|
|
|
|
* Most of this is probably not useful, but the RELATION lines with
|
|
|
|
* "BASE" could be used to figure out how to start the dissection
|
|
|
|
* (if we knew what "L" and "D" did), and *some* of the others might
|
|
|
|
* be useful if they don't match what's already in various dissector
|
|
|
|
* tables (the ones for IP and a higher-level protocol, for example,
|
|
|
|
* aren't very useful, as those are standardized, but the ones for
|
|
|
|
* TCP, UDP, and SCTP ports, and SCTP PPIs, might be useful).
|
|
|
|
*/
|
2005-06-10 16:01:16 +00:00
|
|
|
|
|
|
|
/*
|
2005-06-16 02:27:30 +00:00
|
|
|
* get_record: Get the next record into a buffer
|
2014-10-05 05:18:27 +00:00
|
|
|
* Every 8192 bytes 16 bytes are inserted in the file,
|
2005-06-16 02:27:30 +00:00
|
|
|
* even in the middle of a record.
|
2014-10-05 05:18:27 +00:00
|
|
|
* This reads the next record without the eventual 16 bytes.
|
2007-10-16 23:42:33 +00:00
|
|
|
* returns the length of the record + the stuffing (if any)
|
2005-06-10 16:01:16 +00:00
|
|
|
*
|
2011-02-04 09:45:39 +00:00
|
|
|
* Returns number of bytes read on success, 0 on EOF, -1 on error;
|
|
|
|
* if -1 is returned, *err is set to the error indication and, for
|
|
|
|
* errors where that's appropriate, *err_info is set to an additional
|
|
|
|
* error string.
|
|
|
|
*
|
2014-10-05 05:18:27 +00:00
|
|
|
* XXX: works at most with 8191 bytes per record
|
2005-06-10 16:01:16 +00:00
|
|
|
*/
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
static gint get_record(k12_t *file_data, FILE_T fh, gint64 file_offset,
|
|
|
|
gboolean is_random, int *err, gchar **err_info) {
|
|
|
|
guint8 *buffer = is_random ? file_data->rand_read_buff : file_data->seq_read_buff;
|
|
|
|
guint buffer_len = is_random ? file_data->rand_read_buff_len : file_data->seq_read_buff_len;
|
2014-10-05 18:46:43 +00:00
|
|
|
guint total_read = 0;
|
2011-04-18 20:03:32 +00:00
|
|
|
guint left;
|
2009-04-22 03:07:37 +00:00
|
|
|
guint8* writep;
|
2011-04-18 20:03:32 +00:00
|
|
|
#ifdef DEBUG_K12
|
|
|
|
guint actual_len;
|
|
|
|
#endif
|
2009-04-22 03:07:37 +00:00
|
|
|
|
2014-10-05 05:18:27 +00:00
|
|
|
/*
|
|
|
|
* Where the next unknown 16 bytes are stuffed to the file.
|
|
|
|
* Following the file header, they appear every 8192 bytes,
|
|
|
|
* starting right after the file header, so if the file offset
|
|
|
|
* relative to the file header is a multiple of 8192, the
|
|
|
|
* 16-byte blob is there.
|
|
|
|
*/
|
|
|
|
guint junky_offset = 8192 - (gint) ( (file_offset - K12_FILE_HDR_LEN) % 8192 );
|
2009-04-22 03:07:37 +00:00
|
|
|
|
|
|
|
K12_DBG(6,("get_record: ENTER: junky_offset=%" G_GINT64_MODIFIER "d, file_offset=%" G_GINT64_MODIFIER "d",junky_offset,file_offset));
|
|
|
|
|
|
|
|
/* no buffer is given, lets create it */
|
|
|
|
if (buffer == NULL) {
|
2014-10-05 05:18:27 +00:00
|
|
|
buffer = (guint8*)g_malloc(8192);
|
|
|
|
buffer_len = 8192;
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
if (is_random) {
|
|
|
|
file_data->rand_read_buff = buffer;
|
|
|
|
file_data->rand_read_buff_len = buffer_len;
|
|
|
|
} else {
|
|
|
|
file_data->seq_read_buff = buffer;
|
|
|
|
file_data->seq_read_buff_len = buffer_len;
|
|
|
|
}
|
2009-04-22 03:07:37 +00:00
|
|
|
}
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-10-05 05:18:27 +00:00
|
|
|
if ( junky_offset == 8192 ) {
|
|
|
|
/*
|
|
|
|
* We're at the beginning of one of the 16-byte blobs,
|
2014-10-05 18:46:43 +00:00
|
|
|
* so we first need to skip the blob.
|
2014-10-05 05:18:27 +00:00
|
|
|
*
|
2014-10-05 18:46:43 +00:00
|
|
|
* XXX - what if the blob is in the middle of the record
|
|
|
|
* length? If the record length is always a multiple of
|
|
|
|
* 4 bytes, that won't happen.
|
2014-10-05 05:18:27 +00:00
|
|
|
*/
|
2014-10-11 20:10:14 +00:00
|
|
|
if ( ! file_skip( fh, K12_FILE_BLOB_LEN, err ) )
|
2007-03-10 02:04:57 +00:00
|
|
|
return -1;
|
2014-10-11 20:10:14 +00:00
|
|
|
total_read += K12_FILE_BLOB_LEN;
|
2014-10-05 18:46:43 +00:00
|
|
|
}
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-10-05 18:46:43 +00:00
|
|
|
/*
|
|
|
|
* Read the record length.
|
|
|
|
*/
|
2014-10-11 20:10:14 +00:00
|
|
|
if ( !wtap_read_bytes( fh, buffer, 4, err, err_info ) )
|
2014-10-05 18:46:43 +00:00
|
|
|
return -1;
|
2014-10-11 20:10:14 +00:00
|
|
|
total_read += 4;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2013-12-03 20:35:50 +00:00
|
|
|
left = pntoh32(buffer + K12_RECORD_LEN);
|
2011-04-18 20:03:32 +00:00
|
|
|
#ifdef DEBUG_K12
|
|
|
|
actual_len = left;
|
|
|
|
#endif
|
2014-10-05 05:18:27 +00:00
|
|
|
junky_offset -= 4;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2009-04-22 03:07:37 +00:00
|
|
|
K12_DBG(5,("get_record: GET length=%u",left));
|
2007-03-17 14:56:04 +00:00
|
|
|
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
/*
|
2014-10-05 05:42:35 +00:00
|
|
|
* Record length must be at least large enough for the length
|
2014-10-05 05:18:27 +00:00
|
|
|
* and type, hence 8 bytes.
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
*
|
2014-10-05 05:18:27 +00:00
|
|
|
* XXX - is WTAP_MAX_PACKET_SIZE the right check for a maximum
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
* record size? Should we report this error differently?
|
|
|
|
*/
|
2014-10-05 05:18:27 +00:00
|
|
|
if (left < 8) {
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup_printf("k12: Record length %u is less than 8 bytes long",left);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (left > WTAP_MAX_PACKET_SIZE) {
|
2011-12-13 09:53:50 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
2014-10-05 05:18:27 +00:00
|
|
|
*err_info = g_strdup_printf("k12: Record length %u is greater than the maximum %u",left,WTAP_MAX_PACKET_SIZE);
|
2009-04-22 03:07:37 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2007-10-16 15:43:18 +00:00
|
|
|
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
/*
|
|
|
|
* XXX - calculate the lowest power of 2 >= left, rather than just
|
|
|
|
* looping.
|
|
|
|
*/
|
|
|
|
while (left > buffer_len) {
|
2014-10-07 05:01:12 +00:00
|
|
|
buffer = (guint8*)g_realloc(buffer,buffer_len*=2);
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
if (is_random) {
|
|
|
|
file_data->rand_read_buff = buffer;
|
|
|
|
file_data->rand_read_buff_len = buffer_len;
|
|
|
|
} else {
|
|
|
|
file_data->seq_read_buff = buffer;
|
|
|
|
file_data->seq_read_buff_len = buffer_len;
|
|
|
|
}
|
|
|
|
}
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2009-04-22 03:07:37 +00:00
|
|
|
writep = buffer + 4;
|
|
|
|
left -= 4;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
/* Read the rest of the record. */
|
2009-04-22 03:07:37 +00:00
|
|
|
do {
|
|
|
|
K12_DBG(6,("get_record: looping left=%d junky_offset=%" G_GINT64_MODIFIER "d",left,junky_offset));
|
2007-03-17 14:56:04 +00:00
|
|
|
|
2009-04-22 03:07:37 +00:00
|
|
|
if (junky_offset > left) {
|
2014-10-05 05:18:27 +00:00
|
|
|
/*
|
|
|
|
* The next 16-byte blob is past the end of this record.
|
|
|
|
* Just read the rest of the record.
|
|
|
|
*/
|
2014-10-11 20:10:14 +00:00
|
|
|
if ( !wtap_read_bytes( fh, writep, left, err, err_info ) )
|
2009-04-22 03:07:37 +00:00
|
|
|
return -1;
|
2014-10-11 20:10:14 +00:00
|
|
|
total_read += left;
|
2014-10-05 18:46:43 +00:00
|
|
|
break;
|
2009-04-22 03:07:37 +00:00
|
|
|
} else {
|
2014-10-05 05:18:27 +00:00
|
|
|
/*
|
|
|
|
* The next 16-byte blob is part of this record.
|
|
|
|
* Read up to the blob.
|
|
|
|
*/
|
2014-10-11 20:10:14 +00:00
|
|
|
if ( !wtap_read_bytes( fh, writep, junky_offset, err, err_info ) )
|
2009-04-22 03:07:37 +00:00
|
|
|
return -1;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-10-11 20:10:14 +00:00
|
|
|
total_read += junky_offset;
|
|
|
|
writep += junky_offset;
|
2007-03-17 14:56:04 +00:00
|
|
|
|
2014-10-05 05:18:27 +00:00
|
|
|
/*
|
|
|
|
* Skip the blob.
|
|
|
|
*/
|
2014-10-11 20:10:14 +00:00
|
|
|
if ( !file_skip( fh, K12_FILE_BLOB_LEN, err ) )
|
2009-04-22 03:07:37 +00:00
|
|
|
return -1;
|
2014-10-11 20:10:14 +00:00
|
|
|
total_read += K12_FILE_BLOB_LEN;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2009-04-22 03:07:37 +00:00
|
|
|
left -= junky_offset;
|
2014-10-05 05:18:27 +00:00
|
|
|
junky_offset = 8192;
|
2009-04-22 03:07:37 +00:00
|
|
|
}
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2009-04-22 03:07:37 +00:00
|
|
|
} while(left);
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2013-11-19 22:22:16 +00:00
|
|
|
K12_HEX_ASCII_DUMP(5,file_offset, "GOT record", buffer, actual_len);
|
2014-10-05 18:46:43 +00:00
|
|
|
return total_read;
|
2005-06-10 16:01:16 +00:00
|
|
|
}
|
|
|
|
|
2014-10-11 20:10:14 +00:00
|
|
|
static gboolean
|
|
|
|
memiszero(const void *ptr, size_t count)
|
|
|
|
{
|
|
|
|
const guint8 *p = (const guint8 *)ptr;
|
|
|
|
|
|
|
|
while (count != 0) {
|
2015-01-02 00:45:22 +00:00
|
|
|
if (*p != 0)
|
|
|
|
return FALSE;
|
|
|
|
p++;
|
|
|
|
count--;
|
2014-10-11 20:10:14 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-05-17 10:13:12 +00:00
|
|
|
static void
|
2013-06-16 00:20:00 +00:00
|
|
|
process_packet_data(struct wtap_pkthdr *phdr, Buffer *target, guint8 *buffer,
|
|
|
|
gint len, k12_t *k12)
|
|
|
|
{
|
2013-11-20 21:00:55 +00:00
|
|
|
guint32 type;
|
|
|
|
guint buffer_offset;
|
2013-05-17 10:13:12 +00:00
|
|
|
guint64 ts;
|
2013-06-16 00:20:00 +00:00
|
|
|
guint32 length;
|
|
|
|
guint32 extra_len;
|
|
|
|
guint32 src_id;
|
|
|
|
k12_src_desc_t* src_desc;
|
2013-05-17 10:13:12 +00:00
|
|
|
|
2014-05-24 18:28:30 +00:00
|
|
|
phdr->rec_type = REC_TYPE_PACKET;
|
2013-05-17 10:13:12 +00:00
|
|
|
phdr->presence_flags = WTAP_HAS_TS;
|
|
|
|
|
2013-12-03 20:35:50 +00:00
|
|
|
ts = pntoh64(buffer + K12_PACKET_TIMESTAMP);
|
2013-05-17 10:13:12 +00:00
|
|
|
|
|
|
|
phdr->ts.secs = (guint32) ((ts / 2000000) + 631152000);
|
|
|
|
phdr->ts.nsecs = (guint32) ( (ts % 2000000) * 500 );
|
|
|
|
|
2013-12-03 20:35:50 +00:00
|
|
|
length = pntoh32(buffer + K12_RECORD_FRAME_LEN) & 0x00001FFF;
|
2013-06-16 00:20:00 +00:00
|
|
|
phdr->len = phdr->caplen = length;
|
2013-05-17 10:13:12 +00:00
|
|
|
|
2013-12-03 20:35:50 +00:00
|
|
|
type = pntoh32(buffer + K12_RECORD_TYPE);
|
2013-11-20 21:00:55 +00:00
|
|
|
buffer_offset = (type == K12_REC_D0020) ? K12_PACKET_FRAME_D0020 : K12_PACKET_FRAME;
|
|
|
|
|
2014-08-02 11:00:48 +00:00
|
|
|
ws_buffer_assure_space(target, length);
|
|
|
|
memcpy(ws_buffer_start_ptr(target), buffer + buffer_offset, length);
|
2013-05-17 10:13:12 +00:00
|
|
|
|
|
|
|
/* extra information need by some protocols */
|
2013-11-20 21:00:55 +00:00
|
|
|
extra_len = len - buffer_offset - length;
|
2014-08-02 11:00:48 +00:00
|
|
|
ws_buffer_assure_space(&(k12->extra_info), extra_len);
|
|
|
|
memcpy(ws_buffer_start_ptr(&(k12->extra_info)),
|
2013-11-20 21:00:55 +00:00
|
|
|
buffer + buffer_offset + length, extra_len);
|
2014-08-02 11:00:48 +00:00
|
|
|
phdr->pseudo_header.k12.extra_info = (guint8*)ws_buffer_start_ptr(&(k12->extra_info));
|
2013-05-17 10:13:12 +00:00
|
|
|
phdr->pseudo_header.k12.extra_length = extra_len;
|
|
|
|
|
2013-12-03 20:35:50 +00:00
|
|
|
src_id = pntoh32(buffer + K12_RECORD_SRC_ID);
|
2013-06-16 00:20:00 +00:00
|
|
|
K12_DBG(5,("process_packet_data: src_id=%.8x",src_id));
|
2013-05-17 10:13:12 +00:00
|
|
|
phdr->pseudo_header.k12.input = src_id;
|
|
|
|
|
|
|
|
if ( ! (src_desc = (k12_src_desc_t*)g_hash_table_lookup(k12->src_by_id,GUINT_TO_POINTER(src_id))) ) {
|
|
|
|
/*
|
|
|
|
* Some records from K15 files have a port ID of an undeclared
|
|
|
|
* interface which happens to be the only one with the first byte changed.
|
|
|
|
* It is still unknown how to recognize when this happens.
|
|
|
|
* If the lookup of the interface record fails we'll mask it
|
|
|
|
* and retry.
|
|
|
|
*/
|
|
|
|
src_desc = (k12_src_desc_t*)g_hash_table_lookup(k12->src_by_id,GUINT_TO_POINTER(src_id&K12_RECORD_SRC_ID_MASK));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src_desc) {
|
2013-06-16 00:20:00 +00:00
|
|
|
K12_DBG(5,("process_packet_data: input_name='%s' stack_file='%s' type=%x",src_desc->input_name,src_desc->stack_file,src_desc->input_type));
|
2013-05-17 10:13:12 +00:00
|
|
|
phdr->pseudo_header.k12.input_name = src_desc->input_name;
|
|
|
|
phdr->pseudo_header.k12.stack_file = src_desc->stack_file;
|
|
|
|
phdr->pseudo_header.k12.input_type = src_desc->input_type;
|
|
|
|
|
|
|
|
switch(src_desc->input_type) {
|
|
|
|
case K12_PORT_ATMPVC:
|
2013-11-20 21:00:55 +00:00
|
|
|
if ((long)(buffer_offset + length + K12_PACKET_OFFSET_CID) < len) {
|
2013-12-03 20:35:50 +00:00
|
|
|
phdr->pseudo_header.k12.input_info.atm.vp = pntoh16(buffer + buffer_offset + length + K12_PACKET_OFFSET_VP);
|
|
|
|
phdr->pseudo_header.k12.input_info.atm.vc = pntoh16(buffer + buffer_offset + length + K12_PACKET_OFFSET_VC);
|
2013-11-20 21:00:55 +00:00
|
|
|
phdr->pseudo_header.k12.input_info.atm.cid = *((unsigned char*)(buffer + buffer_offset + length + K12_PACKET_OFFSET_CID));
|
2013-05-17 10:13:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Fall through */
|
|
|
|
default:
|
|
|
|
memcpy(&(phdr->pseudo_header.k12.input_info),&(src_desc->input_info),sizeof(src_desc->input_info));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2013-06-16 00:20:00 +00:00
|
|
|
K12_DBG(5,("process_packet_data: NO SRC_RECORD FOUND"));
|
2013-05-17 10:13:12 +00:00
|
|
|
|
|
|
|
memset(&(phdr->pseudo_header.k12),0,sizeof(phdr->pseudo_header.k12));
|
|
|
|
phdr->pseudo_header.k12.input_name = "unknown port";
|
|
|
|
phdr->pseudo_header.k12.stack_file = "unknown stack file";
|
|
|
|
}
|
|
|
|
|
|
|
|
phdr->pseudo_header.k12.input = src_id;
|
|
|
|
phdr->pseudo_header.k12.stuff = k12;
|
|
|
|
}
|
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean k12_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) {
|
2014-05-09 05:18:49 +00:00
|
|
|
k12_t *k12 = (k12_t *)wth->priv;
|
2007-03-10 02:04:57 +00:00
|
|
|
k12_src_desc_t* src_desc;
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
guint8* buffer;
|
2007-03-10 02:04:57 +00:00
|
|
|
gint64 offset;
|
2009-04-22 03:07:37 +00:00
|
|
|
gint len;
|
2007-03-10 02:04:57 +00:00
|
|
|
guint32 type;
|
2009-04-22 03:07:37 +00:00
|
|
|
guint32 src_id;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
offset = file_tell(wth->fh);
|
2007-10-16 15:43:18 +00:00
|
|
|
|
|
|
|
/* ignore the record if it isn't a packet */
|
2007-03-10 02:04:57 +00:00
|
|
|
do {
|
2014-10-11 20:10:14 +00:00
|
|
|
if ( k12->num_of_records == 0 ) {
|
|
|
|
/* No more records */
|
|
|
|
*err = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-04-22 03:07:37 +00:00
|
|
|
K12_DBG(5,("k12_read: offset=%i",offset));
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
*data_offset = offset;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
len = get_record(k12, wth->fh, offset, FALSE, err, err_info);
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
if (len < 0) {
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
/* read error */
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2007-03-10 02:04:57 +00:00
|
|
|
} else if (len == 0) {
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
/* EOF */
|
2014-10-11 20:10:14 +00:00
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
} else if (len < K12_RECORD_SRC_ID + 4) {
|
|
|
|
/* Record not large enough to contain a src ID */
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup_printf("data record length %d too short", len);
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2007-03-10 02:04:57 +00:00
|
|
|
}
|
2014-10-11 20:10:14 +00:00
|
|
|
k12->num_of_records--;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
buffer = k12->seq_read_buff;
|
|
|
|
|
2013-12-03 20:35:50 +00:00
|
|
|
type = pntoh32(buffer + K12_RECORD_TYPE);
|
|
|
|
src_id = pntoh32(buffer + K12_RECORD_SRC_ID);
|
2007-10-16 15:43:18 +00:00
|
|
|
|
|
|
|
|
2012-06-02 14:13:14 +00:00
|
|
|
if ( ! (src_desc = (k12_src_desc_t*)g_hash_table_lookup(k12->src_by_id,GUINT_TO_POINTER(src_id))) ) {
|
2009-04-22 03:07:37 +00:00
|
|
|
/*
|
|
|
|
* Some records from K15 files have a port ID of an undeclared
|
|
|
|
* interface which happens to be the only one with the first byte changed.
|
|
|
|
* It is still unknown how to recognize when this happens.
|
|
|
|
* If the lookup of the interface record fails we'll mask it
|
|
|
|
* and retry.
|
|
|
|
*/
|
2012-06-02 14:13:14 +00:00
|
|
|
src_desc = (k12_src_desc_t*)g_hash_table_lookup(k12->src_by_id,GUINT_TO_POINTER(src_id&K12_RECORD_SRC_ID_MASK));
|
2009-04-22 03:07:37 +00:00
|
|
|
}
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-17 14:56:04 +00:00
|
|
|
K12_DBG(5,("k12_read: record type=%x src_id=%x",type,src_id));
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
offset += len;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2013-11-20 21:00:55 +00:00
|
|
|
} while ( ((type & K12_MASK_PACKET) != K12_REC_PACKET && (type & K12_MASK_PACKET) != K12_REC_D0020) || !src_id || !src_desc );
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
process_packet_data(&wth->phdr, wth->frame_buffer, buffer, len, k12);
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
return TRUE;
|
2005-06-10 16:01:16 +00:00
|
|
|
}
|
|
|
|
|
2005-06-16 02:27:30 +00:00
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean k12_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) {
|
2014-05-09 05:18:49 +00:00
|
|
|
k12_t *k12 = (k12_t *)wth->priv;
|
2007-03-17 14:56:04 +00:00
|
|
|
guint8* buffer;
|
2009-04-22 03:07:37 +00:00
|
|
|
gint len;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-17 14:56:04 +00:00
|
|
|
K12_DBG(5,("k12_seek_read: ENTER"));
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if ( file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) {
|
2007-03-17 14:56:04 +00:00
|
|
|
K12_DBG(5,("k12_seek_read: SEEK ERROR"));
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2007-03-10 02:04:57 +00:00
|
|
|
}
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
len = get_record(k12, wth->random_fh, seek_off, TRUE, err, err_info);
|
2011-02-04 09:45:39 +00:00
|
|
|
if (len < 0) {
|
2007-03-17 14:56:04 +00:00
|
|
|
K12_DBG(5,("k12_seek_read: READ ERROR"));
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
} else if (len < K12_RECORD_SRC_ID + 4) {
|
|
|
|
/* Record not large enough to contain a src ID */
|
2011-02-04 09:45:39 +00:00
|
|
|
K12_DBG(5,("k12_seek_read: SHORT READ"));
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2011-02-04 09:45:39 +00:00
|
|
|
}
|
2007-10-16 15:43:18 +00:00
|
|
|
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
buffer = k12->rand_read_buff;
|
|
|
|
|
2013-06-16 00:20:00 +00:00
|
|
|
process_packet_data(phdr, buf, buffer, len, k12);
|
2007-03-10 02:04:57 +00:00
|
|
|
|
2007-03-17 14:56:04 +00:00
|
|
|
K12_DBG(5,("k12_seek_read: DONE OK"));
|
2007-03-10 02:04:57 +00:00
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
return TRUE;
|
2005-06-10 16:01:16 +00:00
|
|
|
}
|
|
|
|
|
2005-06-16 02:27:30 +00:00
|
|
|
|
2007-04-21 22:57:22 +00:00
|
|
|
static k12_t* new_k12_file_data(void) {
|
2012-06-02 14:13:14 +00:00
|
|
|
k12_t* fd = g_new(k12_t,1);
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
fd->file_len = 0;
|
|
|
|
fd->num_of_records = 0;
|
|
|
|
fd->src_by_name = g_hash_table_new(g_str_hash,g_str_equal);
|
|
|
|
fd->src_by_id = g_hash_table_new(g_direct_hash,g_direct_equal);
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
fd->seq_read_buff = NULL;
|
|
|
|
fd->seq_read_buff_len = 0;
|
|
|
|
fd->rand_read_buff = NULL;
|
|
|
|
fd->rand_read_buff_len = 0;
|
2007-03-10 02:04:57 +00:00
|
|
|
|
2014-08-02 11:00:48 +00:00
|
|
|
ws_buffer_init(&(fd->extra_info), 100);
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
return fd;
|
2005-06-13 19:45:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean destroy_srcdsc(gpointer k _U_, gpointer v, gpointer p _U_) {
|
2012-06-02 14:13:14 +00:00
|
|
|
k12_src_desc_t* rec = (k12_src_desc_t*)v;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2009-03-15 18:08:46 +00:00
|
|
|
g_free(rec->input_name);
|
|
|
|
g_free(rec->stack_file);
|
2007-03-10 02:04:57 +00:00
|
|
|
g_free(rec);
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
return TRUE;
|
2005-06-13 19:45:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void destroy_k12_file_data(k12_t* fd) {
|
2007-03-10 02:04:57 +00:00
|
|
|
g_hash_table_destroy(fd->src_by_id);
|
2007-10-16 15:43:18 +00:00
|
|
|
g_hash_table_foreach_remove(fd->src_by_name,destroy_srcdsc,NULL);
|
2007-03-10 02:04:57 +00:00
|
|
|
g_hash_table_destroy(fd->src_by_name);
|
2014-08-02 11:00:48 +00:00
|
|
|
ws_buffer_free(&(fd->extra_info));
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
g_free(fd->seq_read_buff);
|
|
|
|
g_free(fd->rand_read_buff);
|
2007-03-10 02:04:57 +00:00
|
|
|
g_free(fd);
|
2005-06-10 16:01:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
static void k12_close(wtap *wth) {
|
|
|
|
k12_t *k12 = (k12_t *)wth->priv;
|
2010-02-26 07:59:54 +00:00
|
|
|
|
|
|
|
destroy_k12_file_data(k12);
|
2015-01-02 00:45:22 +00:00
|
|
|
wth->priv = NULL; /* destroy_k12_file_data freed it */
|
2005-10-13 18:37:42 +00:00
|
|
|
#ifdef DEBUG_K12
|
2007-03-17 14:56:04 +00:00
|
|
|
K12_DBG(5,("k12_close: CLOSED"));
|
2005-10-24 21:20:03 +00:00
|
|
|
if (env_file) fclose(dbg_out);
|
2005-10-13 18:37:42 +00:00
|
|
|
#endif
|
2005-06-10 16:01:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-09 23:44:15 +00:00
|
|
|
wtap_open_return_val k12_open(wtap *wth, int *err, gchar **err_info) {
|
2007-03-10 02:04:57 +00:00
|
|
|
k12_src_desc_t* rec;
|
2014-10-05 05:18:27 +00:00
|
|
|
guint8 header_buffer[K12_FILE_HDR_LEN];
|
2007-03-17 14:56:04 +00:00
|
|
|
guint8* read_buffer;
|
2007-03-10 02:04:57 +00:00
|
|
|
guint32 type;
|
|
|
|
long offset;
|
|
|
|
long len;
|
2014-12-06 04:53:39 +00:00
|
|
|
guint port_type;
|
2007-03-10 02:04:57 +00:00
|
|
|
guint32 rec_len;
|
2014-12-06 04:53:39 +00:00
|
|
|
guint32 hwpart_len;
|
2007-03-10 02:04:57 +00:00
|
|
|
guint32 name_len;
|
|
|
|
guint32 stack_len;
|
|
|
|
guint i;
|
|
|
|
k12_t* file_data;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2005-10-13 18:37:42 +00:00
|
|
|
#ifdef DEBUG_K12
|
2005-10-24 21:20:03 +00:00
|
|
|
gchar* env_level = getenv("K12_DEBUG_LEVEL");
|
|
|
|
env_file = getenv("K12_DEBUG_FILENAME");
|
2012-10-10 19:33:49 +00:00
|
|
|
if ( env_file ) {
|
2015-01-02 00:45:22 +00:00
|
|
|
dbg_out = ws_fopen(env_file,"w");
|
|
|
|
if (dbg_out == NULL) {
|
|
|
|
dbg_out = stderr;
|
|
|
|
K12_DBG(1,("unable to open K12 DEBUG FILENAME for writing! Logging to standard error"));
|
|
|
|
}
|
2013-11-19 20:12:51 +00:00
|
|
|
}
|
2012-10-10 19:33:49 +00:00
|
|
|
else
|
2015-01-02 00:45:22 +00:00
|
|
|
dbg_out = stderr;
|
2013-11-19 20:12:51 +00:00
|
|
|
if ( env_level ) debug_level = (unsigned int)strtoul(env_level,NULL,10);
|
2007-03-17 14:56:04 +00:00
|
|
|
K12_DBG(1,("k12_open: ENTER debug_level=%u",debug_level));
|
2005-10-13 18:37:42 +00:00
|
|
|
#endif
|
2007-10-16 15:43:18 +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_buffer,K12_FILE_HDR_LEN,err,err_info) ) {
|
2011-02-04 09:45:39 +00:00
|
|
|
K12_DBG(1,("k12_open: FILE HEADER TOO SHORT OR READ ERROR"));
|
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;
|
2014-10-07 19:49:14 +00:00
|
|
|
}
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_NOT_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
|
|
|
}
|
|
|
|
|
|
|
|
if ( memcmp(header_buffer,k12_file_magic,8) != 0 ) {
|
|
|
|
K12_DBG(1,("k12_open: BAD MAGIC"));
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_NOT_MINE;
|
2007-03-10 02:04:57 +00:00
|
|
|
}
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-10-05 05:18:27 +00:00
|
|
|
offset = K12_FILE_HDR_LEN;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
file_data = new_k12_file_data();
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2013-12-03 20:35:50 +00:00
|
|
|
file_data->file_len = pntoh32( header_buffer + 0x8);
|
2014-10-11 20:10:14 +00:00
|
|
|
if (memiszero(header_buffer + 0x10, K12_FILE_HDR_LEN - 0x10)) {
|
|
|
|
/*
|
|
|
|
* The rest of the file header is all zeroes. That means
|
2015-01-02 00:45:22 +00:00
|
|
|
* this is a file written by the old Wireshark code, and
|
|
|
|
* a count of records in the file is at an offset of 0x0C.
|
2014-10-11 20:10:14 +00:00
|
|
|
*/
|
|
|
|
file_data->num_of_records = pntoh32( header_buffer + 0x0C );
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* There's at least one non-zero byte in the rest of the
|
|
|
|
* header. The value 8192 is at 0xC (page size?), and
|
|
|
|
* what appears to be the number of records in the file
|
|
|
|
* is at an offset of 0x24 and at an offset of 0x2c.
|
|
|
|
*
|
|
|
|
* If the two values are not the same, we fail; if that's
|
|
|
|
* the case, we need to see the file to figure out which
|
|
|
|
* of those two values, if any, is the count.
|
|
|
|
*/
|
|
|
|
file_data->num_of_records = pntoh32( header_buffer + K12_FILE_HDR_RECORD_COUNT_1 );
|
|
|
|
if ( file_data->num_of_records != pntoh32( header_buffer + K12_FILE_HDR_RECORD_COUNT_2 ) ) {
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup_printf("k12: two different record counts, %u at 0x%02x and %u at 0x%02x",
|
|
|
|
file_data->num_of_records,
|
|
|
|
K12_FILE_HDR_RECORD_COUNT_1,
|
|
|
|
pntoh32( header_buffer + K12_FILE_HDR_RECORD_COUNT_2 ),
|
|
|
|
K12_FILE_HDR_RECORD_COUNT_2 );
|
|
|
|
return WTAP_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
}
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-17 14:56:04 +00:00
|
|
|
K12_DBG(5,("k12_open: FILE_HEADER OK: offset=%x file_len=%i records=%i",
|
2005-10-13 18:37:42 +00:00
|
|
|
offset,
|
|
|
|
file_data->file_len,
|
2007-03-10 02:04:57 +00:00
|
|
|
file_data->num_of_records ));
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
do {
|
2014-10-11 20:10:14 +00:00
|
|
|
if ( file_data->num_of_records == 0 ) {
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
|
|
|
destroy_k12_file_data(file_data);
|
|
|
|
return WTAP_OPEN_ERROR;
|
|
|
|
}
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
len = get_record(file_data, wth->fh, offset, FALSE, err, err_info);
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2011-02-04 09:45:39 +00:00
|
|
|
if ( len < 0 ) {
|
2007-03-17 14:56:04 +00:00
|
|
|
K12_DBG(1,("k12_open: BAD HEADER RECORD",len));
|
2010-02-26 07:59:54 +00:00
|
|
|
destroy_k12_file_data(file_data);
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
2007-03-10 02:04:57 +00:00
|
|
|
}
|
2014-10-11 20:10:14 +00:00
|
|
|
if ( len == 0 ) {
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
K12_DBG(1,("k12_open: BAD HEADER RECORD",len));
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
|
|
|
destroy_k12_file_data(file_data);
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
}
|
2007-10-16 15:43:18 +00:00
|
|
|
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
read_buffer = file_data->seq_read_buff;
|
|
|
|
|
2013-12-03 20:35:50 +00:00
|
|
|
rec_len = pntoh32( read_buffer + K12_RECORD_LEN );
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
if (rec_len < K12_RECORD_TYPE + 4) {
|
|
|
|
/* Record isn't long enough to have a type field */
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup_printf("k12_open: record length %u < %u",
|
|
|
|
rec_len, K12_RECORD_TYPE + 4);
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
}
|
2013-12-03 20:35:50 +00:00
|
|
|
type = pntoh32( read_buffer + K12_RECORD_TYPE );
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2013-11-20 21:00:55 +00:00
|
|
|
if ( (type & K12_MASK_PACKET) == K12_REC_PACKET ||
|
|
|
|
(type & K12_MASK_PACKET) == K12_REC_D0020) {
|
2007-03-10 02:04:57 +00:00
|
|
|
/*
|
|
|
|
* we are at the first packet record, rewind and leave.
|
|
|
|
*/
|
2014-05-09 05:18:49 +00:00
|
|
|
if (file_seek(wth->fh, offset, SEEK_SET, err) == -1) {
|
2007-03-10 02:04:57 +00:00
|
|
|
destroy_k12_file_data(file_data);
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
2007-03-10 02:04:57 +00:00
|
|
|
}
|
2007-03-17 14:56:04 +00:00
|
|
|
K12_DBG(5,("k12_open: FIRST PACKET offset=%x",offset));
|
2007-03-10 02:04:57 +00:00
|
|
|
break;
|
2014-10-11 20:10:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
|
|
|
case K12_REC_SRCDSC:
|
|
|
|
case K12_REC_SRCDSC2:
|
2012-06-02 14:13:14 +00:00
|
|
|
rec = g_new0(k12_src_desc_t,1);
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-12-06 04:53:39 +00:00
|
|
|
if (rec_len < K12_SRCDESC_HWPART) {
|
|
|
|
/*
|
|
|
|
* Record isn't long enough to have the fixed-length portion
|
|
|
|
* of the source descriptor field.
|
|
|
|
*/
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup_printf("k12_open: source descriptor record length %u < %u",
|
2014-12-08 19:40:35 +00:00
|
|
|
rec_len, K12_SRCDESC_HWPART);
|
2014-10-07 22:07:25 +00:00
|
|
|
destroy_k12_file_data(file_data);
|
|
|
|
g_free(rec);
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
}
|
2014-12-06 04:53:39 +00:00
|
|
|
port_type = read_buffer[K12_SRCDESC_PORT_TYPE];
|
|
|
|
hwpart_len = pntoh16( read_buffer + K12_SRCDESC_HWPARTLEN );
|
2013-12-03 20:35:50 +00:00
|
|
|
name_len = pntoh16( read_buffer + K12_SRCDESC_NAMELEN );
|
|
|
|
stack_len = pntoh16( read_buffer + K12_SRCDESC_STACKLEN );
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2013-12-03 20:35:50 +00:00
|
|
|
rec->input = pntoh32( read_buffer + K12_RECORD_SRC_ID );
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-17 14:56:04 +00:00
|
|
|
K12_DBG(5,("k12_open: INTERFACE RECORD offset=%x interface=%x",offset,rec->input));
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-12-06 04:53:39 +00:00
|
|
|
if (name_len == 0) {
|
|
|
|
K12_DBG(5,("k12_open: failed (name_len == 0 in source description"));
|
|
|
|
destroy_k12_file_data(file_data);
|
2007-03-10 02:04:57 +00:00
|
|
|
g_free(rec);
|
2014-12-06 04:53:39 +00:00
|
|
|
return WTAP_OPEN_NOT_MINE;
|
|
|
|
}
|
|
|
|
if (stack_len == 0) {
|
|
|
|
K12_DBG(5,("k12_open: failed (stack_len == 0 in source description"));
|
2010-02-26 07:59:54 +00:00
|
|
|
destroy_k12_file_data(file_data);
|
2014-10-07 22:07:25 +00:00
|
|
|
g_free(rec);
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_NOT_MINE;
|
2007-03-10 02:04:57 +00:00
|
|
|
}
|
2014-12-06 04:53:39 +00:00
|
|
|
if (rec_len < K12_SRCDESC_HWPART + hwpart_len + name_len + stack_len) {
|
|
|
|
/*
|
|
|
|
* Record isn't long enough to have the full source descriptor
|
|
|
|
* field, including the variable-length parts.
|
|
|
|
*/
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup_printf("k12_open: source descriptor record length %u < %u (%u + %u + %u + %u)",
|
|
|
|
rec_len,
|
|
|
|
K12_SRCDESC_HWPART + hwpart_len + name_len + stack_len,
|
|
|
|
K12_SRCDESC_HWPART, hwpart_len, name_len, stack_len);
|
|
|
|
destroy_k12_file_data(file_data);
|
|
|
|
g_free(rec);
|
|
|
|
return WTAP_OPEN_ERROR;
|
|
|
|
}
|
2007-03-10 02:04:57 +00:00
|
|
|
|
2014-12-06 04:53:39 +00:00
|
|
|
if (hwpart_len) {
|
|
|
|
if (hwpart_len < 4) {
|
|
|
|
/* Hardware part isn't long enough to have a type field */
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
2014-12-06 04:53:39 +00:00
|
|
|
*err_info = g_strdup_printf("k12_open: source descriptor hardware part length %u < 4",
|
|
|
|
hwpart_len);
|
2014-10-07 22:07:25 +00:00
|
|
|
destroy_k12_file_data(file_data);
|
|
|
|
g_free(rec);
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
}
|
2014-12-06 04:53:39 +00:00
|
|
|
switch(( rec->input_type = pntoh32( read_buffer + K12_SRCDESC_HWPART + K12_SRCDESC_HWPARTTYPE ) )) {
|
2007-03-10 02:04:57 +00:00
|
|
|
case K12_PORT_DS0S:
|
2014-12-06 04:53:39 +00:00
|
|
|
/* This appears to be variable-length */
|
2007-03-10 02:04:57 +00:00
|
|
|
rec->input_info.ds0mask = 0x00000000;
|
2014-12-06 04:53:39 +00:00
|
|
|
if (hwpart_len > K12_SRCDESC_DS0_MASK) {
|
|
|
|
for (i = 0; i < hwpart_len - K12_SRCDESC_DS0_MASK; i++) {
|
2015-04-30 22:21:00 +00:00
|
|
|
rec->input_info.ds0mask |= ( *(read_buffer + K12_SRCDESC_HWPART + K12_SRCDESC_DS0_MASK + i) == 0xff ) ? 1U<<(31-i) : 0x0;
|
2014-12-06 04:53:39 +00:00
|
|
|
}
|
2007-03-10 02:04:57 +00:00
|
|
|
}
|
2011-02-04 09:45:39 +00:00
|
|
|
break;
|
2007-03-10 02:04:57 +00:00
|
|
|
case K12_PORT_ATMPVC:
|
2014-12-06 04:53:39 +00:00
|
|
|
if (hwpart_len < K12_SRCDESC_ATM_VCI + 2) {
|
|
|
|
/* Hardware part isn't long enough to have ATM information */
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
2014-12-06 04:53:39 +00:00
|
|
|
*err_info = g_strdup_printf("k12_open: source descriptor hardware part length %u < %u",
|
|
|
|
hwpart_len,
|
|
|
|
K12_SRCDESC_ATM_VCI + 2);
|
2014-10-07 22:07:25 +00:00
|
|
|
destroy_k12_file_data(file_data);
|
|
|
|
g_free(rec);
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
}
|
|
|
|
|
2014-12-06 04:53:39 +00:00
|
|
|
rec->input_info.atm.vp = pntoh16( read_buffer + K12_SRCDESC_HWPART + K12_SRCDESC_ATM_VPI );
|
|
|
|
rec->input_info.atm.vc = pntoh16( read_buffer + K12_SRCDESC_HWPART + K12_SRCDESC_ATM_VCI );
|
2007-03-10 02:04:57 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
} else {
|
2014-10-07 05:01:12 +00:00
|
|
|
/* Record viewer generated files don't have this information */
|
2014-12-06 04:53:39 +00:00
|
|
|
if (port_type >= 0x14
|
|
|
|
&& port_type <= 0x17) {
|
2007-10-16 15:43:18 +00:00
|
|
|
/* For ATM2_E1DS1, ATM2_E3DS3,
|
2007-03-10 02:04:57 +00:00
|
|
|
ATM2_STM1EL and ATM2_STM1OP */
|
|
|
|
rec->input_type = K12_PORT_ATMPVC;
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
rec->input_info.atm.vp = 0;
|
|
|
|
rec->input_info.atm.vc = 0;
|
|
|
|
}
|
2007-03-10 02:04:57 +00:00
|
|
|
}
|
|
|
|
|
2014-12-07 20:17:48 +00:00
|
|
|
if (read_buffer[K12_SRCDESC_HWPART + hwpart_len + name_len - 1] != '\0') {
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup("k12_open: source descriptor record contains non-null-terminated link-layer name");
|
|
|
|
destroy_k12_file_data(file_data);
|
|
|
|
g_free(rec);
|
|
|
|
return WTAP_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
if (read_buffer[K12_SRCDESC_HWPART + hwpart_len + name_len + stack_len - 1] != '\0') {
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup("k12_open: source descriptor record contains non-null-terminated stack path");
|
|
|
|
destroy_k12_file_data(file_data);
|
|
|
|
g_free(rec);
|
|
|
|
return WTAP_OPEN_ERROR;
|
|
|
|
}
|
2014-12-06 04:53:39 +00:00
|
|
|
rec->input_name = (gchar *)g_memdup(read_buffer + K12_SRCDESC_HWPART + hwpart_len, name_len);
|
|
|
|
rec->stack_file = (gchar *)g_memdup(read_buffer + K12_SRCDESC_HWPART + hwpart_len + name_len, stack_len);
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2008-09-03 19:14:52 +00:00
|
|
|
ascii_strdown_inplace (rec->stack_file);
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
g_hash_table_insert(file_data->src_by_id,GUINT_TO_POINTER(rec->input),rec);
|
|
|
|
g_hash_table_insert(file_data->src_by_name,rec->stack_file,rec);
|
2014-10-11 20:10:14 +00:00
|
|
|
break;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-10-11 20:10:14 +00:00
|
|
|
case K12_REC_STK_FILE:
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
K12_DBG(1,("k12_open: K12_REC_STK_FILE"));
|
2013-12-03 20:35:50 +00:00
|
|
|
K12_DBG(1,("Field 1: 0x%08x",pntoh32( read_buffer + 0x08 )));
|
|
|
|
K12_DBG(1,("Field 2: 0x%08x",pntoh32( read_buffer + 0x0c )));
|
2014-10-05 05:18:27 +00:00
|
|
|
K12_ASCII_DUMP(1, read_buffer, rec_len, 16);
|
2014-10-11 20:10:14 +00:00
|
|
|
break;
|
Add code to dump part of a record as ASCII, and use it to dump strings
in a source description record, including the stack. Dump some other
fields in those records as well.
Attach separate sequential and random read buffers to the private data
structure, rather than allocating them in various routines (and not
always freeing them) and, in at least one case, allocating a single
*common* buffer for all wth's to use.
Fix some comments (the DS0 mask is 32 bytes long, but gets turned into a
bitmask).
Put in a description of what a "stack file"'s contents look like. Much
of it may be useless to us (for example, we have the notion that TCP has
protocol number 6 built-in...), but the RELATION entries that map from
"BASE" to a protocol could obviate the need to have the user specify a
map from stack file names to starting protocols, and we might be able to
use, for example, entries that map TCP/UDP/SCTP port numbers to
protocols to obviate the need for the user to explicitly use Decode As
or otherwise configure port-to-protocol mappings themselves.
Add a bunch of record length checks before we fetch data from records.
svn path=/trunk/; revision=53450
2013-11-20 20:17:33 +00:00
|
|
|
|
2014-10-11 20:10:14 +00:00
|
|
|
default:
|
2013-11-19 22:22:16 +00:00
|
|
|
K12_DBG(1,("k12_open: RECORD TYPE 0x%08x",type));
|
2014-10-11 20:10:14 +00:00
|
|
|
break;
|
2007-03-10 02:04:57 +00:00
|
|
|
}
|
2014-10-11 20:10:14 +00:00
|
|
|
offset += len;
|
|
|
|
file_data->num_of_records--;
|
2007-03-10 02:04:57 +00:00
|
|
|
} while(1);
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_K12;
|
|
|
|
wth->file_encap = WTAP_ENCAP_K12;
|
|
|
|
wth->snapshot_length = 0;
|
|
|
|
wth->subtype_read = k12_read;
|
|
|
|
wth->subtype_seek_read = k12_seek_read;
|
|
|
|
wth->subtype_close = k12_close;
|
|
|
|
wth->priv = (void *)file_data;
|
2014-09-28 18:37:06 +00:00
|
|
|
wth->file_tsprec = WTAP_TSPREC_NSEC;
|
2007-03-10 02:04:57 +00:00
|
|
|
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_MINE;
|
2005-06-10 16:01:16 +00:00
|
|
|
}
|
2005-06-17 17:26:43 +00:00
|
|
|
|
2010-02-26 07:59:54 +00:00
|
|
|
typedef struct {
|
2015-01-02 00:45:22 +00:00
|
|
|
guint32 file_len;
|
|
|
|
guint32 num_of_records;
|
|
|
|
guint32 file_offset;
|
2010-02-26 07:59:54 +00:00
|
|
|
} k12_dump_t;
|
|
|
|
|
2005-06-17 17:26:43 +00:00
|
|
|
int k12_dump_can_write_encap(int encap) {
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
if (encap == WTAP_ENCAP_PER_PACKET)
|
|
|
|
return WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
if (encap != WTAP_ENCAP_K12)
|
2014-12-17 06:40:45 +00:00
|
|
|
return WTAP_ERR_UNWRITABLE_ENCAP;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
return 0;
|
2005-06-17 17:26:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const gchar dumpy_junk[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
static gboolean k12_dump_record(wtap_dumper *wdh, guint32 len, guint8* buffer, int *err_p) {
|
2010-02-26 07:59:54 +00:00
|
|
|
k12_dump_t *k12 = (k12_dump_t *)wdh->priv;
|
2014-10-05 05:18:27 +00:00
|
|
|
guint32 junky_offset = (8192 - ( (k12->file_offset - K12_FILE_HDR_LEN) % 8192 )) % 8192;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
if (len > junky_offset) {
|
2007-09-28 17:22:03 +00:00
|
|
|
if (junky_offset) {
|
2014-05-09 05:18:49 +00:00
|
|
|
if (! wtap_dump_file_write(wdh, buffer, junky_offset, err_p))
|
2007-09-28 17:22:03 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2014-10-05 05:18:27 +00:00
|
|
|
if (! wtap_dump_file_write(wdh, dumpy_junk, K12_FILE_BLOB_LEN, err_p))
|
2007-09-28 17:22:03 +00:00
|
|
|
return FALSE;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if (! wtap_dump_file_write(wdh, buffer+junky_offset, len - junky_offset, err_p))
|
2007-09-28 17:22:03 +00:00
|
|
|
return FALSE;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-10-05 05:18:27 +00:00
|
|
|
k12->file_offset += len + K12_FILE_BLOB_LEN;
|
2014-10-11 20:10:14 +00:00
|
|
|
k12->file_len += len + K12_FILE_BLOB_LEN;
|
2007-03-10 02:04:57 +00:00
|
|
|
} else {
|
2014-05-09 05:18:49 +00:00
|
|
|
if (! wtap_dump_file_write(wdh, buffer, len, err_p))
|
2007-09-28 17:22:03 +00:00
|
|
|
return FALSE;
|
2010-02-26 07:59:54 +00:00
|
|
|
k12->file_offset += len;
|
2014-10-11 20:10:14 +00:00
|
|
|
k12->file_len += len;
|
2007-03-10 02:04:57 +00:00
|
|
|
}
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2010-02-26 07:59:54 +00:00
|
|
|
k12->num_of_records++;
|
2007-09-28 17:22:03 +00:00
|
|
|
return TRUE;
|
2005-06-17 17:26:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void k12_dump_src_setting(gpointer k _U_, gpointer v, gpointer p) {
|
2012-06-02 14:13:14 +00:00
|
|
|
k12_src_desc_t* src_desc = (k12_src_desc_t*)v;
|
2014-05-09 05:18:49 +00:00
|
|
|
wtap_dumper *wdh = (wtap_dumper *)p;
|
2007-03-10 02:04:57 +00:00
|
|
|
guint32 len;
|
|
|
|
guint offset;
|
|
|
|
guint i;
|
2007-09-28 17:22:03 +00:00
|
|
|
int errxxx; /* dummy */
|
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
union {
|
2014-10-05 05:18:27 +00:00
|
|
|
guint8 buffer[8192];
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
struct {
|
|
|
|
guint32 len;
|
|
|
|
guint32 type;
|
|
|
|
guint32 unk32_1;
|
|
|
|
guint32 input;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
guint16 unk32_2;
|
|
|
|
guint16 color;
|
|
|
|
guint32 unk32_3;
|
|
|
|
guint32 unk32_4;
|
|
|
|
guint16 unk16_1;
|
2014-12-06 04:53:39 +00:00
|
|
|
guint16 hwpart_len;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
guint16 name_len;
|
|
|
|
guint16 stack_len;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
struct {
|
|
|
|
guint32 type;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
guint32 unk32;
|
|
|
|
guint8 mask[32];
|
|
|
|
} ds0mask;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
struct {
|
2014-10-05 05:18:27 +00:00
|
|
|
guint8 unk_data[16];
|
2007-03-10 02:04:57 +00:00
|
|
|
guint16 vp;
|
|
|
|
guint16 vc;
|
|
|
|
} atm;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
guint32 unk;
|
|
|
|
} desc;
|
|
|
|
} extra;
|
|
|
|
} record;
|
|
|
|
} obj;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
obj.record.type = g_htonl(K12_REC_SRCDSC);
|
|
|
|
obj.record.unk32_1 = g_htonl(0x00000001);
|
|
|
|
obj.record.input = g_htonl(src_desc->input);
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
obj.record.unk32_2 = g_htons(0x0000);
|
|
|
|
obj.record.color = g_htons(0x060f);
|
|
|
|
obj.record.unk32_3 = g_htonl(0x00000003);
|
|
|
|
switch (src_desc->input_type) {
|
|
|
|
case K12_PORT_ATMPVC:
|
|
|
|
obj.record.unk32_4 = g_htonl(0x01001400);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
obj.record.unk32_4 = g_htonl(0x01000100);
|
|
|
|
}
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
obj.record.unk16_1 = g_htons(0x0000);
|
2009-03-09 21:18:55 +00:00
|
|
|
obj.record.name_len = (guint16) strlen(src_desc->input_name) + 1;
|
|
|
|
obj.record.stack_len = (guint16) strlen(src_desc->stack_file) + 1;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
obj.record.extra.type = g_htonl(src_desc->input_type);
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
switch (src_desc->input_type) {
|
|
|
|
case K12_PORT_ATMPVC:
|
2014-12-06 04:53:39 +00:00
|
|
|
obj.record.hwpart_len = g_htons(0x18);
|
2007-03-10 02:04:57 +00:00
|
|
|
obj.record.extra.desc.atm.vp = g_htons(src_desc->input_info.atm.vp);
|
|
|
|
obj.record.extra.desc.atm.vc = g_htons(src_desc->input_info.atm.vc);
|
|
|
|
offset = 0x3c;
|
|
|
|
break;
|
|
|
|
case K12_PORT_DS0S:
|
2014-12-06 04:53:39 +00:00
|
|
|
obj.record.hwpart_len = g_htons(0x18);
|
2007-03-10 02:04:57 +00:00
|
|
|
for( i=0; i<32; i++ ) {
|
|
|
|
obj.record.extra.desc.ds0mask.mask[i] =
|
2005-10-24 21:20:03 +00:00
|
|
|
(src_desc->input_info.ds0mask & (1 << i)) ? 0xff : 0x00;
|
2007-03-10 02:04:57 +00:00
|
|
|
}
|
2012-05-04 21:18:01 +00:00
|
|
|
offset = 0x3c;
|
2007-03-10 02:04:57 +00:00
|
|
|
break;
|
|
|
|
default:
|
2014-12-06 04:53:39 +00:00
|
|
|
obj.record.hwpart_len = g_htons(0x08);
|
2007-03-10 02:04:57 +00:00
|
|
|
offset = 0x2c;
|
|
|
|
break;
|
|
|
|
}
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
memcpy(obj.buffer + offset,
|
|
|
|
src_desc->input_name,
|
|
|
|
obj.record.name_len);
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
memcpy(obj.buffer + offset + obj.record.name_len,
|
|
|
|
src_desc->stack_file,
|
|
|
|
obj.record.stack_len);
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
len = offset + obj.record.name_len + obj.record.stack_len;
|
|
|
|
len += (len % 4) ? 4 - (len % 4) : 0;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
obj.record.len = g_htonl(len);
|
|
|
|
obj.record.name_len = g_htons(obj.record.name_len);
|
|
|
|
obj.record.stack_len = g_htons(obj.record.stack_len);
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-09-28 17:22:03 +00:00
|
|
|
k12_dump_record(wdh,len,obj.buffer, &errxxx); /* fwrite errs ignored: see k12_dump below */
|
2005-06-17 17:26:43 +00:00
|
|
|
}
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
static gboolean k12_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
|
2014-12-18 00:02:50 +00:00
|
|
|
const guint8 *pd, int *err, gchar **err_info _U_) {
|
2012-10-16 21:50:57 +00:00
|
|
|
const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header;
|
2010-02-26 07:59:54 +00:00
|
|
|
k12_dump_t *k12 = (k12_dump_t *)wdh->priv;
|
2009-04-22 03:07:37 +00:00
|
|
|
guint32 len;
|
2007-03-10 02:04:57 +00:00
|
|
|
union {
|
2014-10-05 05:18:27 +00:00
|
|
|
guint8 buffer[8192];
|
2007-03-10 02:04:57 +00:00
|
|
|
struct {
|
|
|
|
guint32 len;
|
|
|
|
guint32 type;
|
|
|
|
guint32 frame_len;
|
|
|
|
guint32 input;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
guint32 datum_1;
|
|
|
|
guint32 datum_2;
|
|
|
|
guint64 ts;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
guint8 frame[0x1fc0];
|
|
|
|
} record;
|
|
|
|
} obj;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-05-24 18:28:30 +00:00
|
|
|
/* We can only write packet records. */
|
|
|
|
if (phdr->rec_type != REC_TYPE_PACKET) {
|
2014-12-18 00:31:49 +00:00
|
|
|
*err = WTAP_ERR_UNWRITABLE_REC_TYPE;
|
2014-05-24 18:28:30 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-02-26 07:59:54 +00:00
|
|
|
if (k12->num_of_records == 0) {
|
2012-06-02 15:32:34 +00:00
|
|
|
k12_t* file_data = (k12_t*)pseudo_header->k12.stuff;
|
2007-09-28 17:22:03 +00:00
|
|
|
/* XXX: We'll assume that any fwrite errors in k12_dump_src_setting will */
|
|
|
|
/* repeat during the final k12_dump_record at the end of k12_dump */
|
|
|
|
/* (and thus cause an error return from k12_dump). */
|
|
|
|
/* (I don't see a reasonably clean way to handle any fwrite errors */
|
|
|
|
/* encountered in k12_dump_src_setting). */
|
2007-03-10 02:04:57 +00:00
|
|
|
g_hash_table_foreach(file_data->src_by_id,k12_dump_src_setting,wdh);
|
|
|
|
}
|
2014-01-22 00:26:36 +00:00
|
|
|
obj.record.len = 0x20 + phdr->caplen;
|
2007-03-10 02:04:57 +00:00
|
|
|
obj.record.len += (obj.record.len % 4) ? 4 - obj.record.len % 4 : 0;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
len = obj.record.len;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
obj.record.len = g_htonl(obj.record.len);
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
obj.record.type = g_htonl(K12_REC_PACKET);
|
2014-01-22 00:26:36 +00:00
|
|
|
obj.record.frame_len = g_htonl(phdr->caplen);
|
2007-03-10 02:04:57 +00:00
|
|
|
obj.record.input = g_htonl(pseudo_header->k12.input);
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
obj.record.ts = GUINT64_TO_BE((((guint64)phdr->ts.secs - 631152000) * 2000000) + (phdr->ts.nsecs / 1000 * 2));
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-01-22 00:26:36 +00:00
|
|
|
memcpy(obj.record.frame,pd,phdr->caplen);
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-09-28 17:22:03 +00:00
|
|
|
return k12_dump_record(wdh,len,obj.buffer, err);
|
2005-06-17 17:26:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const guint8 k12_eof[] = {0xff,0xff};
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
static gboolean k12_dump_close(wtap_dumper *wdh, int *err) {
|
2010-02-26 07:59:54 +00:00
|
|
|
k12_dump_t *k12 = (k12_dump_t *)wdh->priv;
|
2007-03-10 02:04:57 +00:00
|
|
|
union {
|
|
|
|
guint8 b[sizeof(guint32)];
|
|
|
|
guint32 u;
|
|
|
|
} d;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if (! wtap_dump_file_write(wdh, k12_eof, 2, err))
|
2007-09-28 17:22:03 +00:00
|
|
|
return FALSE;
|
2014-10-11 20:10:14 +00:00
|
|
|
k12->file_len += 2;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-10-11 20:10:14 +00:00
|
|
|
if (wtap_dump_file_seek(wdh, K12_FILE_HDR_FILE_SIZE, SEEK_SET, err) == -1)
|
2007-03-10 02:04:57 +00:00
|
|
|
return FALSE;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2010-02-26 07:59:54 +00:00
|
|
|
d.u = g_htonl(k12->file_len);
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if (! wtap_dump_file_write(wdh, d.b, 4, err))
|
2007-09-28 17:22:03 +00:00
|
|
|
return FALSE;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-10-11 20:10:14 +00:00
|
|
|
if (wtap_dump_file_seek(wdh, K12_FILE_HDR_PAGE_SIZE, SEEK_SET, err) == -1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
d.u = g_htonl(8192);
|
|
|
|
|
|
|
|
if (! wtap_dump_file_write(wdh, d.b, 4, err))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (wtap_dump_file_seek(wdh, K12_FILE_HDR_RECORD_COUNT_1, SEEK_SET, err) == -1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
d.u = g_htonl(k12->num_of_records);
|
|
|
|
|
|
|
|
if (! wtap_dump_file_write(wdh, d.b, 4, err))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (wtap_dump_file_seek(wdh, K12_FILE_HDR_RECORD_COUNT_2, SEEK_SET, err) == -1)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-02-26 07:59:54 +00:00
|
|
|
d.u = g_htonl(k12->num_of_records);
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if (! wtap_dump_file_write(wdh, d.b, 4, err))
|
2007-09-28 17:22:03 +00:00
|
|
|
return FALSE;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
return TRUE;
|
2005-06-17 17:26:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
gboolean k12_dump_open(wtap_dumper *wdh, int *err) {
|
2010-02-26 07:59:54 +00:00
|
|
|
k12_dump_t *k12;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if ( ! wtap_dump_file_write(wdh, k12_file_magic, 8, err)) {
|
2007-03-10 02:04:57 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2014-10-05 05:18:27 +00:00
|
|
|
if (wtap_dump_file_seek(wdh, K12_FILE_HDR_LEN, SEEK_SET, err) == -1)
|
2007-03-10 02:04:57 +00:00
|
|
|
return FALSE;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
wdh->subtype_write = k12_dump;
|
|
|
|
wdh->subtype_close = k12_dump_close;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2010-02-26 07:59:54 +00:00
|
|
|
k12 = (k12_dump_t *)g_malloc(sizeof(k12_dump_t));
|
|
|
|
wdh->priv = (void *)k12;
|
2014-10-05 05:18:27 +00:00
|
|
|
k12->file_len = K12_FILE_HDR_LEN;
|
2010-02-26 07:59:54 +00:00
|
|
|
k12->num_of_records = 0;
|
2014-10-05 05:18:27 +00:00
|
|
|
k12->file_offset = K12_FILE_HDR_LEN;
|
2007-10-16 15:43:18 +00:00
|
|
|
|
2007-03-10 02:04:57 +00:00
|
|
|
return TRUE;
|
2005-06-17 17:26:43 +00:00
|
|
|
}
|
2015-01-02 00:45:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|