aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/ngsniffer.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/ngsniffer.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/ngsniffer.c')
-rw-r--r--wiretap/ngsniffer.c63
1 files changed, 33 insertions, 30 deletions
diff --git a/wiretap/ngsniffer.c b/wiretap/ngsniffer.c
index b0994cfcda..fcabc3f20e 100644
--- a/wiretap/ngsniffer.c
+++ b/wiretap/ngsniffer.c
@@ -1,6 +1,6 @@
/* ngsniffer.c
*
- * $Id: ngsniffer.c,v 1.112 2003/10/25 07:17:27 guy Exp $
+ * $Id: ngsniffer.c,v 1.113 2004/01/25 21:55:16 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
@@ -353,15 +353,17 @@ struct frame6_rec {
#define NUM_NGSNIFF_TIMEUNITS 7
static double Usec[] = { 15.0, 0.838096, 15.0, 0.5, 2.0, 1.0, 0.1 };
-static int process_header_records(wtap *wth, int *err, gint16 maj_vers);
+static int process_header_records(wtap *wth, int *err, gchar **err_info,
+ gint16 maj_vers);
static int process_rec_header2_v2(wtap *wth, unsigned char *buffer,
- guint16 length, int *err);
+ guint16 length, int *err, gchar **err_info);
static int process_rec_header2_v145(wtap *wth, unsigned char *buffer,
- guint16 length, gint16 maj_vers, int *err);
-static gboolean ngsniffer_read(wtap *wth, int *err, long *data_offset);
+ guint16 length, gint16 maj_vers, int *err, gchar **err_info);
+static gboolean ngsniffer_read(wtap *wth, int *err, gchar **err_info,
+ long *data_offset);
static gboolean ngsniffer_seek_read(wtap *wth, long seek_off,
union wtap_pseudo_header *pseudo_header, guchar *pd, int packet_size,
- int *err);
+ int *err, gchar **err_info);
static int ngsniffer_read_rec_header(wtap *wth, gboolean is_random,
guint16 *typep, guint16 *lengthp, int *err);
static gboolean ngsniffer_read_frame2(wtap *wth, gboolean is_random,
@@ -395,7 +397,7 @@ static int read_blob(FILE_T infile, ngsniffer_comp_stream_t *comp_stream,
static long ng_file_seek_seq(wtap *wth, long offset, int whence, int *err);
static long ng_file_seek_rand(wtap *wth, long offset, int whence, int *err);
-int ngsniffer_open(wtap *wth, int *err)
+int ngsniffer_open(wtap *wth, int *err, gchar **err_info)
{
int bytes_read;
char magic[sizeof ngsniffer_magic];
@@ -457,8 +459,8 @@ int ngsniffer_open(wtap *wth, int *err)
length = pletohs(record_length);
if (type != REC_VERS) {
- g_message("ngsniffer: Sniffer file doesn't start with a version record");
*err = WTAP_ERR_BAD_RECORD;
+ *err_info = g_strdup_printf("ngsniffer: Sniffer file doesn't start with a version record");
return -1;
}
@@ -475,16 +477,16 @@ int ngsniffer_open(wtap *wth, int *err)
/* Check the data link type. */
if (version.network >= NUM_NGSNIFF_ENCAPS
|| sniffer_encap[version.network] == WTAP_ENCAP_UNKNOWN) {
- g_message("ngsniffer: network type %u unknown or unsupported",
- version.network);
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
+ *err_info = g_strdup_printf("ngsniffer: network type %u unknown or unsupported",
+ version.network);
return -1;
}
/* Check the time unit */
if (version.timeunit >= NUM_NGSNIFF_TIMEUNITS) {
- g_message("ngsniffer: Unknown timeunit %u", version.timeunit);
*err = WTAP_ERR_UNSUPPORTED;
+ *err_info = g_strdup_printf("ngsniffer: Unknown timeunit %u", version.timeunit);
return -1;
}
@@ -515,7 +517,7 @@ int ngsniffer_open(wtap *wth, int *err)
* the DOS Sniffer understands?
*/
maj_vers = pletohs(&version.maj_vers);
- if (process_header_records(wth, err, maj_vers) < 0)
+ if (process_header_records(wth, err, err_info, maj_vers) < 0)
return -1;
if (wth->file_encap == WTAP_ENCAP_PER_PACKET) {
/*
@@ -630,7 +632,7 @@ int ngsniffer_open(wtap *wth, int *err)
}
static int
-process_header_records(wtap *wth, int *err, gint16 maj_vers)
+process_header_records(wtap *wth, int *err, gchar **err_info, gint16 maj_vers)
{
int bytes_read;
char record_type[2];
@@ -713,7 +715,7 @@ process_header_records(wtap *wth, int *err, gint16 maj_vers)
case 2:
if (process_rec_header2_v2(wth, buffer,
- length, err) < 0)
+ length, err, err_info) < 0)
return -1;
break;
@@ -721,7 +723,7 @@ process_header_records(wtap *wth, int *err, gint16 maj_vers)
case 4:
case 5:
if (process_rec_header2_v145(wth, buffer,
- length, maj_vers, err) < 0)
+ length, maj_vers, err, err_info) < 0)
return -1;
break;
}
@@ -745,7 +747,7 @@ process_header_records(wtap *wth, int *err, gint16 maj_vers)
static int
process_rec_header2_v2(wtap *wth, unsigned char *buffer, guint16 length,
- int *err)
+ int *err, gchar **err_info)
{
static const char x_25_str[] = "HDLC\nX.25\n";
@@ -760,20 +762,20 @@ process_rec_header2_v2(wtap *wth, unsigned char *buffer, guint16 length,
/*
* There's not enough data to compare.
*/
- g_message("ngsniffer: WAN capture has too-short protocol list");
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
+ *err_info = g_strdup_printf("ngsniffer: WAN capture has too-short protocol list");
return -1;
}
- if (strncmp(buffer, x_25_str, sizeof x_25_str - 1) == 0) {
+ if (strncmp((char *)buffer, x_25_str, sizeof x_25_str - 1) == 0) {
/*
* X.25.
*/
wth->file_encap = WTAP_ENCAP_LAPB;
} else {
- g_message("ngsniffer: WAN capture protocol string %.*s unknown",
- length, buffer);
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
+ *err_info = g_strdup_printf("ngsniffer: WAN capture protocol string %.*s unknown",
+ length, buffer);
return -1;
}
return 0;
@@ -781,7 +783,7 @@ process_rec_header2_v2(wtap *wth, unsigned char *buffer, guint16 length,
static int
process_rec_header2_v145(wtap *wth, unsigned char *buffer, guint16 length,
- gint16 maj_vers, int *err)
+ gint16 maj_vers, int *err, gchar **err_info)
{
/*
* The 5th byte of the REC_HEADER2 record appears to be a
@@ -791,8 +793,8 @@ process_rec_header2_v145(wtap *wth, unsigned char *buffer, guint16 length,
/*
* There is no 5th byte; give up.
*/
- g_message("ngsniffer: WAN capture has no network subtype");
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
+ *err_info = g_strdup("ngsniffer: WAN capture has no network subtype");
return -1;
}
@@ -860,8 +862,8 @@ process_rec_header2_v145(wtap *wth, unsigned char *buffer, guint16 length,
/*
* There is no 5th byte; give up.
*/
- g_message("ngsniffer: WAN bridge/router capture has no ISDN flag");
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
+ *err_info = g_strdup("ngsniffer: WAN bridge/router capture has no ISDN flag");
return -1;
}
if (buffer[6] == 0x01)
@@ -878,16 +880,17 @@ process_rec_header2_v145(wtap *wth, unsigned char *buffer, guint16 length,
/*
* Reject these until we can figure them out.
*/
- g_message("ngsniffer: WAN network subtype %u unknown or unsupported",
- buffer[4]);
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
+ *err_info = g_strdup_printf("ngsniffer: WAN network subtype %u unknown or unsupported",
+ buffer[4]);
return -1;
}
return 0;
}
/* Read the next packet */
-static gboolean ngsniffer_read(wtap *wth, int *err, long *data_offset)
+static gboolean ngsniffer_read(wtap *wth, int *err, gchar **err_info,
+ long *data_offset)
{
int ret;
guint16 type, length;
@@ -919,8 +922,8 @@ static gboolean ngsniffer_read(wtap *wth, int *err, long *data_offset)
* We shouldn't get a frame2 record in
* an ATM capture.
*/
- g_message("ngsniffer: REC_FRAME2 record in an ATM Sniffer file");
*err = WTAP_ERR_BAD_RECORD;
+ *err_info = g_strdup("ngsniffer: REC_FRAME2 record in an ATM Sniffer file");
return FALSE;
}
@@ -951,8 +954,8 @@ static gboolean ngsniffer_read(wtap *wth, int *err, long *data_offset)
* We shouldn't get a frame2 record in
* a non-ATM capture.
*/
- g_message("ngsniffer: REC_FRAME4 record in a non-ATM Sniffer file");
*err = WTAP_ERR_BAD_RECORD;
+ *err_info = g_strdup("ngsniffer: REC_FRAME4 record in a non-ATM Sniffer file");
return FALSE;
}
@@ -1048,8 +1051,8 @@ found:
/*
* Yes - treat this as an error.
*/
- g_message("ngsniffer: Record length is less than packet size");
*err = WTAP_ERR_BAD_RECORD;
+ *err_info = g_strdup("ngsniffer: Record length is less than packet size");
return FALSE;
}
@@ -1078,7 +1081,7 @@ found:
static gboolean ngsniffer_seek_read(wtap *wth, long seek_off,
union wtap_pseudo_header *pseudo_header, guchar *pd, int packet_size,
- int *err)
+ int *err, gchar **err_info _U_)
{
int ret;
guint16 type, length;