* $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,
/* 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];
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;
}
*err = 0;
} else {
/* We got an error. */
- *err = file_error(wth->fh);
+ *err = file_error(wth->fh, err_info);
}
break;
}
* 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;
if (file_eof(wth->fh))
*err = 0;
else
- *err = file_error(wth->fh);
+ *err = file_error(wth->fh, err_info);
return FALSE;
}
}
}
-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
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;
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;
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;
}
&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;
}
&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;
}
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;
}
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;
}