Remove the (long deprecated) proto_tree_add_*_hidden() functions
[obnox/wireshark/wip.git] / wiretap / toshiba.c
index 68370ecaa6e2da0094c95e66980429bd2a915254..a6d67900fef4419eabad29cbced6eca9a70b783e 100644 (file)
@@ -1,6 +1,6 @@
 /* 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>
@@ -109,23 +109,25 @@ static const char toshiba_rec_magic[]  = { '[', 'N', 'o', '.' };
  */
 #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]) {
@@ -208,7 +210,7 @@ static gboolean toshiba_check_file_type(wtap *wth, int *err)
 }
 
 
-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)) {
@@ -224,14 +226,16 @@ int toshiba_open(wtap *wth, int *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;
 
@@ -241,7 +245,8 @@ static gboolean toshiba_read(wtap *wth, int *err, long *data_offset)
                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;
 
@@ -250,7 +255,7 @@ static gboolean toshiba_read(wtap *wth, int *err, long *data_offset)
        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;
@@ -260,8 +265,9 @@ static gboolean toshiba_read(wtap *wth, int *err, long *data_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;
 
@@ -269,21 +275,24 @@ toshiba_seek_read (wtap *wth, long seek_off,
                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;
@@ -310,6 +319,7 @@ parse_toshiba_rec_hdr(wtap *wth, FILE_T fh,
 
        if (num_items_scanned != 7) {
                *err = WTAP_ERR_BAD_RECORD;
+               *err_info = g_strdup("toshiba: record header isn't valid");
                return -1;
        }
 
@@ -339,12 +349,13 @@ parse_toshiba_rec_hdr(wtap *wth, FILE_T fh,
        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;
        }
@@ -376,7 +387,8 @@ parse_toshiba_rec_hdr(wtap *wth, FILE_T fh,
 
 /* 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;
@@ -395,6 +407,7 @@ parse_toshiba_hex_dump(FILE_T fh, int pkt_len, guint8* buf, int *err)
                }
                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;
                }
        }