Move the new files to the same places as in automake.
[obnox/wireshark/wip.git] / wiretap / cosine.c
index 7ffeca88a827acd5127de3e3b6955a2e4080dca9..083ce596b7939754fb6ee5338af3010066791293 100644 (file)
@@ -3,7 +3,7 @@
  * $Id$
  *
  * CoSine IPNOS L2 debug output parsing
- * Copyright (c) 2002 by Motonori Shindo <mshindo@mshindo.net>
+ * Copyright (c) 2002 by Motonori Shindo <motonori@shin.do>
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
 #define COSINE_MAX_PACKET_LEN  65536
 
 static gboolean empty_line(const gchar *line);
-static gint64 cosine_seek_next_packet(wtap *wth, int *err, char *hdr);
-static gboolean cosine_check_file_type(wtap *wth, int *err);
+static gint64 cosine_seek_next_packet(wtap *wth, int *err, gchar **err_info,
+       char *hdr);
+static gboolean cosine_check_file_type(wtap *wth, int *err, gchar **err_info);
 static gboolean cosine_read(wtap *wth, int *err, gchar **err_info,
        gint64 *data_offset);
 static gboolean cosine_seek_read(wtap *wth, gint64 seek_off,
@@ -201,8 +202,10 @@ static gboolean empty_line(const gchar *line)
 
 /* Seeks to the beginning of the next packet, and returns the
    byte offset. Copy the header line to hdr. Returns -1 on failure,
-   and sets "*err" to the error and set hdr as NULL. */
-static gint64 cosine_seek_next_packet(wtap *wth, int *err, char *hdr)
+   and sets "*err" to the error, sets "*err_info" to null or an
+   additional error string, and sets hdr to NULL. */
+static gint64 cosine_seek_next_packet(wtap *wth, int *err, gchar **err_info,
+       char *hdr)
 {
        gint64 cur_off;
        char buf[COSINE_LINE_LENGTH];
@@ -211,7 +214,7 @@ static gint64 cosine_seek_next_packet(wtap *wth, int *err, char *hdr)
                cur_off = file_tell(wth->fh);
                if (cur_off == -1) {
                        /* Error */
-                       *err = file_error(wth->fh);
+                       *err = file_error(wth->fh, err_info);
                        hdr = NULL;
                        return -1;
                }
@@ -227,7 +230,7 @@ static gint64 cosine_seek_next_packet(wtap *wth, int *err, char *hdr)
                                *err = 0;
                        } else {
                                /* We got an error. */
-                               *err = file_error(wth->fh);
+                               *err = file_error(wth->fh, err_info);
                        }
                        break;
                }
@@ -240,9 +243,10 @@ static gint64 cosine_seek_next_packet(wtap *wth, int *err, char *hdr)
  * a CoSine L2 debug output.
  *
  * Returns TRUE if it is, FALSE if it isn't or if we get an I/O error;
- * if we get an I/O error, "*err" will be set to a non-zero value.
+ * if we get an I/O error, "*err" will be set to a non-zero value and
+ * "*err_info" will be set to null or an additional error string.
  */
-static gboolean cosine_check_file_type(wtap *wth, int *err)
+static gboolean cosine_check_file_type(wtap *wth, int *err, gchar **err_info)
 {
        char    buf[COSINE_LINE_LENGTH];
        gsize   reclen;
@@ -268,7 +272,7 @@ static gboolean cosine_check_file_type(wtap *wth, int *err)
                        if (file_eof(wth->fh))
                                *err = 0;
                        else
-                               *err = file_error(wth->fh);
+                               *err = file_error(wth->fh, err_info);
                        return FALSE;
                }
        }
@@ -277,10 +281,10 @@ static gboolean cosine_check_file_type(wtap *wth, int *err)
 }
 
 
-int cosine_open(wtap *wth, int *err, gchar **err_info _U_)
+int cosine_open(wtap *wth, int *err, gchar **err_info)
 {
        /* Look for CoSine header */
-       if (!cosine_check_file_type(wth, err)) {
+       if (!cosine_check_file_type(wth, err, err_info)) {
                if (*err == 0)
                        return 0;
                else
@@ -311,7 +315,7 @@ static gboolean cosine_read(wtap *wth, int *err, gchar **err_info,
        char    line[COSINE_LINE_LENGTH];
 
        /* Find the next packet */
-       offset = cosine_seek_next_packet(wth, err, line);
+       offset = cosine_seek_next_packet(wth, err, err_info, line);
        if (offset < 0)
                return FALSE;
 
@@ -331,6 +335,7 @@ static gboolean cosine_read(wtap *wth, int *err, gchar **err_info,
                return FALSE;
 
        wth->data_offset = offset;
+       wth->phdr.presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
        wth->phdr.caplen = caplen;
        *data_offset = offset;
        return TRUE;
@@ -348,7 +353,7 @@ cosine_seek_read (wtap *wth, gint64 seek_off,
                return FALSE;
 
        if (file_gets(line, COSINE_LINE_LENGTH, wth->random_fh) == NULL) {
-               *err = file_error(wth->random_fh);
+               *err = file_error(wth->random_fh, err_info);
                if (*err == 0) {
                        *err = WTAP_ERR_SHORT_READ;
                }
@@ -388,7 +393,7 @@ parse_cosine_rec_hdr(wtap *wth, const char *line,
                                   &code1, &code2);
 
                if (num_items_scanned != 17) {
-                       *err = WTAP_ERR_BAD_RECORD;
+                       *err = WTAP_ERR_BAD_FILE;
                        *err_info = g_strdup("cosine: purported control blade line doesn't have code values");
                        return -1;
                }
@@ -401,7 +406,7 @@ parse_cosine_rec_hdr(wtap *wth, const char *line,
                                   &code1, &code2);
 
                if (num_items_scanned != 10) {
-                       *err = WTAP_ERR_BAD_RECORD;
+                       *err = WTAP_ERR_BAD_FILE;
                        *err_info = g_strdup("cosine: header line is neither control blade nor PE output");
                        return -1;
                }
@@ -472,7 +477,7 @@ parse_cosine_hex_dump(FILE_T fh, int pkt_len, guint8* buf, int *err,
 
        for (i = 0; i < hex_lines; i++) {
                if (file_gets(line, COSINE_LINE_LENGTH, fh) == NULL) {
-                       *err = file_error(fh);
+                       *err = file_error(fh, err_info);
                        if (*err == 0) {
                                *err = WTAP_ERR_SHORT_READ;
                        }
@@ -482,7 +487,7 @@ parse_cosine_hex_dump(FILE_T fh, int pkt_len, guint8* buf, int *err,
                        break;
                }
                if ((n = parse_single_hex_dump_line(line, buf, i*16)) == -1) {
-                       *err = WTAP_ERR_BAD_RECORD;
+                       *err = WTAP_ERR_BAD_FILE;
                        *err_info = g_strdup("cosine: hex dump line doesn't have 16 numbers");
                        return -1;
                }