/* toshiba.c
*
- * $Id: toshiba.c,v 1.28 2004/01/05 17:33:28 ulfl Exp $
+ * $Id$
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
*/
#define TOSHIBA_MAX_PACKET_LEN 16384
-static gboolean toshiba_read(wtap *wth, int *err, long *data_offset);
-static gboolean toshiba_seek_read(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err);
+static gboolean toshiba_read(wtap *wth, int *err, gchar **err_info,
+ gint64 *data_offset);
+static gboolean toshiba_seek_read(wtap *wth, gint64 seek_off,
+ union wtap_pseudo_header *pseudo_header, guint8 *pd, int len,
+ int *err, gchar **err_info);
static gboolean parse_single_hex_dump_line(char* rec, guint8 *buf,
guint byte_offset);
static gboolean parse_toshiba_hex_dump(FILE_T fh, int pkt_len, guint8* buf,
- int *err);
+ int *err, gchar **err_info);
static int parse_toshiba_rec_hdr(wtap *wth, FILE_T fh,
- union wtap_pseudo_header *pseudo_header, int *err);
+ union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info);
/* Seeks to the beginning of the next packet, and returns the
byte offset. Returns -1 on failure, and sets "*err" to the error. */
-static long toshiba_seek_next_packet(wtap *wth, int *err)
+static gint64 toshiba_seek_next_packet(wtap *wth, int *err)
{
int byte;
guint level = 0;
- long cur_off;
+ gint64 cur_off;
while ((byte = file_getc(wth->fh)) != EOF) {
if (byte == toshiba_rec_magic[level]) {
}
-int toshiba_open(wtap *wth, int *err)
+int toshiba_open(wtap *wth, int *err, gchar **err_info _U_)
{
/* Look for Toshiba header */
if (!toshiba_check_file_type(wth, err)) {
wth->snapshot_length = 0; /* not known */
wth->subtype_read = toshiba_read;
wth->subtype_seek_read = toshiba_seek_read;
+ wth->tsprecision = WTAP_FILE_TSPREC_CSEC;
return 1;
}
-/* Find the next packet and parse it; called from wtap_loop(). */
-static gboolean toshiba_read(wtap *wth, int *err, long *data_offset)
+/* Find the next packet and parse it; called from wtap_read(). */
+static gboolean toshiba_read(wtap *wth, int *err, gchar **err_info,
+ gint64 *data_offset)
{
- long offset;
+ gint64 offset;
guint8 *buf;
int pkt_len;
return FALSE;
/* Parse the header */
- pkt_len = parse_toshiba_rec_hdr(wth, wth->fh, &wth->pseudo_header, err);
+ pkt_len = parse_toshiba_rec_hdr(wth, wth->fh, &wth->pseudo_header,
+ err, err_info);
if (pkt_len == -1)
return FALSE;
buf = buffer_start_ptr(wth->frame_buffer);
/* Convert the ASCII hex dump to binary data */
- if (!parse_toshiba_hex_dump(wth->fh, pkt_len, buf, err))
+ if (!parse_toshiba_hex_dump(wth->fh, pkt_len, buf, err, err_info))
return FALSE;
wth->data_offset = offset;
/* Used to read packets in random-access fashion */
static gboolean
-toshiba_seek_read (wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err)
+toshiba_seek_read (wtap *wth, gint64 seek_off,
+ union wtap_pseudo_header *pseudo_header, guint8 *pd, int len,
+ int *err, gchar **err_info)
{
int pkt_len;
return FALSE;
pkt_len = parse_toshiba_rec_hdr(NULL, wth->random_fh, pseudo_header,
- err);
+ err, err_info);
if (pkt_len != len) {
- if (pkt_len != -1)
+ if (pkt_len != -1) {
*err = WTAP_ERR_BAD_RECORD;
+ *err_info = g_strdup_printf("toshiba: requested length %d doesn't match record length %d",
+ len, pkt_len);
+ }
return FALSE;
}
- return parse_toshiba_hex_dump(wth->random_fh, pkt_len, pd, err);
+ return parse_toshiba_hex_dump(wth->random_fh, pkt_len, pd, err, err_info);
}
/* Parses a packet record header. */
static int
parse_toshiba_rec_hdr(wtap *wth, FILE_T fh,
- union wtap_pseudo_header *pseudo_header, int *err)
+ union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
{
char line[TOSHIBA_LINE_LENGTH];
int num_items_scanned;
if (num_items_scanned != 7) {
*err = WTAP_ERR_BAD_RECORD;
+ *err_info = g_strdup("toshiba: record header isn't valid");
return -1;
}
num_items_scanned = sscanf(line+64, "LEN=%d", &pkt_len);
if (num_items_scanned != 1) {
*err = WTAP_ERR_BAD_RECORD;
+ *err_info = g_strdup("toshiba: OFFSET line doesn't have valid LEN item");
return -1;
}
if (wth) {
- wth->phdr.ts.tv_sec = hr * 3600 + min * 60 + sec;
- wth->phdr.ts.tv_usec = csec * 10000;
+ wth->phdr.ts.secs = hr * 3600 + min * 60 + sec;
+ wth->phdr.ts.nsecs = csec * 10000000;
wth->phdr.caplen = pkt_len;
wth->phdr.len = pkt_len;
}
/* Converts ASCII hex dump to binary data */
static gboolean
-parse_toshiba_hex_dump(FILE_T fh, int pkt_len, guint8* buf, int *err)
+parse_toshiba_hex_dump(FILE_T fh, int pkt_len, guint8* buf, int *err,
+ gchar **err_info)
{
char line[TOSHIBA_LINE_LENGTH];
int i, hex_lines;
}
if (!parse_single_hex_dump_line(line, buf, i * 16)) {
*err = WTAP_ERR_BAD_RECORD;
+ *err_info = g_strdup("toshiba: hex dump not valid");
return FALSE;
}
}