Add a "wtap_strerror()" routine, which takes as an argument an error
code supplied by a Wiretap routine (whether a positive UNIX "errno" code or a negative Wiretap error code), and returns an error message corresponding to it. Use that to construct the message Ethereal put up in a message box for those errors for which we don't have Ethereal put up a message of its choice. svn path=/trunk/; revision=545
This commit is contained in:
parent
4b9ab6d1fc
commit
c82c5954f2
20
file.c
20
file.c
|
@ -1,7 +1,7 @@
|
|||
/* file.c
|
||||
* File I/O routines
|
||||
*
|
||||
* $Id: file.c,v 1.78 1999/08/22 00:47:43 guy Exp $
|
||||
* $Id: file.c,v 1.79 1999/08/22 02:52:42 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -262,13 +262,8 @@ read_cap_file(capture_file *cf) {
|
|||
break;
|
||||
|
||||
default:
|
||||
if (err < 0) {
|
||||
sprintf(errmsg_errno, "An error occurred while reading the"
|
||||
" capture file: Error %d.", err);
|
||||
} else {
|
||||
sprintf(errmsg_errno, "An error occurred while reading the"
|
||||
" capture file: %s.", strerror(err));
|
||||
}
|
||||
sprintf(errmsg_errno, "An error occurred while reading the"
|
||||
" capture file: %s.", wtap_strerror(err));
|
||||
errmsg = errmsg_errno;
|
||||
break;
|
||||
}
|
||||
|
@ -1056,7 +1051,8 @@ file_open_error_message(int err, int for_writing)
|
|||
break;
|
||||
|
||||
default:
|
||||
sprintf(errmsg_errno, "The file \"%%s\" could not be opened: %s.", strerror(err));
|
||||
sprintf(errmsg_errno, "The file \"%%s\" could not be opened: %s.",
|
||||
wtap_strerror(err));
|
||||
errmsg = errmsg_errno;
|
||||
break;
|
||||
}
|
||||
|
@ -1068,7 +1064,8 @@ file_read_error_message(int err)
|
|||
{
|
||||
static char errmsg_errno[1024+1];
|
||||
|
||||
sprintf(errmsg_errno, "An error occurred while reading from the file \"%%s\": %s.", strerror(err));
|
||||
sprintf(errmsg_errno, "An error occurred while reading from the file \"%%s\": %s.",
|
||||
wtap_strerror(err));
|
||||
return errmsg_errno;
|
||||
}
|
||||
|
||||
|
@ -1091,7 +1088,8 @@ file_write_error_message(int err)
|
|||
#endif
|
||||
|
||||
default:
|
||||
sprintf(errmsg_errno, "An error occurred while writing to the file \"%%s\": %s.", strerror(err));
|
||||
sprintf(errmsg_errno, "An error occurred while writing to the file \"%%s\": %s.",
|
||||
wtap_strerror(err));
|
||||
errmsg = errmsg_errno;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* wtap.c
|
||||
*
|
||||
* $Id: wtap.c,v 1.15 1999/08/19 05:31:33 guy Exp $
|
||||
* $Id: wtap.c,v 1.16 1999/08/22 02:52:48 guy Exp $
|
||||
*
|
||||
* Wiretap Library
|
||||
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
|
||||
|
@ -20,6 +20,8 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
#include <string.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
@ -86,6 +88,39 @@ const char *wtap_file_type_string(wtap *wth)
|
|||
}
|
||||
}
|
||||
|
||||
static const char *wtap_errlist[] = {
|
||||
"The file isn't a plain file",
|
||||
"The file isn't a capture file in a known format",
|
||||
"File contains record data we don't support",
|
||||
NULL,
|
||||
"Files can't be saved in that format",
|
||||
"That format doesn't support per-packet encapsulations",
|
||||
NULL,
|
||||
NULL,
|
||||
"Less data was read than was expected",
|
||||
"File contains a record that's not valid",
|
||||
"Less data was written than was requested"
|
||||
};
|
||||
#define WTAP_ERRLIST_SIZE (sizeof wtap_errlist / sizeof wtap_errlist[0])
|
||||
|
||||
const char *wtap_strerror(int err)
|
||||
{
|
||||
static char errbuf[6+11+1]; /* "Error %d" */
|
||||
int wtap_errlist_index;
|
||||
|
||||
if (err < 0) {
|
||||
wtap_errlist_index = -1 - err;
|
||||
if (wtap_errlist_index >= WTAP_ERRLIST_SIZE) {
|
||||
sprintf(errbuf, "Error %d", err);
|
||||
return errbuf;
|
||||
}
|
||||
if (wtap_errlist[wtap_errlist_index] == NULL)
|
||||
return "Unknown reason";
|
||||
return wtap_errlist[wtap_errlist_index];
|
||||
} else
|
||||
return strerror(err);
|
||||
}
|
||||
|
||||
void wtap_close(wtap *wth)
|
||||
{
|
||||
/* free up memory. If any capture structure ever allocates
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* wtap.h
|
||||
*
|
||||
* $Id: wtap.h,v 1.31 1999/08/22 02:29:38 guy Exp $
|
||||
* $Id: wtap.h,v 1.32 1999/08/22 02:52:48 guy Exp $
|
||||
*
|
||||
* Wiretap Library
|
||||
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
|
||||
|
@ -291,6 +291,7 @@ FILE* wtap_file(wtap *wth);
|
|||
int wtap_snapshot_length(wtap *wth); /* per file */
|
||||
int wtap_file_type(wtap *wth);
|
||||
const char *wtap_file_type_string(wtap *wth);
|
||||
const char *wtap_strerror(int err);
|
||||
void wtap_close(wtap *wth);
|
||||
|
||||
wtap_dumper* wtap_dump_open(const char *filename, int filetype, int encap,
|
||||
|
|
Loading…
Reference in New Issue