aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/cosine.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2004-01-25 21:55:17 +0000
committerGuy Harris <guy@alum.mit.edu>2004-01-25 21:55:17 +0000
commitd6cd61061efe7207b298b5ac40a92e7b86b00b3e (patch)
tree392720e018248f9cf2b46db00a4a9740ff7d1fca /wiretap/cosine.c
parent34bddb3c1a932632fd0515f7999ed96ef9974611 (diff)
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with "g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed strings returned as the error info string, and change the callers of those routines to, for those errors, put the info string into the printed message or alert box for the error. Add messages for cases where those errors were returned without printing an additional message. Nobody uses the error code from "cf_read()" - "cf_read()" puts up the alert box itself for failures; get rid of the error code, so it just returns a success/failure indication. Rename "file_read_error_message()" to "cf_read_error_message()", as it handles read errors from Wiretap, and have it take an error info string as an argument. (That handles a lot of the work of putting the info string into the error message.) Make some variables in "ascend-grammar.y" static. Check the return value of "erf_read_header()" in "erf_seek_read()". Get rid of an unused #define in "i4btrace.c". svn path=/trunk/; revision=9852
Diffstat (limited to 'wiretap/cosine.c')
-rw-r--r--wiretap/cosine.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/wiretap/cosine.c b/wiretap/cosine.c
index 3eeddbd250..4c0e541db4 100644
--- a/wiretap/cosine.c
+++ b/wiretap/cosine.c
@@ -1,6 +1,6 @@
/* cosine.c
*
- * $Id: cosine.c,v 1.7 2004/01/24 16:48:12 jmayer Exp $
+ * $Id: cosine.c,v 1.8 2004/01/25 21:55:12 guy Exp $
*
* CoSine IPNOS L2 debug output parsing
* Copyright (c) 2002 by Motonori Shindo <mshindo@mshindo.net>
@@ -169,14 +169,15 @@
static gboolean empty_line(const gchar *line);
static long cosine_seek_next_packet(wtap *wth, int *err, char *hdr);
static gboolean cosine_check_file_type(wtap *wth, int *err);
-static gboolean cosine_read(wtap *wth, int *err, long *data_offset);
+static gboolean cosine_read(wtap *wth, int *err, gchar **err_info,
+ long *data_offset);
static gboolean cosine_seek_read(wtap *wth, long seek_off,
union wtap_pseudo_header *pseudo_header, guint8 *pd,
- int len, int *err);
+ int len, int *err, gchar **err_info);
static int parse_cosine_rec_hdr(wtap *wth, const char *line,
- union wtap_pseudo_header *pseudo_header, int *err);
+ union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info);
static int parse_cosine_hex_dump(FILE_T fh, int pkt_len, guint8* buf,
- int *err);
+ int *err, gchar **err_info);
static int parse_single_hex_dump_line(char* rec, guint8 *buf,
guint byte_offset);
@@ -279,7 +280,7 @@ static gboolean cosine_check_file_type(wtap *wth, int *err)
}
-int cosine_open(wtap *wth, int *err)
+int cosine_open(wtap *wth, int *err, gchar **err_info _U_)
{
/* Look for CoSine header */
if (!cosine_check_file_type(wth, err)) {
@@ -303,7 +304,8 @@ int cosine_open(wtap *wth, int *err)
}
/* Find the next packet and parse it; called from wtap_loop(). */
-static gboolean cosine_read(wtap *wth, int *err, long *data_offset)
+static gboolean cosine_read(wtap *wth, int *err, gchar **err_info,
+ long *data_offset)
{
long offset;
guint8 *buf;
@@ -316,7 +318,8 @@ static gboolean cosine_read(wtap *wth, int *err, long *data_offset)
return FALSE;
/* Parse the header */
- pkt_len = parse_cosine_rec_hdr(wth, line, &wth->pseudo_header, err);
+ pkt_len = parse_cosine_rec_hdr(wth, line, &wth->pseudo_header, err,
+ err_info);
if (pkt_len == -1)
return FALSE;
@@ -325,7 +328,8 @@ static gboolean cosine_read(wtap *wth, int *err, long *data_offset)
buf = buffer_start_ptr(wth->frame_buffer);
/* Convert the ASCII hex dump to binary data */
- if ((caplen = parse_cosine_hex_dump(wth->fh, pkt_len, buf, err)) == -1)
+ if ((caplen = parse_cosine_hex_dump(wth->fh, pkt_len, buf, err,
+ err_info)) == -1)
return FALSE;
wth->data_offset = offset;
@@ -337,7 +341,8 @@ static gboolean cosine_read(wtap *wth, int *err, long *data_offset)
/* Used to read packets in random-access fashion */
static gboolean
cosine_seek_read (wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err)
+ union wtap_pseudo_header *pseudo_header, guint8 *pd, int len,
+ int *err, gchar **err_info)
{
char line[COSINE_LINE_LENGTH];
@@ -352,10 +357,10 @@ cosine_seek_read (wtap *wth, long seek_off,
return FALSE;
}
- if (parse_cosine_rec_hdr(NULL, line, pseudo_header, err) == -1)
+ if (parse_cosine_rec_hdr(NULL, line, pseudo_header, err, err_info) == -1)
return FALSE;
- return parse_cosine_hex_dump(wth->random_fh, len, pd, err);
+ return parse_cosine_hex_dump(wth->random_fh, len, pd, err, err_info);
}
/* Parses a packet record header. There are two possible formats:
@@ -364,7 +369,8 @@ cosine_seek_read (wtap *wth, long seek_off,
2) output to PE without date and time
l2-tx (FR:3/7/1:1), Length:18, Pro:0, Off:0, Pri:0, RM:0, Err:0 [0x4000, 0x0] */
static int
-parse_cosine_rec_hdr(wtap *wth, const char *line, union wtap_pseudo_header *pseudo_header, int *err)
+parse_cosine_rec_hdr(wtap *wth, const char *line,
+ union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
{
int num_items_scanned;
int yy, mm, dd, hr, min, sec, csec, pkt_len;
@@ -385,6 +391,7 @@ parse_cosine_rec_hdr(wtap *wth, const char *line, union wtap_pseudo_header *pseu
if (num_items_scanned != 17) {
*err = WTAP_ERR_BAD_RECORD;
+ *err_info = g_strdup("cosine: purported control blade line doesn't have code values");
return -1;
}
} else {
@@ -397,6 +404,7 @@ parse_cosine_rec_hdr(wtap *wth, const char *line, union wtap_pseudo_header *pseu
if (num_items_scanned != 10) {
*err = WTAP_ERR_BAD_RECORD;
+ *err_info = g_strdup("cosine: header line is neither control blade nor PE output");
return -1;
}
yy = mm = dd = hr = min = sec = csec = 0;
@@ -455,7 +463,8 @@ parse_cosine_rec_hdr(wtap *wth, const char *line, union wtap_pseudo_header *pseu
/* Converts ASCII hex dump to binary data. Returns the capture length.
If any error is encountered, -1 is returned. */
static int
-parse_cosine_hex_dump(FILE_T fh, int pkt_len, guint8* buf, int *err)
+parse_cosine_hex_dump(FILE_T fh, int pkt_len, guint8* buf, int *err,
+ gchar **err_info)
{
gchar line[COSINE_LINE_LENGTH];
int i, hex_lines, n, caplen = 0;
@@ -477,6 +486,7 @@ parse_cosine_hex_dump(FILE_T fh, int pkt_len, guint8* buf, int *err)
}
if ((n = parse_single_hex_dump_line(line, buf, i*16)) == -1) {
*err = WTAP_ERR_BAD_RECORD;
+ *err_info = g_strdup("cosine: hex dump line doesn't have 16 numbers");
return -1;
}
caplen += n;