#include <errno.h>
#include "wtap-int.h"
-#include "wtap.h"
#include "file_wrappers.h"
-#include <wsutil/buffer.h>
#include "k12.h"
#include <wsutil/str_util.h>
/* #define DEBUG_K12 */
#ifdef DEBUG_K12
#include <stdio.h>
-#include <ctype.h>
#include <stdarg.h>
#include <wsutil/file_util.h>
#define CAT(a,b) a##b
#define K12_DBG(level,args) do { if (level <= debug_level) { \
- fprintf(dbg_out,"%s:%d: ",CAT(__FI,LE__),CAT(__LI,NE__)); \
- k12_fprintf args ; \
- fprintf(dbg_out,"\n"); \
+ fprintf(dbg_out,"%s:%d: ",CAT(__FI,LE__),CAT(__LI,NE__)); \
+ k12_fprintf args ; \
+ fprintf(dbg_out,"\n"); \
} } while(0)
void k12_hex_ascii_dump(guint level, gint64 offset, const char* label, const unsigned char* b, unsigned int len) {
/*
- * A 32-bit .rf5 file contains:
+ * A 32-bit .rf5 file begins with a 512-byte file header, containing:
*
- * a 32-bit big-endian file header length (0x0200 = 512);
+ * a 32-bit big-endian file header length, in bytes - always 512 in
+ * the files we've seen;
*
* 4 unknown bytes, always 0x12 0x05 0x00 0x10;
*
* a 32-bit big-endian file length, giving the total length of the file,
* in bytes;
*
- * a 32-bit big-endian number of records;
+ * a 32-bit big-endian number giving the "page size" of the file, in
+ * bytes, which is normally 8192;
*
- * 496 bytes of uncharted territory;
+ * 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;
*
* followed by a sequence of records containing:
*
* in memory as the file was being written.
*
* There's a 16-bit terminator FFFF at the end.
+ *
+ * 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.
*/
/*
static const guint8 k12_file_magic[] = { 0x00, 0x00, 0x02, 0x00 ,0x12, 0x05, 0x00, 0x10 };
#define K12_FILE_HDR_LEN 512
+
+/*
+ * 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
+
#define K12_FILE_BLOB_LEN 16
typedef struct {
* with the "group" code followe by the "type" code. The "group" values
* are:
*
- * 0x0001 - "data event"
- * 0x0002 - "text or L1 event"
- * 0x0007 - "configuration event"
+ * 0x0001 - "data event"
+ * 0x0002 - "text or L1 event"
+ * 0x0007 - "configuration event"
*
* and the "type" values are:
*
* data events:
- * 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"
+ * 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"
*
* text or L1 events:
- * 0x0030 - "text event"
- * 0x0031 - "L1 event"
- * 0x0032 - "L1 event (BAI)"
- * 0x0033 - "L1 event (VX)"
+ * 0x0030 - "text event"
+ * 0x0031 - "L1 event"
+ * 0x0032 - "L1 event (BAI)"
+ * 0x0033 - "L1 event (VX)"
*
* configuration events:
- * 0x0040 - Logical Data Source configuration event
- * 0x0041 - Logical Link configuration event
+ * 0x0040 - Logical Data Source configuration event
+ * 0x0041 - Logical Link configuration event
*/
/* so far we've seen these types of records */
#define K12_REC_PACKET 0x00010020 /* an actual packet */
#define K12_SRCDESC_COLOR_FOREGROUND 0x12 /* 1 byte */
#define K12_SRCDESC_COLOR_BACKGROUND 0x13 /* 1 byte */
-#define K12_SRCDESC_PORT_TYPE 0x1a /* 1 byte */
-#define K12_SRCDESC_EXTRALEN 0x1e /* uint16, big endian */
-#define K12_SRCDESC_NAMELEN 0x20 /* uint16, big endian */
-#define K12_SRCDESC_STACKLEN 0x22 /* uint16, big endian */
+#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 */
+
+/* Hardware part of the record */
+#define K12_SRCDESC_HWPART 0x24 /* offset of the hardware part */
-#define K12_SRCDESC_EXTRATYPE 0x24 /* uint32, big endian */
+/* Offsets relative to the beginning of the hardware part */
+#define K12_SRCDESC_HWPARTTYPE 0 /* uint32, big endian */
-#define K12_SRCDESC_ATM_VPI 0x38 /* uint16, big endian */
-#define K12_SRCDESC_ATM_VCI 0x3a /* uint16, big endian */
-#define K12_SRCDESC_ATM_AAL 0x3c /* 1 byte */
+#define K12_SRCDESC_DS0_MASK 24 /* variable-length */
-#define K12_SRCDESC_DS0_MASK 0x3c /* 32 bytes */
+#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 */
/*
* A "stack file", as appears in a K12_REC_STK_FILE record, is a text
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;
guint total_read = 0;
- guint bytes_read;
guint left;
- guint8 junk[K12_FILE_BLOB_LEN+4];
guint8* writep;
#ifdef DEBUG_K12
guint actual_len;
* We're at the beginning of one of the 16-byte blobs,
* so we first need to skip the blob.
*
- * Or we may just have the 2-byte FFFF marker.
- * XXX - would the FFFF marker ever be in the 16-byte blob?
- *
* 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.
*/
- bytes_read = file_read(junk,K12_FILE_BLOB_LEN,fh);
- if (bytes_read == 2 && junk[0] == 0xff && junk[1] == 0xff) {
- K12_DBG(1,("get_record: EOF"));
- return 0;
- } else if ( bytes_read < K12_FILE_BLOB_LEN ){
- K12_DBG(1,("get_record: SHORT READ OR ERROR"));
- *err = file_error(fh, err_info);
- if (*err == 0) {
- *err = WTAP_ERR_SHORT_READ;
- }
+ if ( ! file_skip( fh, K12_FILE_BLOB_LEN, err ) )
return -1;
- }
- total_read += bytes_read;
+ total_read += K12_FILE_BLOB_LEN;
}
/*
* Read the record length.
*/
- bytes_read = file_read(buffer,4,fh);
- if (bytes_read == 2 && buffer[0] == 0xff && buffer[1] == 0xff) {
- K12_DBG(1,("get_record: EOF"));
- return 0;
- } else if (bytes_read == 4 && buffer[0] == 0xff && buffer[1] == 0xff
- && buffer[2] == 0x00 && buffer[3] == 0x00) {
- /*
- * In at least one k18 RF5 file, there appears to be a "record"
- * with a length value of 0xffff0000, followed by a bunch of
- * data that doesn't appear to be records, including a long
- * list of numbers.
- *
- * We treat a length value of 0xffff0000 as an end-of-file
- * indication.
- *
- * XXX - is this a length indication, or will it appear
- * at the beginning of an 8KB block, so that we should
- * check for it above?
- */
- K12_DBG(1,("get_record: EOF"));
- return 0;
- } else if ( bytes_read != 4 ) {
- K12_DBG(1,("get_record: SHORT READ OR ERROR"));
- *err = file_error(fh, err_info);
- if (*err == 0) {
- *err = WTAP_ERR_SHORT_READ;
- }
+ if ( !wtap_read_bytes( fh, buffer, 4, err, err_info ) )
return -1;
- }
- total_read += bytes_read;
+ total_read += 4;
left = pntoh32(buffer + K12_RECORD_LEN);
#ifdef DEBUG_K12
* The next 16-byte blob is past the end of this record.
* Just read the rest of the record.
*/
- bytes_read = file_read(writep, left, fh);
- if ( bytes_read != left ) {
- K12_DBG(1,("get_record: SHORT READ OR ERROR"));
- *err = file_error(fh, err_info);
- if (*err == 0) {
- *err = WTAP_ERR_SHORT_READ;
- }
+ if ( !wtap_read_bytes( fh, writep, left, err, err_info ) )
return -1;
- }
- total_read += bytes_read;
+ total_read += left;
break;
} else {
/*
* The next 16-byte blob is part of this record.
* Read up to the blob.
*/
- bytes_read = file_read(writep, junky_offset, fh);
- if ( bytes_read != junky_offset ) {
- K12_DBG(1,("get_record: SHORT READ OR ERROR, read=%d expected=%d",bytes_read, junky_offset));
- *err = file_error(fh, err_info);
- if (*err == 0) {
- *err = WTAP_ERR_SHORT_READ;
- }
+ if ( !wtap_read_bytes( fh, writep, junky_offset, err, err_info ) )
return -1;
- }
- total_read += bytes_read;
- writep += bytes_read;
+ total_read += junky_offset;
+ writep += junky_offset;
/*
* Skip the blob.
*/
- bytes_read = file_read(junk, K12_FILE_BLOB_LEN, fh);
- if ( bytes_read != K12_FILE_BLOB_LEN ) {
- K12_DBG(1,("get_record: SHORT READ OR ERROR"));
- *err = file_error(fh, err_info);
- if (*err == 0) {
- *err = WTAP_ERR_SHORT_READ;
- }
+ if ( !file_skip( fh, K12_FILE_BLOB_LEN, err ) )
return -1;
- }
- total_read += bytes_read;
+ total_read += K12_FILE_BLOB_LEN;
left -= junky_offset;
junky_offset = 8192;
return total_read;
}
+static gboolean
+memiszero(const void *ptr, size_t count)
+{
+ const guint8 *p = (const guint8 *)ptr;
+
+ while (count != 0) {
+ if (*p != 0)
+ return FALSE;
+ p++;
+ count--;
+ }
+ return TRUE;
+}
+
static void
process_packet_data(struct wtap_pkthdr *phdr, Buffer *target, guint8 *buffer,
gint len, k12_t *k12)
/* ignore the record if it isn't a packet */
do {
+ if ( k12->num_of_records == 0 ) {
+ /* No more records */
+ *err = 0;
+ return FALSE;
+ }
+
K12_DBG(5,("k12_read: offset=%i",offset));
*data_offset = offset;
return FALSE;
} else if (len == 0) {
/* EOF */
- *err = 0;
+ *err = WTAP_ERR_SHORT_READ;
return FALSE;
} else if (len < K12_RECORD_SRC_ID + 4) {
/* Record not large enough to contain a src ID */
*err_info = g_strdup_printf("data record length %d too short", len);
return FALSE;
}
+ k12->num_of_records--;
buffer = k12->seq_read_buff;
k12_t *k12 = (k12_t *)wth->priv;
destroy_k12_file_data(k12);
- wth->priv = NULL; /* destroy_k12_file_data freed it */
+ wth->priv = NULL; /* destroy_k12_file_data freed it */
#ifdef DEBUG_K12
K12_DBG(5,("k12_close: CLOSED"));
if (env_file) fclose(dbg_out);
}
-int k12_open(wtap *wth, int *err, gchar **err_info) {
+wtap_open_return_val k12_open(wtap *wth, int *err, gchar **err_info) {
k12_src_desc_t* rec;
guint8 header_buffer[K12_FILE_HDR_LEN];
guint8* read_buffer;
guint32 type;
long offset;
long len;
+ guint port_type;
guint32 rec_len;
- guint32 extra_len;
+ guint32 hwpart_len;
guint32 name_len;
guint32 stack_len;
guint i;
gchar* env_level = getenv("K12_DEBUG_LEVEL");
env_file = getenv("K12_DEBUG_FILENAME");
if ( env_file ) {
- 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"));
- }
+ 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"));
+ }
}
else
- dbg_out = stderr;
+ dbg_out = stderr;
if ( env_level ) debug_level = (unsigned int)strtoul(env_level,NULL,10);
K12_DBG(1,("k12_open: ENTER debug_level=%u",debug_level));
#endif
if ( !wtap_read_bytes(wth->fh,header_buffer,K12_FILE_HDR_LEN,err,err_info) ) {
K12_DBG(1,("k12_open: FILE HEADER TOO SHORT OR READ ERROR"));
- if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ if (*err != WTAP_ERR_SHORT_READ) {
+ return WTAP_OPEN_ERROR;
+ }
+ return WTAP_OPEN_NOT_MINE;
}
if ( memcmp(header_buffer,k12_file_magic,8) != 0 ) {
K12_DBG(1,("k12_open: BAD MAGIC"));
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
offset = K12_FILE_HDR_LEN;
file_data = new_k12_file_data();
file_data->file_len = pntoh32( header_buffer + 0x8);
- file_data->num_of_records = pntoh32( header_buffer + 0xC );
+ if (memiszero(header_buffer + 0x10, K12_FILE_HDR_LEN - 0x10)) {
+ /*
+ * The rest of the file header is all zeroes. That means
+ * this is a file written by the old Wireshark code, and
+ * a count of records in the file is at an offset of 0x0C.
+ */
+ 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;
+ }
+ }
K12_DBG(5,("k12_open: FILE_HEADER OK: offset=%x file_len=%i records=%i",
offset,
file_data->num_of_records ));
do {
+ if ( file_data->num_of_records == 0 ) {
+ *err = WTAP_ERR_SHORT_READ;
+ destroy_k12_file_data(file_data);
+ return WTAP_OPEN_ERROR;
+ }
len = get_record(file_data, wth->fh, offset, FALSE, err, err_info);
if ( len < 0 ) {
K12_DBG(1,("k12_open: BAD HEADER RECORD",len));
destroy_k12_file_data(file_data);
- return -1;
- }
- if (len == 0) {
- K12_DBG(1,("k12_open: BAD HEADER RECORD",len));
- *err = WTAP_ERR_SHORT_READ;
- destroy_k12_file_data(file_data);
- return -1;
+ return WTAP_OPEN_ERROR;
}
-
- if (len == 0) {
+ if ( len == 0 ) {
K12_DBG(1,("k12_open: BAD HEADER RECORD",len));
*err = WTAP_ERR_SHORT_READ;
destroy_k12_file_data(file_data);
- return -1;
+ return WTAP_OPEN_ERROR;
}
read_buffer = file_data->seq_read_buff;
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("k12_open: record length %u < %u",
rec_len, K12_RECORD_TYPE + 4);
- return -1;
+ return WTAP_OPEN_ERROR;
}
type = pntoh32( read_buffer + K12_RECORD_TYPE );
*/
if (file_seek(wth->fh, offset, SEEK_SET, err) == -1) {
destroy_k12_file_data(file_data);
- return -1;
+ return WTAP_OPEN_ERROR;
}
K12_DBG(5,("k12_open: FIRST PACKET offset=%x",offset));
break;
- } else if (type == K12_REC_SRCDSC || type == K12_REC_SRCDSC2 ) {
+ }
+
+ switch (type) {
+
+ case K12_REC_SRCDSC:
+ case K12_REC_SRCDSC2:
rec = g_new0(k12_src_desc_t,1);
- if (rec_len < K12_SRCDESC_STACKLEN + 2) {
- /* Record isn't long enough to have a stack length field */
+ if (rec_len < K12_SRCDESC_HWPART) {
+ /*
+ * Record isn't long enough to have the fixed-length portion
+ * of the source descriptor field.
+ */
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("k12_open: source descriptor record length %u < %u",
- rec_len, K12_SRCDESC_STACKLEN + 2);
- return -1;
+ rec_len, K12_SRCDESC_HWPART);
+ destroy_k12_file_data(file_data);
+ g_free(rec);
+ return WTAP_OPEN_ERROR;
}
- extra_len = pntoh16( read_buffer + K12_SRCDESC_EXTRALEN );
+ port_type = read_buffer[K12_SRCDESC_PORT_TYPE];
+ hwpart_len = pntoh16( read_buffer + K12_SRCDESC_HWPARTLEN );
name_len = pntoh16( read_buffer + K12_SRCDESC_NAMELEN );
stack_len = pntoh16( read_buffer + K12_SRCDESC_STACKLEN );
K12_DBG(5,("k12_open: INTERFACE RECORD offset=%x interface=%x",offset,rec->input));
- if (name_len == 0 || stack_len == 0
- || 0x20 + extra_len + name_len + stack_len > rec_len ) {
+ if (name_len == 0) {
+ K12_DBG(5,("k12_open: failed (name_len == 0 in source description"));
+ destroy_k12_file_data(file_data);
+ g_free(rec);
+ return WTAP_OPEN_NOT_MINE;
+ }
+ if (stack_len == 0) {
+ K12_DBG(5,("k12_open: failed (stack_len == 0 in source description"));
+ destroy_k12_file_data(file_data);
g_free(rec);
- K12_DBG(5,("k12_open: failed (name_len == 0 || stack_len == 0 "
- "|| 0x20 + extra_len + name_len + stack_len > rec_len) extra_len=%i name_len=%i stack_len=%i"));
+ return WTAP_OPEN_NOT_MINE;
+ }
+ 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);
- return 0;
+ g_free(rec);
+ return WTAP_OPEN_ERROR;
}
- if (extra_len) {
- if (rec_len < K12_SRCDESC_EXTRATYPE + 4) {
- /* Record isn't long enough to have a source descriptor extra type field */
+ if (hwpart_len) {
+ if (hwpart_len < 4) {
+ /* Hardware part isn't long enough to have a type field */
*err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("k12_open: source descriptor record length %u < %u",
- rec_len, K12_SRCDESC_EXTRATYPE + 4);
- return -1;
+ *err_info = g_strdup_printf("k12_open: source descriptor hardware part length %u < 4",
+ hwpart_len);
+ destroy_k12_file_data(file_data);
+ g_free(rec);
+ return WTAP_OPEN_ERROR;
}
- switch(( rec->input_type = pntoh32( read_buffer + K12_SRCDESC_EXTRATYPE ) )) {
+ switch(( rec->input_type = pntoh32( read_buffer + K12_SRCDESC_HWPART + K12_SRCDESC_HWPARTTYPE ) )) {
case K12_PORT_DS0S:
- if (rec_len < K12_SRCDESC_DS0_MASK + 32) {
- /* Record isn't long enough to have a source descriptor extra type field */
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("k12_open: source descriptor record length %u < %u",
- rec_len, K12_SRCDESC_DS0_MASK + 12);
- return -1;
- }
-
+ /* This appears to be variable-length */
rec->input_info.ds0mask = 0x00000000;
-
- for (i = 0; i < 32; i++) {
- rec->input_info.ds0mask |= ( *(read_buffer + K12_SRCDESC_DS0_MASK + i) == 0xff ) ? 0x1<<(31-i) : 0x0;
+ if (hwpart_len > K12_SRCDESC_DS0_MASK) {
+ for (i = 0; i < hwpart_len - K12_SRCDESC_DS0_MASK; i++) {
+ rec->input_info.ds0mask |= ( *(read_buffer + K12_SRCDESC_HWPART + K12_SRCDESC_DS0_MASK + i) == 0xff ) ? 1U<<(31-i) : 0x0;
+ }
}
-
break;
case K12_PORT_ATMPVC:
- if (rec_len < K12_SRCDESC_ATM_VCI + 2) {
- /* Record isn't long enough to have a source descriptor extra type field */
+ if (hwpart_len < K12_SRCDESC_ATM_VCI + 2) {
+ /* Hardware part isn't long enough to have ATM information */
*err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("k12_open: source descriptor record length %u < %u",
- rec_len, K12_SRCDESC_DS0_MASK + 12);
- return -1;
+ *err_info = g_strdup_printf("k12_open: source descriptor hardware part length %u < %u",
+ hwpart_len,
+ K12_SRCDESC_ATM_VCI + 2);
+ destroy_k12_file_data(file_data);
+ g_free(rec);
+ return WTAP_OPEN_ERROR;
}
- rec->input_info.atm.vp = pntoh16( read_buffer + K12_SRCDESC_ATM_VPI );
- rec->input_info.atm.vc = pntoh16( read_buffer + K12_SRCDESC_ATM_VCI );
+ 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 );
break;
default:
break;
}
} else {
/* Record viewer generated files don't have this information */
- if (rec_len < K12_SRCDESC_PORT_TYPE + 1) {
- /* Record isn't long enough to have a source descriptor extra type field */
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("k12_open: source descriptor record length %u < %u",
- rec_len, K12_SRCDESC_DS0_MASK + 12);
- return -1;
- }
- if (read_buffer[K12_SRCDESC_PORT_TYPE] >= 0x14
- && read_buffer[K12_SRCDESC_PORT_TYPE] <= 0x17) {
+ if (port_type >= 0x14
+ && port_type <= 0x17) {
/* For ATM2_E1DS1, ATM2_E3DS3,
ATM2_STM1EL and ATM2_STM1OP */
rec->input_type = K12_PORT_ATMPVC;
}
}
- /* XXX - this is assumed, in a number of places (not just in the
- ascii_strdown_inplace() call below) to be null-terminated;
- is that guaranteed (even with a corrupt file)?
- Obviously not, as a corrupt file could contain anything
- here; the Tektronix document says the strings "must end
- with \0", but a bad file could fail to add the \0. */
- if (rec_len < K12_SRCDESC_EXTRATYPE + extra_len + name_len + stack_len) {
- /* Record isn't long enough to have a source descriptor extra type field */
+ if (read_buffer[K12_SRCDESC_HWPART + hwpart_len + name_len - 1] != '\0') {
*err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("k12_open: source descriptor record length %u < %u",
- rec_len, K12_SRCDESC_EXTRATYPE + extra_len + name_len + stack_len);
- return -1;
+ *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;
}
- rec->input_name = (gchar *)g_memdup(read_buffer + K12_SRCDESC_EXTRATYPE + extra_len, name_len);
- rec->stack_file = (gchar *)g_memdup(read_buffer + K12_SRCDESC_EXTRATYPE + extra_len + name_len, stack_len);
+ 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);
ascii_strdown_inplace (rec->stack_file);
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);
+ break;
- offset += len;
- continue;
- } else if (type == K12_REC_STK_FILE) {
+ case K12_REC_STK_FILE:
K12_DBG(1,("k12_open: K12_REC_STK_FILE"));
K12_DBG(1,("Field 1: 0x%08x",pntoh32( read_buffer + 0x08 )));
K12_DBG(1,("Field 2: 0x%08x",pntoh32( read_buffer + 0x0c )));
K12_ASCII_DUMP(1, read_buffer, rec_len, 16);
+ break;
- offset += len;
- continue;
- } else {
+ default:
K12_DBG(1,("k12_open: RECORD TYPE 0x%08x",type));
- offset += len;
- continue;
+ break;
}
+ offset += len;
+ file_data->num_of_records--;
} while(1);
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_K12;
wth->priv = (void *)file_data;
wth->file_tsprec = WTAP_TSPREC_NSEC;
- return 1;
+ return WTAP_OPEN_MINE;
}
typedef struct {
- guint32 file_len;
- guint32 num_of_records;
- guint32 file_offset;
+ guint32 file_len;
+ guint32 num_of_records;
+ guint32 file_offset;
} k12_dump_t;
int k12_dump_can_write_encap(int encap) {
return WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED;
if (encap != WTAP_ENCAP_K12)
- return WTAP_ERR_UNSUPPORTED_ENCAP;
+ return WTAP_ERR_UNWRITABLE_ENCAP;
return 0;
}
return FALSE;
k12->file_offset += len + K12_FILE_BLOB_LEN;
+ k12->file_len += len + K12_FILE_BLOB_LEN;
} else {
if (! wtap_dump_file_write(wdh, buffer, len, err_p))
return FALSE;
k12->file_offset += len;
+ k12->file_len += len;
}
k12->num_of_records++;
guint32 unk32_3;
guint32 unk32_4;
guint16 unk16_1;
- guint16 extra_len;
+ guint16 hwpart_len;
guint16 name_len;
guint16 stack_len;
switch (src_desc->input_type) {
case K12_PORT_ATMPVC:
- obj.record.extra_len = g_htons(0x18);
+ obj.record.hwpart_len = g_htons(0x18);
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:
- obj.record.extra_len = g_htons(0x18);
+ obj.record.hwpart_len = g_htons(0x18);
for( i=0; i<32; i++ ) {
obj.record.extra.desc.ds0mask.mask[i] =
(src_desc->input_info.ds0mask & (1 << i)) ? 0xff : 0x00;
offset = 0x3c;
break;
default:
- obj.record.extra_len = g_htons(0x08);
+ obj.record.hwpart_len = g_htons(0x08);
offset = 0x2c;
break;
}
}
static gboolean k12_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
- const guint8 *pd, int *err) {
+ const guint8 *pd, int *err, gchar **err_info _U_) {
const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header;
k12_dump_t *k12 = (k12_dump_t *)wdh->priv;
guint32 len;
/* We can only write packet records. */
if (phdr->rec_type != REC_TYPE_PACKET) {
- *err = WTAP_ERR_REC_TYPE_UNSUPPORTED;
+ *err = WTAP_ERR_UNWRITABLE_REC_TYPE;
return FALSE;
}
static const guint8 k12_eof[] = {0xff,0xff};
-static gboolean k12_dump_close(wtap_dumper *wdh, int *err) {
+static gboolean k12_dump_finish(wtap_dumper *wdh, int *err) {
k12_dump_t *k12 = (k12_dump_t *)wdh->priv;
union {
guint8 b[sizeof(guint32)];
if (! wtap_dump_file_write(wdh, k12_eof, 2, err))
return FALSE;
+ k12->file_len += 2;
- if (wtap_dump_file_seek(wdh, 8, SEEK_SET, err) == -1)
+ if (wtap_dump_file_seek(wdh, K12_FILE_HDR_FILE_SIZE, SEEK_SET, err) == -1)
return FALSE;
d.u = g_htonl(k12->file_len);
if (! wtap_dump_file_write(wdh, d.b, 4, err))
return FALSE;
+ 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;
+
d.u = g_htonl(k12->num_of_records);
if (! wtap_dump_file_write(wdh, d.b, 4, err))
return FALSE;
wdh->subtype_write = k12_dump;
- wdh->subtype_close = k12_dump_close;
+ wdh->subtype_finish = k12_dump_finish;
k12 = (k12_dump_t *)g_malloc(sizeof(k12_dump_t));
wdh->priv = (void *)k12;
return TRUE;
}
+
+/*
+ * 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:
+ */