Have WTAP_ERR_INTERNAL include an err_info string giving details.

That way, users won't just see "You got an internal error", the details
will be given, so they can report them in a bug.
This commit is contained in:
Guy Harris 2020-10-13 18:48:46 -07:00
parent 92e1b110f3
commit 6e6233521a
69 changed files with 551 additions and 360 deletions

View File

@ -997,17 +997,17 @@ failure_message_cont(const char *msg_format, va_list ap)
static wtap_dumper *
editcap_dump_open(const char *filename, const wtap_dump_params *params,
int *write_err)
int *write_err, gchar **write_err_info)
{
wtap_dumper *pdh;
if (strcmp(filename, "-") == 0) {
/* Write to the standard output. */
pdh = wtap_dump_open_stdout(out_file_type_subtype, WTAP_UNCOMPRESSED,
params, write_err);
params, write_err, write_err_info);
} else {
pdh = wtap_dump_open(filename, out_file_type_subtype, WTAP_UNCOMPRESSED,
params, write_err);
params, write_err, write_err_info);
}
return pdh;
}
@ -1688,11 +1688,12 @@ invalid_time:
wtap_block_add_string_option_format(g_array_index(params.shb_hdrs, wtap_block_t, 0), OPT_SHB_USERAPPL, "%s", get_appname_and_version());
}
pdh = editcap_dump_open(filename, &params, &write_err);
pdh = editcap_dump_open(filename, &params, &write_err,
&write_err_info);
if (pdh == NULL) {
cfile_dump_open_failure_message("editcap", filename,
write_err,
write_err, write_err_info,
out_file_type_subtype);
ret = INVALID_FILE;
goto clean_exit;
@ -1714,8 +1715,9 @@ invalid_time:
}
while (nstime_cmp(&rec->ts, &block_next) > 0) { /* time for the next file */
if (!wtap_dump_close(pdh, &write_err)) {
cfile_close_failure_message(filename, write_err);
if (!wtap_dump_close(pdh, &write_err, &write_err_info)) {
cfile_close_failure_message(filename, write_err,
write_err_info);
ret = WRITE_ERROR;
goto clean_exit;
}
@ -1727,11 +1729,13 @@ invalid_time:
if (verbose)
fprintf(stderr, "Continuing writing in file %s\n", filename);
pdh = editcap_dump_open(filename, &params, &write_err);
pdh = editcap_dump_open(filename, &params, &write_err,
&write_err_info);
if (pdh == NULL) {
cfile_dump_open_failure_message("editcap", filename,
write_err,
write_err_info,
out_file_type_subtype);
ret = INVALID_FILE;
goto clean_exit;
@ -1743,8 +1747,9 @@ invalid_time:
if (split_packet_count != 0) {
/* time for the next file? */
if (written_count > 0 && (written_count % split_packet_count) == 0) {
if (!wtap_dump_close(pdh, &write_err)) {
cfile_close_failure_message(filename, write_err);
if (!wtap_dump_close(pdh, &write_err, &write_err_info)) {
cfile_close_failure_message(filename, write_err,
write_err_info);
ret = WRITE_ERROR;
goto clean_exit;
}
@ -1756,10 +1761,11 @@ invalid_time:
if (verbose)
fprintf(stderr, "Continuing writing in file %s\n", filename);
pdh = editcap_dump_open(filename, &params, &write_err);
pdh = editcap_dump_open(filename, &params, &write_err,
&write_err_info);
if (pdh == NULL) {
cfile_dump_open_failure_message("editcap", filename,
write_err,
write_err, write_err_info,
out_file_type_subtype);
ret = INVALID_FILE;
goto clean_exit;
@ -2155,18 +2161,18 @@ invalid_time:
g_free (filename);
filename = g_strdup(argv[optind+1]);
pdh = editcap_dump_open(filename, &params, &write_err);
pdh = editcap_dump_open(filename, &params, &write_err, &write_err_info);
if (pdh == NULL) {
cfile_dump_open_failure_message("editcap", filename,
write_err,
write_err, write_err_info,
out_file_type_subtype);
ret = INVALID_FILE;
goto clean_exit;
}
}
if (!wtap_dump_close(pdh, &write_err)) {
cfile_close_failure_message(filename, write_err);
if (!wtap_dump_close(pdh, &write_err, &write_err_info)) {
cfile_close_failure_message(filename, write_err, write_err_info);
ret = WRITE_ERROR;
goto clean_exit;
}

View File

@ -1145,6 +1145,7 @@ snort_dissector(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data
if (!current_session.pdh) {
wtap_dump_params params = WTAP_DUMP_PARAMS_INIT;
int open_err;
gchar *open_err_info;
/* Older versions of Snort don't support capture file with several encapsulations (like pcapng),
* so write in pcap format and hope we have just one encap.
@ -1163,8 +1164,11 @@ snort_dissector(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data
WTAP_FILE_TYPE_SUBTYPE_PCAP,
WTAP_UNCOMPRESSED,
&params,
&open_err);
&open_err,
&open_err_info);
if (!current_session.pdh) {
/* XXX - report the error somehow? */
g_free(open_err_info);
current_session.working = FALSE;
return 0;
}
@ -1189,10 +1193,13 @@ snort_dissector(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data
/* Dump frame into snort's stdin */
if (!wtap_dump(current_session.pdh, &rec, tvb_get_ptr(tvb, 0, tvb_reported_length(tvb)), &write_err, &err_info)) {
/* XXX - report the error somehow? */
g_free(err_info);
current_session.working = FALSE;
return 0;
}
if (!wtap_dump_flush(current_session.pdh, &write_err)) {
/* XXX - report the error somehow? */
current_session.working = FALSE;
return 0;
}
@ -1375,8 +1382,10 @@ static void snort_cleanup(void)
/* Close dumper writing into snort's stdin. This will cause snort to exit! */
if (current_session.pdh) {
int write_err;
if (!wtap_dump_close(current_session.pdh, &write_err)) {
gchar *write_err_info;
if (!wtap_dump_close(current_session.pdh, &write_err, &write_err_info)) {
/* XXX - somehow report the error? */
g_free(write_err_info);
}
current_session.pdh = NULL;
}

View File

@ -204,11 +204,13 @@ WSLUA_CONSTRUCTOR Dumper_new(lua_State* L) {
int filetype = (int)luaL_optinteger(L,WSLUA_OPTARG_Dumper_new_FILETYPE,WTAP_FILE_TYPE_SUBTYPE_PCAP);
int encap = (int)luaL_optinteger(L,WSLUA_OPTARG_Dumper_new_ENCAP,WTAP_ENCAP_ETHERNET);
int err = 0;
gchar *err_info = NULL;
const char* filename = cross_plat_fname(fname);
wtap_dump_params params = WTAP_DUMP_PARAMS_INIT;
params.encap = encap;
d = wtap_dump_open(filename, filetype, WTAP_UNCOMPRESSED, &params, &err);
d = wtap_dump_open(filename, filetype, WTAP_UNCOMPRESSED, &params, &err,
&err_info);
if (! d ) {
/* WSLUA_ERROR("Error while opening file for writing"); */
@ -254,6 +256,13 @@ WSLUA_CONSTRUCTOR Dumper_new(lua_State* L) {
wtap_file_type_subtype_string(filetype));
break;
case WTAP_ERR_INTERNAL:
luaL_error(L,"An internal error occurred creating the file \"%s\" (%s)",
filename,
err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
default:
luaL_error(L,"error while opening \"%s\": %s",
filename,
@ -274,6 +283,7 @@ WSLUA_METHOD Dumper_close(lua_State* L) {
/* Closes a dumper. */
Dumper* dp = (Dumper*)luaL_checkudata(L, 1, "Dumper");
int err;
gchar *err_info;
if (! *dp) {
WSLUA_ERROR(Dumper_close,"Cannot operate on a closed dumper");
@ -282,9 +292,15 @@ WSLUA_METHOD Dumper_close(lua_State* L) {
g_hash_table_remove(dumper_encaps,*dp);
if (!wtap_dump_close(*dp, &err)) {
luaL_error(L,"error closing: %s",
wtap_strerror(err));
if (!wtap_dump_close(*dp, &err, &err_info)) {
if (err_info != NULL) {
luaL_error(L,"error closing: %s (%s)",
wtap_strerror(err), err_info);
g_free(err_info);
} else {
luaL_error(L,"error closing: %s",
wtap_strerror(err));
}
}
/* this way if we close a dumper any attempt to use it (for everything but GC) will yield an error */
@ -392,6 +408,7 @@ WSLUA_METHOD Dumper_new_for_current(lua_State* L) {
int filetype = (int)luaL_optinteger(L,WSLUA_OPTARG_Dumper_new_for_current_FILETYPE,WTAP_FILE_TYPE_SUBTYPE_PCAP);
int encap;
int err = 0;
gchar *err_info = NULL;
const char* filename = cross_plat_fname(fname);
wtap_dump_params params = WTAP_DUMP_PARAMS_INIT;
@ -406,7 +423,8 @@ WSLUA_METHOD Dumper_new_for_current(lua_State* L) {
encap = lua_pinfo->rec->rec_header.packet_header.pkt_encap;
params.encap = encap;
d = wtap_dump_open(filename, filetype, WTAP_UNCOMPRESSED, &params, &err);
d = wtap_dump_open(filename, filetype, WTAP_UNCOMPRESSED, &params, &err,
&err_info);
if (! d ) {
switch (err) {
@ -451,6 +469,13 @@ WSLUA_METHOD Dumper_new_for_current(lua_State* L) {
wtap_file_type_subtype_string(filetype));
break;
case WTAP_ERR_INTERNAL:
luaL_error(L,"An internal error occurred creating the file \"%s\" (%s)",
filename,
err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
default:
luaL_error(L,"error while opening \"%s\": %s",
filename,
@ -541,6 +566,7 @@ WSLUA_METHOD Dumper_dump_current(lua_State* L) {
static int Dumper__gc(lua_State* L) {
Dumper* dp = (Dumper*)luaL_checkudata(L, 1, "Dumper");
int err;
gchar *err_info;
/* If we are Garbage Collected it means the Dumper is no longer usable. Close it */
@ -549,9 +575,15 @@ static int Dumper__gc(lua_State* L) {
g_hash_table_remove(dumper_encaps,*dp);
if (!wtap_dump_close(*dp, &err)) {
luaL_error(L,"error closing: %s",
wtap_strerror(err));
if (!wtap_dump_close(*dp, &err, &err_info)) {
if (err_info != NULL) {
luaL_error(L,"error closing: %s (%s)",
wtap_strerror(err), err_info);
g_free(err_info);
} else {
luaL_error(L,"error closing: %s",
wtap_strerror(err));
}
}
return 0;

View File

@ -338,7 +338,7 @@ WSLUA_METHOD File_seek(lua_State* L) {
File f = checkFile(L,1);
int op = luaL_checkoption(L, 2, "cur", modenames);
gint64 offset = (gint64) luaL_optlong(L, 3, 0);
int err = WTAP_ERR_INTERNAL;
int err;
if (file_is_reader(f)) {

View File

@ -50,22 +50,40 @@ static GSList *registered_file_handlers;
set this to true right before pcall(), and back to false afterwards */
static gboolean in_routine = FALSE;
static void
report_error(int *err, gchar **err_info, const char *fmt, ...)
{
va_list ap;
gchar *msg;
va_start(ap, fmt);
msg = g_strdup_vprintf(fmt, ap);
va_end(ap);
if (err != NULL) {
*err = WTAP_ERR_INTERNAL;
*err_info = msg;
} else {
g_warning("%s", msg);
g_free(msg);
}
}
/* This does the verification and setup common to all open/read/seek_read/close routines */
#define INIT_FILEHANDLER_ROUTINE(name,retval) \
#define INIT_FILEHANDLER_ROUTINE(name,retval,err,err_info) \
if (!fh) { \
g_warning("Error in file %s: no Lua FileHandler object", #name); \
report_error(err, err_info, "Error in file %s: no Lua FileHandler object", #name); \
return retval; \
} \
if (!fh->registered) { \
g_warning("Error in file %s: Lua FileHandler is not registered", #name); \
report_error(err, err_info, "Error in file %s: Lua FileHandler is not registered", #name); \
return retval; \
} \
if (!fh->L) { \
g_warning("Error in file %s: no FileHandler Lua state", #name); \
report_error(err, err_info, "Error in file %s: no FileHandler Lua state", #name); \
return retval; \
} \
if (fh->name##_ref == LUA_NOREF) { \
g_warning("Error in file %s: no FileHandler %s routine reference", #name, #name); \
report_error(err, err_info, "Error in file %s: no FileHandler %s routine reference", #name, #name); \
return retval; \
} \
L = fh->L; \
@ -73,7 +91,7 @@ static gboolean in_routine = FALSE;
push_error_handler(L, #name " routine"); \
lua_rawgeti(L, LUA_REGISTRYINDEX, fh->name##_ref); \
if (!lua_isfunction(L, -1)) { \
g_warning("Error in file %s: no FileHandler %s routine function in Lua", #name, #name); \
report_error(err, err_info, "Error in file %s: no FileHandler %s routine function in Lua", #name, #name); \
return retval; \
} \
/* now guard against deregistering during pcall() */ \
@ -89,45 +107,23 @@ static gboolean in_routine = FALSE;
#define LUA_ERRGCMM 9
#endif
#define CASE_ERROR(name) \
#define CASE_ERROR(name,err,err_info) \
case LUA_ERRRUN: \
g_warning("Run-time error while calling FileHandler %s routine", name); \
report_error(err, err_info, "Run-time error while calling FileHandler %s routine", name); \
break; \
case LUA_ERRMEM: \
g_warning("Memory alloc error while calling FileHandler %s routine", name); \
report_error(err, err_info, "Memory alloc error while calling FileHandler %s routine", name); \
break; \
case LUA_ERRERR: \
g_warning("Error in error handling while calling FileHandler %s routine", name); \
report_error(err, err_info, "Error in error handling while calling FileHandler %s routine", name); \
break; \
case LUA_ERRGCMM: \
g_warning("Error in garbage collector while calling FileHandler %s routine", name); \
report_error(err, err_info, "Error in garbage collector while calling FileHandler %s routine", name); \
break; \
default: \
g_assert_not_reached(); \
break;
#define CASE_ERROR_ERRINFO(name) \
case LUA_ERRRUN: \
g_warning("Run-time error while calling FileHandler %s routine", name); \
*err_info = g_strdup_printf("Run-time error while calling FileHandler %s routine", name); \
break; \
case LUA_ERRMEM: \
g_warning("Memory alloc error while calling FileHandler %s routine", name); \
*err_info = g_strdup_printf("Memory alloc error while calling FileHandler %s routine", name); \
break; \
case LUA_ERRERR: \
g_warning("Error in error handling while calling FileHandler %s routine", name); \
*err_info = g_strdup_printf("Error in error handling while calling FileHandler %s routine", name); \
break; \
case LUA_ERRGCMM: \
g_warning("Error in garbage collector while calling FileHandler %s routine", name); \
*err_info = g_strdup_printf("Error in garbage collector while calling FileHandler %s routine", name); \
break; \
default: \
g_assert_not_reached(); \
break;
/* some declarations */
static gboolean
wslua_filehandler_read(wtap *wth, wtap_rec *rec, Buffer *buf,
@ -162,7 +158,7 @@ wslua_filehandler_open(wtap *wth, int *err, gchar **err_info)
File *fp = NULL;
CaptureInfo *fc = NULL;
INIT_FILEHANDLER_ROUTINE(read_open,WTAP_OPEN_NOT_MINE);
INIT_FILEHANDLER_ROUTINE(read_open,WTAP_OPEN_ERROR,err,err_info);
create_wth_priv(L, wth);
@ -174,7 +170,7 @@ wslua_filehandler_open(wtap *wth, int *err, gchar **err_info)
case 0:
retval = (wtap_open_return_val)wslua_optboolint(L,-1,0);
break;
CASE_ERROR_ERRINFO("read_open")
CASE_ERROR("read_open",err,err_info)
}
END_FILEHANDLER_ROUTINE();
@ -227,9 +223,9 @@ wslua_filehandler_open(wtap *wth, int *err, gchar **err_info)
}
else {
/* not a valid return type */
g_warning("FileHandler read_open routine returned %d", retval);
if (err) {
*err = WTAP_ERR_INTERNAL;
*err_info = g_strdup_printf("FileHandler read_open routine returned %d", retval);
}
retval = WTAP_OPEN_ERROR;
}
@ -255,7 +251,7 @@ wslua_filehandler_read(wtap *wth, wtap_rec *rec, Buffer *buf,
CaptureInfo *fc = NULL;
FrameInfo *fi = NULL;
INIT_FILEHANDLER_ROUTINE(read,FALSE);
INIT_FILEHANDLER_ROUTINE(read,FALSE,err,err_info);
/* Reset errno */
if (err) {
@ -285,7 +281,7 @@ wslua_filehandler_read(wtap *wth, wtap_rec *rec, Buffer *buf,
}
retval = wslua_optboolint(L,-1,0);
break;
CASE_ERROR_ERRINFO("read")
CASE_ERROR("read",err,err_info)
}
END_FILEHANDLER_ROUTINE();
@ -313,7 +309,7 @@ wslua_filehandler_seek_read(wtap *wth, gint64 seek_off,
CaptureInfo *fc = NULL;
FrameInfo *fi = NULL;
INIT_FILEHANDLER_ROUTINE(seek_read,FALSE);
INIT_FILEHANDLER_ROUTINE(seek_read,FALSE,err,err_info);
/* Reset errno */
if (err) {
@ -340,7 +336,7 @@ wslua_filehandler_seek_read(wtap *wth, gint64 seek_off,
*/
retval = lua_toboolean(L, -1);
break;
CASE_ERROR_ERRINFO("seek_read")
CASE_ERROR("seek_read",err,err_info)
}
END_FILEHANDLER_ROUTINE();
@ -363,7 +359,7 @@ wslua_filehandler_close(wtap *wth)
File *fp = NULL;
CaptureInfo *fc = NULL;
INIT_FILEHANDLER_ROUTINE(read_close,);
INIT_FILEHANDLER_ROUTINE(read_close,,NULL,NULL);
fp = push_File(L, wth->fh);
fc = push_CaptureInfo(L, wth, FALSE);
@ -371,7 +367,7 @@ wslua_filehandler_close(wtap *wth)
switch ( lua_pcall(L,2,1,1) ) {
case 0:
break;
CASE_ERROR("read_close")
CASE_ERROR("read_close",NULL,NULL)
}
END_FILEHANDLER_ROUTINE();
@ -395,7 +391,7 @@ wslua_filehandler_sequential_close(wtap *wth)
File *fp = NULL;
CaptureInfo *fc = NULL;
INIT_FILEHANDLER_ROUTINE(seq_read_close,);
INIT_FILEHANDLER_ROUTINE(seq_read_close,,NULL,NULL);
fp = push_File(L, wth->fh);
fc = push_CaptureInfo(L, wth, FALSE);
@ -403,7 +399,7 @@ wslua_filehandler_sequential_close(wtap *wth)
switch ( lua_pcall(L,2,1,1) ) {
case 0:
break;
CASE_ERROR("seq_read_close")
CASE_ERROR("seq_read_close",NULL,NULL)
}
END_FILEHANDLER_ROUTINE();
@ -435,7 +431,7 @@ wslua_filehandler_can_write_encap(int encap, void* data)
int retval = WTAP_ERR_UNWRITABLE_ENCAP;
lua_State* L = NULL;
INIT_FILEHANDLER_ROUTINE(can_write_encap,WTAP_ERR_INTERNAL);
INIT_FILEHANDLER_ROUTINE(can_write_encap,WTAP_ERR_UNWRITABLE_ENCAP,NULL,NULL);
lua_pushnumber(L, encap);
@ -443,7 +439,7 @@ wslua_filehandler_can_write_encap(int encap, void* data)
case 0:
retval = wslua_optboolint(L,-1,WTAP_ERR_UNWRITABLE_ENCAP);
break;
CASE_ERROR("can_write_encap")
CASE_ERROR("can_write_encap",NULL,NULL)
}
END_FILEHANDLER_ROUTINE();
@ -464,14 +460,14 @@ static gboolean
wslua_filehandler_dump(wtap_dumper *wdh, const wtap_rec *rec,
const guint8 *pd, int *err, gchar **err_info);
static gboolean
wslua_filehandler_dump_finish(wtap_dumper *wdh, int *err);
wslua_filehandler_dump_finish(wtap_dumper *wdh, int *err, gchar **err_info);
/* The classic wtap dump_open function.
* This returns 1 (TRUE) on success.
*/
static int
wslua_filehandler_dump_open(wtap_dumper *wdh, int *err)
wslua_filehandler_dump_open(wtap_dumper *wdh, int *err, gchar **err_info)
{
FileHandler fh = (FileHandler)(wdh->wslua_data);
int retval = 0;
@ -479,7 +475,7 @@ wslua_filehandler_dump_open(wtap_dumper *wdh, int *err)
File *fp = NULL;
CaptureInfoConst *fc = NULL;
INIT_FILEHANDLER_ROUTINE(write_open,0);
INIT_FILEHANDLER_ROUTINE(write_open,0,err,err_info);
create_wdh_priv(L, wdh);
@ -495,7 +491,7 @@ wslua_filehandler_dump_open(wtap_dumper *wdh, int *err)
case 0:
retval = wslua_optboolint(L,-1,0);
break;
CASE_ERROR("write_open")
CASE_ERROR("write_open",err,err_info)
}
END_FILEHANDLER_ROUTINE();
@ -533,7 +529,7 @@ wslua_filehandler_dump_open(wtap_dumper *wdh, int *err)
*/
static gboolean
wslua_filehandler_dump(wtap_dumper *wdh, const wtap_rec *rec,
const guint8 *pd, int *err, gchar **err_info _U_)
const guint8 *pd, int *err, gchar **err_info)
{
FileHandler fh = (FileHandler)(wdh->wslua_data);
int retval = -1;
@ -542,7 +538,7 @@ wslua_filehandler_dump(wtap_dumper *wdh, const wtap_rec *rec,
CaptureInfoConst *fc = NULL;
FrameInfoConst *fi = NULL;
INIT_FILEHANDLER_ROUTINE(write,FALSE);
INIT_FILEHANDLER_ROUTINE(write,FALSE,err,err_info);
/* Reset errno */
if (err) {
@ -558,7 +554,7 @@ wslua_filehandler_dump(wtap_dumper *wdh, const wtap_rec *rec,
case 0:
retval = wslua_optboolint(L,-1,0);
break;
CASE_ERROR("write")
CASE_ERROR("write",err,err_info)
}
END_FILEHANDLER_ROUTINE();
@ -574,7 +570,7 @@ wslua_filehandler_dump(wtap_dumper *wdh, const wtap_rec *rec,
* writes out the last information cleanly, else FALSE.
*/
static gboolean
wslua_filehandler_dump_finish(wtap_dumper *wdh, int *err)
wslua_filehandler_dump_finish(wtap_dumper *wdh, int *err, gchar **err_info)
{
FileHandler fh = (FileHandler)(wdh->wslua_data);
int retval = -1;
@ -582,7 +578,7 @@ wslua_filehandler_dump_finish(wtap_dumper *wdh, int *err)
File *fp = NULL;
CaptureInfoConst *fc = NULL;
INIT_FILEHANDLER_ROUTINE(write_close,FALSE);
INIT_FILEHANDLER_ROUTINE(write_close,FALSE,err,err_info);
/* Reset errno */
if (err) {
@ -597,7 +593,7 @@ wslua_filehandler_dump_finish(wtap_dumper *wdh, int *err)
case 0:
retval = wslua_optboolint(L,-1,0);
break;
CASE_ERROR("write_close")
CASE_ERROR("write_close",err,err_info)
}
END_FILEHANDLER_ROUTINE();

View File

@ -449,19 +449,20 @@ static struct extcap_dumper extcap_dumper_open(char *fifo, int encap) {
#else
wtap_dump_params params = WTAP_DUMP_PARAMS_INIT;
int err = 0;
gchar *err_info = NULL;
wtap_init(FALSE);
params.encap = encap;
params.snaplen = PACKET_LENGTH;
extcap_dumper.dumper.wtap = wtap_dump_open(fifo, WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC, WTAP_UNCOMPRESSED, &params, &err);
extcap_dumper.dumper.wtap = wtap_dump_open(fifo, WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC, WTAP_UNCOMPRESSED, &params, &err, &err_info);
if (!extcap_dumper.dumper.wtap) {
cfile_dump_open_failure_message("androiddump", fifo, err, WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC);
cfile_dump_open_failure_message("androiddump", fifo, err, err_info, WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC);
exit(EXIT_CODE_CANNOT_SAVE_WIRETAP_DUMP);
}
extcap_dumper.encap = encap;
if (!wtap_dump_flush(extcap_dumper.dumper.wtap, &err)) {
cfile_dump_open_failure_message("androiddump", fifo, err, WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC);
cfile_dump_open_failure_message("androiddump", fifo, err, NULL, WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC);
exit(EXIT_CODE_CANNOT_SAVE_WIRETAP_DUMP);
}
#endif

36
file.c
View File

@ -1410,7 +1410,8 @@ cf_merge_files_to_tempfile(gpointer pd_window, char **out_filenamep,
break;
case MERGE_ERR_CANT_OPEN_OUTFILE:
cfile_dump_open_failure_alert_box(*out_filenamep, err, file_type);
cfile_dump_open_failure_alert_box(*out_filenamep, err, err_info,
file_type);
break;
case MERGE_ERR_CANT_READ_INFILE:
@ -1429,7 +1430,7 @@ cf_merge_files_to_tempfile(gpointer pd_window, char **out_filenamep,
break;
case MERGE_ERR_CANT_CLOSE_OUTFILE:
cfile_close_failure_alert_box(*out_filenamep, err);
cfile_close_failure_alert_box(*out_filenamep, err, err_info);
break;
default:
@ -4539,16 +4540,17 @@ cf_save_records(capture_file *cf, const char *fname, guint save_format,
from which we're reading the packets that we're writing!) */
fname_new = g_strdup_printf("%s~", fname);
pdh = wtap_dump_open(fname_new, save_format, compression_type, &params,
&err);
&err, &err_info);
} else {
pdh = wtap_dump_open(fname, save_format, compression_type, &params, &err);
pdh = wtap_dump_open(fname, save_format, compression_type, &params,
&err, &err_info);
}
/* XXX idb_inf is documented to be used until wtap_dump_close. */
g_free(params.idb_inf);
params.idb_inf = NULL;
if (pdh == NULL) {
cfile_dump_open_failure_alert_box(fname, err, save_format);
cfile_dump_open_failure_alert_box(fname, err, err_info, save_format);
goto fail;
}
@ -4571,7 +4573,7 @@ cf_save_records(capture_file *cf, const char *fname, guint save_format,
If we're writing to a temporary file, remove it.
XXX - should we do so even if we're not writing to a
temporary file? */
wtap_dump_close(pdh, &err);
wtap_dump_close(pdh, &err, &err_info);
if (fname_new != NULL)
ws_unlink(fname_new);
cf_callback_invoke(cf_cb_file_save_stopped, NULL);
@ -4582,14 +4584,14 @@ cf_save_records(capture_file *cf, const char *fname, guint save_format,
If we're writing to a temporary file, remove it. */
if (fname_new != NULL)
ws_unlink(fname_new);
wtap_dump_close(pdh, &err);
wtap_dump_close(pdh, &err, &err_info);
goto fail;
}
needs_reload = wtap_dump_get_needs_reload(pdh);
if (!wtap_dump_close(pdh, &err)) {
cfile_close_failure_alert_box(fname, err);
if (!wtap_dump_close(pdh, &err, &err_info)) {
cfile_close_failure_alert_box(fname, err, err_info);
goto fail;
}
@ -4764,6 +4766,7 @@ cf_export_specified_packets(capture_file *cf, const char *fname,
{
gchar *fname_new = NULL;
int err;
gchar *err_info;
wtap_dumper *pdh;
save_callback_args_t callback_args;
wtap_dump_params params;
@ -4796,16 +4799,17 @@ cf_export_specified_packets(capture_file *cf, const char *fname,
from which we're reading the packets that we're writing!) */
fname_new = g_strdup_printf("%s~", fname);
pdh = wtap_dump_open(fname_new, save_format, compression_type, &params,
&err);
&err, &err_info);
} else {
pdh = wtap_dump_open(fname, save_format, compression_type, &params, &err);
pdh = wtap_dump_open(fname, save_format, compression_type, &params,
&err, &err_info);
}
/* XXX idb_inf is documented to be used until wtap_dump_close. */
g_free(params.idb_inf);
params.idb_inf = NULL;
if (pdh == NULL) {
cfile_dump_open_failure_alert_box(fname, err, save_format);
cfile_dump_open_failure_alert_box(fname, err, err_info, save_format);
goto fail;
}
@ -4834,7 +4838,7 @@ cf_export_specified_packets(capture_file *cf, const char *fname,
If we're writing to a temporary file, remove it.
XXX - should we do so even if we're not writing to a
temporary file? */
wtap_dump_close(pdh, &err);
wtap_dump_close(pdh, &err, &err_info);
if (fname_new != NULL)
ws_unlink(fname_new);
return CF_WRITE_ABORTED;
@ -4845,12 +4849,12 @@ cf_export_specified_packets(capture_file *cf, const char *fname,
If we're writing to a temporary file, remove it. */
if (fname_new != NULL)
ws_unlink(fname_new);
wtap_dump_close(pdh, &err);
wtap_dump_close(pdh, &err, &err_info);
goto fail;
}
if (!wtap_dump_close(pdh, &err)) {
cfile_close_failure_alert_box(fname, err);
if (!wtap_dump_close(pdh, &err, &err_info)) {
cfile_close_failure_alert_box(fname, err, err_info);
goto fail;
}

View File

@ -410,7 +410,8 @@ main(int argc, char *argv[])
break;
case MERGE_ERR_CANT_OPEN_OUTFILE:
cfile_dump_open_failure_message("mergecap", out_filename, err, file_type);
cfile_dump_open_failure_message("mergecap", out_filename, err, err_info,
file_type);
break;
case MERGE_ERR_CANT_READ_INFILE:
@ -430,7 +431,7 @@ main(int argc, char *argv[])
break;
case MERGE_ERR_CANT_CLOSE_OUTFILE:
cfile_close_failure_message(out_filename, err);
cfile_close_failure_message(out_filename, err, err_info);
break;
default:

View File

@ -641,10 +641,11 @@ void randpkt_loop(randpkt_example* example, guint64 produce_count, guint64 packe
gboolean randpkt_example_close(randpkt_example* example)
{
int err;
gchar *err_info;
gboolean ok = TRUE;
if (!wtap_dump_close(example->dump, &err)) {
cfile_close_failure_message(example->filename, err);
if (!wtap_dump_close(example->dump, &err, &err_info)) {
cfile_close_failure_message(example->filename, err, err_info);
ok = FALSE;
}
@ -659,6 +660,7 @@ gboolean randpkt_example_close(randpkt_example* example)
int randpkt_example_init(randpkt_example* example, char* produce_filename, int produce_max_bytes)
{
int err;
gchar *err_info;
if (pkt_rand == NULL) {
pkt_rand = g_rand_new();
@ -671,16 +673,16 @@ int randpkt_example_init(randpkt_example* example, char* produce_filename, int p
if (strcmp(produce_filename, "-") == 0) {
/* Write to the standard output. */
example->dump = wtap_dump_open_stdout(WTAP_FILE_TYPE_SUBTYPE_PCAP,
WTAP_UNCOMPRESSED, &params, &err);
WTAP_UNCOMPRESSED, &params, &err, &err_info);
example->filename = "the standard output";
} else {
example->dump = wtap_dump_open(produce_filename, WTAP_FILE_TYPE_SUBTYPE_PCAP,
WTAP_UNCOMPRESSED, &params, &err);
WTAP_UNCOMPRESSED, &params, &err, &err_info);
example->filename = produce_filename;
}
if (!example->dump) {
cfile_dump_open_failure_message("randpkt", produce_filename,
err, WTAP_FILE_TYPE_SUBTYPE_PCAP);
err, err_info, WTAP_FILE_TYPE_SUBTYPE_PCAP);
return WRITE_ERROR;
}

View File

@ -264,15 +264,17 @@ main(int argc, char *argv[])
/* Open outfile (same filetype/encap as input file) */
if (strcmp(outfile, "-") == 0) {
pdh = wtap_dump_open_stdout(wtap_file_type_subtype(wth), WTAP_UNCOMPRESSED, &params, &err);
pdh = wtap_dump_open_stdout(wtap_file_type_subtype(wth),
WTAP_UNCOMPRESSED, &params, &err, &err_info);
} else {
pdh = wtap_dump_open(outfile, wtap_file_type_subtype(wth), WTAP_UNCOMPRESSED, &params, &err);
pdh = wtap_dump_open(outfile, wtap_file_type_subtype(wth),
WTAP_UNCOMPRESSED, &params, &err, &err_info);
}
g_free(params.idb_inf);
params.idb_inf = NULL;
if (pdh == NULL) {
cfile_dump_open_failure_message("reordercap", outfile, err,
cfile_dump_open_failure_message("reordercap", outfile, err, err_info,
wtap_file_type_subtype(wth));
wtap_dump_params_cleanup(&params);
ret = OUTPUT_FILE_ERROR;
@ -341,8 +343,8 @@ main(int argc, char *argv[])
g_ptr_array_free(frames, TRUE);
/* Close outfile */
if (!wtap_dump_close(pdh, &err)) {
cfile_close_failure_message(outfile, err);
if (!wtap_dump_close(pdh, &err, &err_info)) {
cfile_close_failure_message(outfile, err, err_info);
wtap_dump_params_cleanup(&params);
ret = OUTPUT_FILE_ERROR;
goto clean_exit;

View File

@ -712,6 +712,8 @@ main(int argc, char *argv[])
gboolean arg_error = FALSE;
int err;
gchar *err_info;
gboolean exp_pdu_status;
volatile process_file_status_t status;
volatile gboolean draw_taps = FALSE;
volatile int exit_status = EXIT_SUCCESS;
@ -2009,10 +2011,12 @@ main(int argc, char *argv[])
/* Activate the export PDU tap */
comment = g_strdup_printf("Dump of PDUs from %s", cf_name);
err = exp_pdu_open(&exp_pdu_tap_data, exp_fd, comment);
exp_pdu_status = exp_pdu_open(&exp_pdu_tap_data, exp_fd, comment,
&err, &err_info);
g_free(comment);
if (err != 0) {
cfile_dump_open_failure_message("TShark", exp_pdu_filename, err,
if (!exp_pdu_status) {
cfile_dump_open_failure_message("TShark", exp_pdu_filename,
err, err_info,
WTAP_FILE_TYPE_SUBTYPE_PCAPNG);
exit_status = INVALID_EXPORT;
goto clean_exit;
@ -2098,9 +2102,8 @@ main(int argc, char *argv[])
}
if (pdu_export_arg) {
err = exp_pdu_close(&exp_pdu_tap_data);
if (err) {
cfile_close_failure_message(exp_pdu_filename, err);
if (!exp_pdu_close(&exp_pdu_tap_data, &err, &err_info)) {
cfile_close_failure_message(exp_pdu_filename, err, err_info);
exit_status = 2;
}
g_free(pdu_export_arg);
@ -3481,10 +3484,10 @@ process_cap_file(capture_file *cf, char *save_file, int out_file_type,
if (strcmp(save_file, "-") == 0) {
/* Write to the standard output. */
pdh = wtap_dump_open_stdout(out_file_type, WTAP_UNCOMPRESSED, &params,
&err);
&err, &err_info);
} else {
pdh = wtap_dump_open(save_file, out_file_type, WTAP_UNCOMPRESSED, &params,
&err);
&err, &err_info);
}
g_free(params.idb_inf);
@ -3492,7 +3495,8 @@ process_cap_file(capture_file *cf, char *save_file, int out_file_type,
if (pdh == NULL) {
/* We couldn't set up to write to the capture file. */
cfile_dump_open_failure_message("TShark", save_file, err, out_file_type);
cfile_dump_open_failure_message("TShark", save_file, err, err_info,
out_file_type);
status = PROCESS_FILE_NO_FILE_PROCESSED;
goto out;
}
@ -3667,14 +3671,15 @@ process_cap_file(capture_file *cf, char *save_file, int out_file_type,
}
}
/* Now close the capture file. */
if (!wtap_dump_close(pdh, &err)) {
cfile_close_failure_message(save_file, err);
if (!wtap_dump_close(pdh, &err, &err_info)) {
cfile_close_failure_message(save_file, err, err_info);
status = PROCESS_FILE_ERROR;
}
} else {
/* We got a write error; it was reported, so just close the dump file
without bothering to check for further errors. */
wtap_dump_close(pdh, &err);
wtap_dump_close(pdh, &err, &err_info);
g_free(err_info);
status = PROCESS_FILE_ERROR;
}
} else {

View File

@ -49,7 +49,7 @@ vwarning_alert_box(const char *msg_format, va_list ap)
* Alert box for a failed attempt to open a capture file for reading.
* "filename" is the name of the file being opened; "err" is assumed
* to be a UNIX-style errno or a WTAP_ERR_ value; "err_info" is assumed
* to be a string giving further information for some WTAP_ERR_ values..
* to be a string giving further information for some WTAP_ERR_ values.
*
* XXX - add explanatory secondary text for at least some of the errors;
* various HIGs suggest that you should, for example, suggest that the
@ -131,6 +131,14 @@ cfile_open_failure_alert_box(const char *filename, int err, gchar *err_info)
g_free(err_info);
break;
case WTAP_ERR_INTERNAL:
simple_error_message_box(
"An internal error occurred opening the file \"%s\".\n"
"(%s)", display_basename,
err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
case WTAP_ERR_DECOMPRESSION_NOT_SUPPORTED:
simple_error_message_box(
"The file \"%s\" cannot be decompressed; it is compressed in a way that we don't support.\n"
@ -156,9 +164,10 @@ cfile_open_failure_alert_box(const char *filename, int err, gchar *err_info)
/*
* Alert box for a failed attempt to open a capture file for writing.
* "filename" is the name of the file being opened; "err" is assumed
* to be a UNIX-style errno or a WTAP_ERR_ value; "file_type_subtype"
* is a WTAP_FILE_TYPE_SUBTYPE_ value for the type and subtype of file
* being opened.
* to be a UNIX-style errno or a WTAP_ERR_ value; "err_info" is assumed
* to be a string giving further information for some WTAP_ERR_ values;
* "file_type_subtype" is a WTAP_FILE_TYPE_SUBTYPE_ value for the type
* and subtype of file being opened.
*
* XXX - add explanatory secondary text for at least some of the errors;
* various HIGs suggest that you should, for example, suggest that the
@ -168,7 +177,7 @@ cfile_open_failure_alert_box(const char *filename, int err, gchar *err_info)
*/
void
cfile_dump_open_failure_alert_box(const char *filename, int err,
int file_type_subtype)
gchar *err_info, int file_type_subtype)
{
gchar *display_basename;
@ -221,6 +230,15 @@ cfile_dump_open_failure_alert_box(const char *filename, int err,
"This file type cannot be written as a compressed file.");
break;
case WTAP_ERR_INTERNAL:
simple_error_message_box(
"An internal error occurred creating the file \"%s\".\n"
"(%s)",
display_basename,
err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
default:
simple_error_message_box(
"The file \"%s\" could not be created: %s.",
@ -291,6 +309,14 @@ cfile_read_failure_alert_box(const char *filename, int err, gchar *err_info)
g_free(err_info);
break;
case WTAP_ERR_INTERNAL:
simple_error_message_box(
"An internal error occurred while reading the %s.\n(%s)",
display_name,
err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
case WTAP_ERR_DECOMPRESSION_NOT_SUPPORTED:
simple_error_message_box(
"The %s cannot be decompressed; it is compressed in a way that we don't support.\n"
@ -362,6 +388,16 @@ cfile_write_failure_alert_box(const char *in_filename, const char *out_filename,
wtap_file_type_subtype_string(file_type_subtype));
break;
case WTAP_ERR_INTERNAL:
out_display_basename = g_filename_display_basename(out_filename);
simple_error_message_box(
"An internal error occurred while writing to the file \"%s\".\n(%s)",
out_display_basename,
err_info != NULL ? err_info : "no information supplied");
g_free(out_display_basename);
g_free(err_info);
break;
case WTAP_ERR_PACKET_TOO_LARGE:
/*
* This is a problem with the particular frame we're writing and
@ -426,7 +462,9 @@ cfile_write_failure_alert_box(const char *in_filename, const char *out_filename,
/*
* Alert box for a failed attempt to close a capture file.
* "err" is assumed to be a UNIX-style errno or a WTAP_ERR_ value.
* "err" is assumed to be a UNIX-style errno or a WTAP_ERR_ value;
* "err_info" is assumed to be a string giving further information for
* some WTAP_ERR_ values.
*
* When closing a capture file:
*
@ -453,7 +491,7 @@ cfile_write_failure_alert_box(const char *in_filename, const char *out_filename,
* typical Wireshark user is, but....
*/
void
cfile_close_failure_alert_box(const char *filename, int err)
cfile_close_failure_alert_box(const char *filename, int err, gchar *err_info)
{
gchar *display_basename;
@ -474,6 +512,15 @@ cfile_close_failure_alert_box(const char *filename, int err)
display_basename);
break;
case WTAP_ERR_INTERNAL:
simple_error_message_box(
"An internal error occurred closing the file \"%s\".\n"
"(%s)",
display_basename,
err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
default:
simple_error_message_box(
"An error occurred while closing the file \"%s\": %s.",
@ -530,8 +577,7 @@ read_failure_alert_box(const char *filename, int err)
/*
* Alert box for a failed attempt to write to a file.
* "err" is assumed to be a UNIX-style errno if positive and a
* Wiretap error if negative.
* "err" is assumed to be a UNIX-style errno.
*
* XXX - add explanatory secondary text for at least some of the errors;
* various HIGs suggest that you should, for example, suggest that the
@ -545,25 +591,8 @@ write_failure_alert_box(const char *filename, int err)
gchar *display_basename;
display_basename = g_filename_display_basename(filename);
if (err < 0) {
switch (err) {
case WTAP_ERR_SHORT_WRITE:
simple_message_box(ESD_TYPE_ERROR, NULL, NULL,
"A full write couldn't be done to the file \"%s\".",
display_basename);
break;
default:
simple_message_box(ESD_TYPE_ERROR, NULL, NULL,
"An error occurred while writing to the file \"%s\": %s.",
display_basename, wtap_strerror(err));
break;
}
} else {
simple_message_box(ESD_TYPE_ERROR, NULL, NULL,
file_write_error_message(err), display_basename);
}
simple_message_box(ESD_TYPE_ERROR, NULL, NULL,
file_write_error_message(err), display_basename);
g_free(display_basename);
}

View File

@ -39,11 +39,13 @@ extern void cfile_open_failure_alert_box(const char *filename, int err,
/*
* Alert box for a failed attempt to open a capture file for writing.
* "filename" is the name of the file being opened; "err" is assumed
* to be a UNIX-style errno or a WTAP_ERR_ value; "file_type_subtype"
* is a WTAP_FILE_TYPE_SUBTYPE_ value for the type and subtype of file
* being opened.
* to be a UNIX-style errno or a WTAP_ERR_ value; "err_info" is assumed
* to be a string giving further information for some WTAP_ERR_ values;
* "file_type_subtype" is a WTAP_FILE_TYPE_SUBTYPE_ value for the type
* and subtype of file being opened.
*/
extern void cfile_dump_open_failure_alert_box(const char *filename, int err,
gchar *err_info,
int file_type_subtype);
/*
@ -74,7 +76,9 @@ extern void cfile_write_failure_alert_box(const char *in_filename,
/*
* Alert box for a failed attempt to close a capture file.
* "err" is assumed to be a UNIX-style errno or a WTAP_ERR_ value.
* "err" is assumed to be a UNIX-style errno or a WTAP_ERR_ value;
* "err_info" is assumed to be a string giving further information for
* some WTAP_ERR_ values.
*
* When closing a capture file:
*
@ -94,7 +98,8 @@ extern void cfile_write_failure_alert_box(const char *in_filename,
*
* so we have to check for write errors here.
*/
extern void cfile_close_failure_alert_box(const char *filename, int err);
extern void cfile_close_failure_alert_box(const char *filename, int err,
gchar *err_info);
/*
* Alert box for a failed attempt to open or create a file.

View File

@ -370,6 +370,20 @@ cf_open_error_message(int err, gchar *err_info, gboolean for_writing,
errmsg = errmsg_errno;
break;
case WTAP_ERR_INTERNAL:
if (for_writing) {
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
"An internal error occurred creating the file \"%%s\".\n"
"(%s)", err_info != NULL ? err_info : "no information supplied");
} else {
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
"An internal error occurred opening the file \"%%s\".\n"
"(%s)", err_info != NULL ? err_info : "no information supplied");
}
g_free(err_info);
errmsg = errmsg_errno;
break;
case WTAP_ERR_DECOMPRESSION_NOT_SUPPORTED:
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
"We don't support the form of compression used by the compressed file \"%%s\".\n"

View File

@ -35,7 +35,9 @@ exp_pdu_file_open(exp_pdu_t *exp_pdu_tap_data)
{
int import_file_fd;
char *capfile_name, *comment;
gboolean status;
int err;
gchar *err_info;
/* Choose a random name for the temporary import buffer */
GError *err_tempfile = NULL;
@ -47,20 +49,21 @@ exp_pdu_file_open(exp_pdu_t *exp_pdu_tap_data)
}
comment = g_strdup_printf("Dump of PDUs from %s", cfile.filename);
err = exp_pdu_open(exp_pdu_tap_data, import_file_fd, comment);
status = exp_pdu_open(exp_pdu_tap_data, import_file_fd, comment, &err,
&err_info);
g_free(comment);
if (err != 0) {
if (!status) {
cfile_dump_open_failure_alert_box(capfile_name ? capfile_name : "temporary file",
err, WTAP_FILE_TYPE_SUBTYPE_PCAPNG);
err, err_info,
WTAP_FILE_TYPE_SUBTYPE_PCAPNG);
goto end;
}
/* Run the tap */
cf_retap_packets(&cfile);
err = exp_pdu_close(exp_pdu_tap_data);
if (err!= 0) {
cfile_close_failure_alert_box(capfile_name, err);
if (!exp_pdu_close(exp_pdu_tap_data, &err, &err_info)) {
cfile_close_failure_alert_box(capfile_name, err, err_info);
}
/* XXX: should this use the open_routine type in the cfile instead of WTAP_TYPE_AUTO? */

View File

@ -124,6 +124,14 @@ cfile_open_failure_message(const char *progname, const char *filename,
g_free(err_info);
break;
case WTAP_ERR_INTERNAL:
cmdarg_err("An internal error occurred opening the %s.\n"
"(%s)",
file_description,
err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
case WTAP_ERR_DECOMPRESSION_NOT_SUPPORTED:
cmdarg_err("The %s cannot be decompressed; it is compressed in a way that we don't support."
"(%s)",
@ -147,13 +155,15 @@ cfile_open_failure_message(const char *progname, const char *filename,
* Error message for a failed attempt to open a capture file for writing.
* "progname" is the name of the program trying to open the file;
* "filename" is the name of the file being opened; "err" is assumed
* to be a UNIX-style errno or a WTAP_ERR_ value; "file_type_subtype" is
* a WTAP_FILE_TYPE_SUBTYPE_ value for the type and subtype of file being
* opened.
* to be a UNIX-style errno or a WTAP_ERR_ value; "err_info" is assumed
* to be a string giving further information for some WTAP_ERR_ values;
* "file_type_subtype" is a WTAP_FILE_TYPE_SUBTYPE_ value for the type
* and subtype of file being opened.
*/
void
cfile_dump_open_failure_message(const char *progname, const char *filename,
int err, int file_type_subtype)
int err, gchar *err_info,
int file_type_subtype)
{
if (err < 0) {
/*
@ -204,6 +214,14 @@ cfile_dump_open_failure_message(const char *progname, const char *filename,
cmdarg_err("This file type cannot be written as a compressed file.");
break;
case WTAP_ERR_INTERNAL:
cmdarg_err("An internal error occurred creating the %s.\n"
"(%s)",
file_description,
err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
default:
cmdarg_err("The %s could not be created: %s.",
file_description,
@ -262,6 +280,13 @@ cfile_read_failure_message(const char *progname, const char *filename,
g_free(err_info);
break;
case WTAP_ERR_INTERNAL:
cmdarg_err("An internal error occurred while reading the %s.\n(%s)",
file_string,
err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
case WTAP_ERR_DECOMPRESSION_NOT_SUPPORTED:
cmdarg_err("The %s cannot be decompressed; it is compressed in a way that we don't support.\n"
"(%s)",
@ -372,6 +397,13 @@ cfile_write_failure_message(const char *progname, const char *in_filename,
g_free(err_info);
break;
case WTAP_ERR_INTERNAL:
cmdarg_err("An internal error occurred while writing the %s.\n(%s)",
out_file_string,
err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
case ENOSPC:
cmdarg_err("Not all the packets could be written to the %s because there is "
"no space left on the file system.",
@ -403,7 +435,8 @@ cfile_write_failure_message(const char *progname, const char *in_filename,
/*
* Error message for a failed attempt to close a capture file.
* "filename" is the name of the file being closed; "err" is assumed
* to be a UNIX-style errno or a WTAP_ERR_ value.
* to be a UNIX-style errno or a WTAP_ERR_ value; "err_info" is assumed
* to be a string giving further information for some WTAP_ERR_ values.
*
* When closing a capture file:
*
@ -424,7 +457,7 @@ cfile_write_failure_message(const char *progname, const char *in_filename,
* so we have to check for write errors here.
*/
void
cfile_close_failure_message(const char *filename, int err)
cfile_close_failure_message(const char *filename, int err, gchar *err_info)
{
char *file_string;
@ -457,6 +490,14 @@ cfile_close_failure_message(const char *filename, int err)
file_string);
break;
case WTAP_ERR_INTERNAL:
cmdarg_err("An internal error occurred closing the file \"%s\".\n"
"(%s)",
file_string,
err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
default:
cmdarg_err("An error occurred while closing the file %s: %s.",
file_string, wtap_strerror(err));

View File

@ -28,15 +28,16 @@ extern void cfile_open_failure_message(const char *progname,
gchar *err_info);
/*
* Error message for a failed attempt to open a capture file for writing.
* "progname" is the name of the program trying to open the file;
* "filename" is the name of the file being opened; "err" is assumed
* to be a UNIX-style errno or a WTAP_ERR_ value; "file_type_subtype" is
* a WTAP_FILE_TYPE_SUBTYPE_ value for the type and subtype of file being
* opened.
* to be a UNIX-style errno or a WTAP_ERR_ value; "err_info" is assumed
* to be a string giving further information for some WTAP_ERR_ values;
* "file_type_subtype" is a WTAP_FILE_TYPE_SUBTYPE_ value for the type
* and subtype of file being opened.
*/
extern void cfile_dump_open_failure_message(const char *progname,
const char *filename, int err,
gchar *err_info,
int file_type_subtype);
/*
@ -72,7 +73,8 @@ extern void cfile_write_failure_message(const char *progname,
/*
* Error message for a failed attempt to close a capture file.
* "filename" is the name of the file being closed; "err" is assumed
* to be a UNIX-style errno or a WTAP_ERR_ value.
* to be a UNIX-style errno or a WTAP_ERR_ value; "err_info" is assumed
* to be a string giving further information for some WTAP_ERR_ values.
*
* When closing a capture file:
*
@ -92,7 +94,8 @@ extern void cfile_write_failure_message(const char *progname,
*
* so we have to check for write errors here.
*/
extern void cfile_close_failure_message(const char *filename, int err);
extern void cfile_close_failure_message(const char *filename, int err,
gchar *err_info);
#ifdef __cplusplus
}

View File

@ -118,6 +118,7 @@ QString &ImportTextDialog::capfileName() {
void ImportTextDialog::convertTextFile() {
char *tmpname;
int err;
gchar *err_info;
wtap_dump_params params;
capfile_name_.clear();
@ -126,12 +127,12 @@ void ImportTextDialog::convertTextFile() {
params.snaplen = import_info_.max_frame_length;
params.tsprec = WTAP_TSPREC_USEC; /* XXX - support other precisions? */
/* Use a random name for the temporary import buffer */
import_info_.wdh = wtap_dump_open_tempfile(&tmpname, "import", WTAP_FILE_TYPE_SUBTYPE_PCAPNG, WTAP_UNCOMPRESSED, &params, &err);
import_info_.wdh = wtap_dump_open_tempfile(&tmpname, "import", WTAP_FILE_TYPE_SUBTYPE_PCAPNG, WTAP_UNCOMPRESSED, &params, &err, &err_info);
capfile_name_.append(tmpname ? tmpname : "temporary file");
g_free(tmpname);
qDebug() << capfile_name_ << ":" << import_info_.wdh << import_info_.encapsulation << import_info_.max_frame_length;
if (import_info_.wdh == NULL) {
cfile_dump_open_failure_alert_box(capfile_name_.toUtf8().constData(), err, WTAP_FILE_TYPE_SUBTYPE_PCAP);
cfile_dump_open_failure_alert_box(capfile_name_.toUtf8().constData(), err, err_info, WTAP_FILE_TYPE_SUBTYPE_PCAP);
fclose(import_info_.import_text_file);
setResult(QDialog::Rejected);
return;
@ -150,9 +151,9 @@ void ImportTextDialog::convertTextFile() {
read_failure_alert_box(import_info_.import_text_filename, errno);
}
if (!wtap_dump_close(import_info_.wdh, &err))
if (!wtap_dump_close(import_info_.wdh, &err, &err_info))
{
cfile_close_failure_alert_box(capfile_name_.toUtf8().constData(), err);
cfile_close_failure_alert_box(capfile_name_.toUtf8().constData(), err, err_info);
}
}

View File

@ -84,12 +84,10 @@ export_pdu_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const
return TAP_PACKET_DONT_REDRAW; /* Do not redraw */
}
int
exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, const char *comment)
gboolean
exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, const char *comment, int *err,
gchar **err_info)
{
int err;
/* pcapng defs */
wtap_block_t shb_hdr;
wtap_block_t int_data;
@ -150,31 +148,29 @@ exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, const char *comment)
};
if (fd == 1) {
exp_pdu_tap_data->wdh = wtap_dump_open_stdout(WTAP_FILE_TYPE_SUBTYPE_PCAPNG,
WTAP_UNCOMPRESSED, &params, &err);
WTAP_UNCOMPRESSED, &params, err, err_info);
} else {
exp_pdu_tap_data->wdh = wtap_dump_fdopen(fd, WTAP_FILE_TYPE_SUBTYPE_PCAPNG,
WTAP_UNCOMPRESSED, &params, &err);
}
if (exp_pdu_tap_data->wdh == NULL) {
g_assert(err != 0);
return err;
WTAP_UNCOMPRESSED, &params, err, err_info);
}
if (exp_pdu_tap_data->wdh == NULL)
return FALSE;
return 0;
return TRUE;
}
int
exp_pdu_close(exp_pdu_t *exp_pdu_tap_data)
gboolean
exp_pdu_close(exp_pdu_t *exp_pdu_tap_data, int *err, gchar **err_info)
{
int err = 0;
if (!wtap_dump_close(exp_pdu_tap_data->wdh, &err))
g_assert(err != 0);
gboolean status;
status = wtap_dump_close(exp_pdu_tap_data->wdh, err, err_info);
wtap_block_array_free(exp_pdu_tap_data->shb_hdrs);
wtap_free_idb_info(exp_pdu_tap_data->idb_inf);
remove_tap_listener(exp_pdu_tap_data);
return err;
return status;
}

View File

@ -39,12 +39,16 @@ char *exp_pdu_pre_open(const char *tap_name, const char *filter,
* Use the given file descriptor for writing an output file. Can only be called
* once and exp_pdu_pre_open() must be called before.
*
* @return 0 on success or a wtap error code.
* @param[out] err Will be set to an error code on failure.
* @param[out] err_info for some errors, a string giving more details of
* the error
* @return TRUE on success or FALSE on failure.
*/
int exp_pdu_open(exp_pdu_t *data, int fd, const char *comment);
gboolean exp_pdu_open(exp_pdu_t *data, int fd, const char *comment, int *err,
gchar **err_info);
/* Stops the PDUs export. */
int exp_pdu_close(exp_pdu_t *exp_pdu_tap_data);
gboolean exp_pdu_close(exp_pdu_t *exp_pdu_tap_data, int *err, gchar **err_info);
#ifdef __cplusplus
}

View File

@ -93,7 +93,7 @@ static int _5views_read_header(wtap *wth, FILE_T fh, t_5VW_TimeStamped_Header *h
wtap_rec *rec, int *err, gchar **err_info);
static gboolean _5views_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info);
static gboolean _5views_dump_finish(wtap_dumper *wdh, int *err);
static gboolean _5views_dump_finish(wtap_dumper *wdh, int *err, gchar **err_info);
wtap_open_return_val
@ -321,7 +321,7 @@ int _5views_dump_can_write_encap(int encap)
/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on
failure */
gboolean _5views_dump_open(wtap_dumper *wdh, int *err)
gboolean _5views_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_)
{
_5views_dump_t *_5views;
@ -401,7 +401,7 @@ static gboolean _5views_dump(wtap_dumper *wdh,
return TRUE;
}
static gboolean _5views_dump_finish(wtap_dumper *wdh, int *err)
static gboolean _5views_dump_finish(wtap_dumper *wdh, int *err, gchar **err_info _U_)
{
_5views_dump_t *_5views = (_5views_dump_t *)wdh->priv;
t_5VW_Capture_Header file_hdr;

View File

@ -12,7 +12,7 @@
#include "wtap.h"
wtap_open_return_val _5views_open(wtap *wth, int *err, gchar **err_info);
gboolean _5views_dump_open(wtap_dumper *wdh, int *err);
gboolean _5views_dump_open(wtap_dumper *wdh, int *err, gchar **err_info);
int _5views_dump_can_write_encap(int encap);
#endif

View File

@ -409,7 +409,7 @@ static gboolean btsnoop_dump_h4(wtap_dumper *wdh,
}
/* FIXME: How do we support multiple backends?*/
gboolean btsnoop_dump_open_h1(wtap_dumper *wdh, int *err)
gboolean btsnoop_dump_open_h1(wtap_dumper *wdh, int *err, gchar **err_info _U_)
{
struct btsnoop_hdr file_hdr;
@ -437,7 +437,7 @@ gboolean btsnoop_dump_open_h1(wtap_dumper *wdh, int *err)
/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on
failure */
gboolean btsnoop_dump_open_h4(wtap_dumper *wdh, int *err)
gboolean btsnoop_dump_open_h4(wtap_dumper *wdh, int *err, gchar **err_info _U_)
{
struct btsnoop_hdr file_hdr;

View File

@ -12,8 +12,8 @@
#include "ws_symbol_export.h"
wtap_open_return_val btsnoop_open(wtap *wth, int *err, gchar **err_info);
gboolean btsnoop_dump_open_h1(wtap_dumper *wdh, int *err);
gboolean btsnoop_dump_open_h4(wtap_dumper *wdh, int *err);
gboolean btsnoop_dump_open_h1(wtap_dumper *wdh, int *err, gchar **err_info);
gboolean btsnoop_dump_open_h4(wtap_dumper *wdh, int *err, gchar **err_info);
int btsnoop_dump_can_write_encap(int encap);
#endif

View File

@ -313,19 +313,19 @@ read_packet_data(FILE_T fh, guint8 dat_trans_type, guint8 *buf, guint16 dat_len,
/* create a DVB-CI pseudo header
return its length or -1 for error */
static gint
create_pseudo_hdr(guint8 *buf, guint8 dat_trans_type, guint16 dat_len)
create_pseudo_hdr(guint8 *buf, guint8 dat_trans_type, guint16 dat_len,
gchar **err_info)
{
if (!buf)
return -1;
buf[0] = DVB_CI_PSEUDO_HDR_VER;
if (dat_trans_type==TRANS_CAM_HOST)
buf[1] = DVB_CI_PSEUDO_HDR_CAM_TO_HOST;
else if (dat_trans_type==TRANS_HOST_CAM)
buf[1] = DVB_CI_PSEUDO_HDR_HOST_TO_CAM;
else
else {
*err_info = g_strdup_printf("camins: invalid dat_trans_type %u", dat_trans_type);
return -1;
}
buf[2] = (dat_len>>8) & 0xFF;
buf[3] = dat_len & 0xFF;
@ -355,12 +355,12 @@ camins_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf,
ws_buffer_assure_space(buf, DVB_CI_PSEUDO_HDR_LEN+dat_len);
p = ws_buffer_start_ptr(buf);
/* NULL check for p is done in create_pseudo_hdr() */
offset = create_pseudo_hdr(p, dat_trans_type, dat_len);
offset = create_pseudo_hdr(p, dat_trans_type, dat_len, err_info);
if (offset<0) {
/* shouldn't happen, all invalid packets must be detected by
find_next_pkt_info() */
*err = WTAP_ERR_INTERNAL;
/* create_pseudo_hdr() set err_info appropriately */
return FALSE;
}

View File

@ -365,6 +365,7 @@ capsa_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec,
default:
g_assert_not_reached();
*err = WTAP_ERR_INTERNAL;
*err_info = g_strdup_printf("capsa: format indicator is %u", capsa->format_indicator);
return -1;
}
if (orig_size > WTAP_MAX_PACKET_SIZE_STANDARD) {

View File

@ -542,7 +542,7 @@ typedef struct {
/* Set other dump callbacks. */
/*****************************************************/
gboolean
catapult_dct2000_dump_open(wtap_dumper *wdh, int *err _U_)
catapult_dct2000_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_)
{
/* Fill in other dump callbacks */
wdh->subtype_write = catapult_dct2000_dump;

View File

@ -13,7 +13,7 @@
#include "ws_symbol_export.h"
wtap_open_return_val catapult_dct2000_open(wtap *wth, int *err, gchar **err_info);
gboolean catapult_dct2000_dump_open(wtap_dumper *wdh, int *err);
gboolean catapult_dct2000_dump_open(wtap_dumper *wdh, int *err, gchar **err_info);
int catapult_dct2000_dump_can_write_encap(int encap);
#define DCT2000_ENCAP_UNHANDLED 0

View File

@ -375,7 +375,7 @@ int commview_dump_can_write_encap(int encap)
/* Returns TRUE on success, FALSE on failure;
sets "*err" to an error code on failure */
gboolean commview_dump_open(wtap_dumper *wdh, int *err _U_)
gboolean commview_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_)
{
wdh->subtype_write = commview_dump;

View File

@ -12,9 +12,9 @@
#include <glib.h>
#include "ws_symbol_export.h"
wtap_open_return_val commview_open(wtap *wth, int *err, gchar **err_info _U_);
wtap_open_return_val commview_open(wtap *wth, int *err, gchar **err_info);
int commview_dump_can_write_encap(int encap);
gboolean commview_dump_open(wtap_dumper *wdh, int *err);
gboolean commview_dump_open(wtap_dumper *wdh, int *err, gchar **err_info);
#endif /* __COMMVIEW_H__ */

View File

@ -319,7 +319,7 @@ static void erf_meta_tag_free(gpointer data) {
}
static gboolean erf_dump_finish(struct wtap_dumper *wdh, int *err) {
static gboolean erf_dump_finish(struct wtap_dumper *wdh, int *err, gchar **err_info _U_) {
erf_dump_t *dump_priv = (erf_dump_t*)wdh->priv;
gboolean ret = TRUE;
@ -2020,7 +2020,7 @@ int erf_dump_can_write_encap(int encap)
return 0;
}
int erf_dump_open(wtap_dumper *wdh, int *err _U_)
int erf_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_)
{
erf_dump_t *dump_priv;
gchar *s;

View File

@ -42,7 +42,7 @@ struct erf_private {
wtap_open_return_val erf_open(wtap *wth, int *err, gchar **err_info);
int erf_dump_can_write_encap(int encap);
int erf_dump_open(wtap_dumper *wdh, int *err);
int erf_dump_open(wtap_dumper *wdh, int *err, gchar **err_info);
#endif /* __W_ERF_H__ */

View File

@ -338,7 +338,7 @@ static gboolean eyesdn_dump(wtap_dumper *wdh,
const wtap_rec *rec,
const guint8 *pd, int *err, gchar **err_info);
gboolean eyesdn_dump_open(wtap_dumper *wdh, int *err)
gboolean eyesdn_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_)
{
wdh->subtype_write=eyesdn_dump;

View File

@ -28,7 +28,7 @@ enum EyeSDN_TYPES {
EYESDN_ENCAP_V5_EF
};
gboolean eyesdn_dump_open(wtap_dumper *wdh, int *err);
gboolean eyesdn_dump_open(wtap_dumper *wdh, int *err, gchar **err_info);
int eyesdn_dump_can_write_encap(int encap);
#endif

View File

@ -2271,7 +2271,7 @@ static wtap_dumper* wtap_dump_alloc_wdh(int file_type_subtype, int encap, int sn
wtap_compression_type compression_type,
int *err);
static gboolean wtap_dump_open_finish(wtap_dumper *wdh, int file_type_subtype,
int *err);
int *err, gchar **err_info);
static WFILE_T wtap_dump_file_open(wtap_dumper *wdh, const char *filename);
static WFILE_T wtap_dump_file_fdopen(wtap_dumper *wdh, int fd);
@ -2396,11 +2396,14 @@ wtap_dump_init_dumper(int file_type_subtype, wtap_compression_type compression_t
wtap_dumper *
wtap_dump_open(const char *filename, int file_type_subtype,
wtap_compression_type compression_type, const wtap_dump_params *params,
int *err)
int *err, gchar **err_info)
{
wtap_dumper *wdh;
WFILE_T fh;
*err = 0;
*err_info = NULL;
/* Allocate and initialize a data structure for the output stream. */
wdh = wtap_dump_init_dumper(file_type_subtype, compression_type, params,
err);
@ -2418,7 +2421,7 @@ wtap_dump_open(const char *filename, int file_type_subtype,
}
wdh->fh = fh;
if (!wtap_dump_open_finish(wdh, file_type_subtype, err)) {
if (!wtap_dump_open_finish(wdh, file_type_subtype, err, err_info)) {
/* Get rid of the file we created; we couldn't finish
opening it. */
wtap_dump_file_close(wdh);
@ -2432,7 +2435,7 @@ wtap_dump_open(const char *filename, int file_type_subtype,
wtap_dumper *
wtap_dump_open_tempfile(char **filenamep, const char *pfx,
int file_type_subtype, wtap_compression_type compression_type,
const wtap_dump_params *params, int *err)
const wtap_dump_params *params, int *err, gchar **err_info)
{
int fd;
const char *ext;
@ -2443,6 +2446,9 @@ wtap_dump_open_tempfile(char **filenamep, const char *pfx,
/* No path name for the temporary file yet. */
*filenamep = NULL;
*err = 0;
*err_info = NULL;
/* Allocate and initialize a data structure for the output stream. */
wdh = wtap_dump_init_dumper(file_type_subtype, compression_type, params,
err);
@ -2477,7 +2483,7 @@ wtap_dump_open_tempfile(char **filenamep, const char *pfx,
}
wdh->fh = fh;
if (!wtap_dump_open_finish(wdh, file_type_subtype, err)) {
if (!wtap_dump_open_finish(wdh, file_type_subtype, err, err_info)) {
/* Get rid of the file we created; we couldn't finish
opening it. */
wtap_dump_file_close(wdh);
@ -2490,11 +2496,14 @@ wtap_dump_open_tempfile(char **filenamep, const char *pfx,
wtap_dumper *
wtap_dump_fdopen(int fd, int file_type_subtype, wtap_compression_type compression_type,
const wtap_dump_params *params, int *err)
const wtap_dump_params *params, int *err, gchar **err_info)
{
wtap_dumper *wdh;
WFILE_T fh;
*err = 0;
*err_info = NULL;
/* Allocate and initialize a data structure for the output stream. */
wdh = wtap_dump_init_dumper(file_type_subtype, compression_type, params,
err);
@ -2512,7 +2521,7 @@ wtap_dump_fdopen(int fd, int file_type_subtype, wtap_compression_type compressio
}
wdh->fh = fh;
if (!wtap_dump_open_finish(wdh, file_type_subtype, err)) {
if (!wtap_dump_open_finish(wdh, file_type_subtype, err, err_info)) {
wtap_dump_file_close(wdh);
g_free(wdh);
return NULL;
@ -2522,7 +2531,7 @@ wtap_dump_fdopen(int fd, int file_type_subtype, wtap_compression_type compressio
wtap_dumper *
wtap_dump_open_stdout(int file_type_subtype, wtap_compression_type compression_type,
const wtap_dump_params *params, int *err)
const wtap_dump_params *params, int *err, gchar **err_info)
{
int new_fd;
wtap_dumper *wdh;
@ -2554,7 +2563,7 @@ wtap_dump_open_stdout(int file_type_subtype, wtap_compression_type compression_t
#endif
wdh = wtap_dump_fdopen(new_fd, file_type_subtype, compression_type,
params, err);
params, err, err_info);
if (wdh == NULL) {
/* Failed; close the new FD */
ws_close(new_fd);
@ -2619,7 +2628,8 @@ wtap_dump_alloc_wdh(int file_type_subtype, int encap, int snaplen,
}
static gboolean
wtap_dump_open_finish(wtap_dumper *wdh, int file_type_subtype, int *err)
wtap_dump_open_finish(wtap_dumper *wdh, int file_type_subtype, int *err,
gchar **err_info)
{
int fd;
gboolean cant_seek;
@ -2652,7 +2662,8 @@ wtap_dump_open_finish(wtap_dumper *wdh, int file_type_subtype, int *err)
wdh->wslua_data = dump_open_table[file_type_subtype].wslua_info->wslua_data;
/* Now try to open the file for writing. */
if (!(*dump_open_table[file_type_subtype].dump_open)(wdh, err)) {
if (!(*dump_open_table[file_type_subtype].dump_open)(wdh, err,
err_info)) {
return FALSE;
}
@ -2689,13 +2700,15 @@ wtap_dump_flush(wtap_dumper *wdh, int *err)
}
gboolean
wtap_dump_close(wtap_dumper *wdh, int *err)
wtap_dump_close(wtap_dumper *wdh, int *err, gchar **err_info)
{
gboolean ret = TRUE;
*err = 0;
*err_info = NULL;
if (wdh->subtype_finish != NULL) {
/* There's a finish routine for this dump stream. */
if (!(wdh->subtype_finish)(wdh, err))
if (!(wdh->subtype_finish)(wdh, err, err_info))
ret = FALSE;
}
errno = WTAP_ERR_CANT_CLOSE;

View File

@ -1670,14 +1670,15 @@ file_close(FILE_T file)
struct wtap_writer {
int fd; /* file descriptor */
gint64 pos; /* current position in uncompressed data */
guint size; /* buffer size, zero if not allocated yet */
guint want; /* requested buffer size, default is GZBUFSIZE */
guint size; /* buffer size, zero if not allocated yet */
guint want; /* requested buffer size, default is GZBUFSIZE */
unsigned char *in; /* input buffer */
unsigned char *out; /* output buffer (double-sized when reading) */
unsigned char *next; /* next output data to deliver or write */
int level; /* compression level */
int strategy; /* compression strategy */
int err; /* error code */
const char *err_info; /* additional error information string for some errors */
/* zlib deflate stream */
z_stream strm; /* stream structure in-place (not a pointer) */
};
@ -1719,6 +1720,7 @@ gzwfile_fdopen(int fd)
/* initialize stream */
state->err = Z_OK; /* clear error */
state->err_info = NULL; /* clear additional error information */
state->pos = 0; /* no uncompressed data yet */
state->strm.avail_in = 0; /* no input data yet */
@ -1727,8 +1729,8 @@ gzwfile_fdopen(int fd)
}
/* Initialize state for writing a gzip file. Mark initialization by setting
state->size to non-zero. Return -1, and set state->err, on failure;
return 0 on success. */
state->size to non-zero. Return -1, and set state->err and possibly
state->err_info, on failure; return 0 on success. */
static int
gz_init(GZWFILE_T state)
{
@ -1760,6 +1762,7 @@ gz_init(GZWFILE_T state)
} else {
/* This "shouldn't happen". */
state->err = WTAP_ERR_INTERNAL;
state->err_info = "Unknown error from deflateInit2()";
}
return -1;
}
@ -1775,8 +1778,8 @@ gz_init(GZWFILE_T state)
}
/* Compress whatever is at avail_in and next_in and write to the output file.
Return -1, and set state->err, if there is an error writing to the output
file; return 0 on success.
Return -1, and set state->err and possibly state->err_info, if there is
an error writing to the output file; return 0 on success.
flush is assumed to be a valid deflate() flush value. If flush is Z_FINISH,
then the deflate() state is reset to start a new gzip stream. */
static int
@ -1823,6 +1826,7 @@ gz_comp(GZWFILE_T state, int flush)
if (ret == Z_STREAM_ERROR) {
/* This "shouldn't happen". */
state->err = WTAP_ERR_INTERNAL;
state->err_info = "Z_STREAM_ERROR from deflate()";
return -1;
}
have -= strm->avail_out;

View File

@ -1320,7 +1320,7 @@ static gboolean k12_dump(wtap_dumper *wdh, const wtap_rec *rec,
static const guint8 k12_eof[] = {0xff,0xff};
static gboolean k12_dump_finish(wtap_dumper *wdh, int *err) {
static gboolean k12_dump_finish(wtap_dumper *wdh, int *err, gchar **err_info _U_) {
k12_dump_t *k12 = (k12_dump_t *)wdh->priv;
union {
guint8 b[sizeof(guint32)];
@ -1367,7 +1367,7 @@ static gboolean k12_dump_finish(wtap_dumper *wdh, int *err) {
}
gboolean k12_dump_open(wtap_dumper *wdh, int *err) {
gboolean k12_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_) {
k12_dump_t *k12;
if ( ! wtap_dump_file_write(wdh, k12_file_magic, 8, err)) {

View File

@ -14,10 +14,10 @@
wtap_open_return_val k12_open(wtap *wth, int *err, gchar **err_info);
int k12_dump_can_write_encap(int encap);
gboolean k12_dump_open(wtap_dumper *wdh, int *err);
wtap_open_return_val k12text_open(wtap *wth, int *err, gchar **err_info _U_);
gboolean k12_dump_open(wtap_dumper *wdh, int *err, gchar **err_info);
wtap_open_return_val k12text_open(wtap *wth, int *err, gchar **err_info);
int k12text_dump_can_write_encap(int encap);
gboolean k12text_dump_open(wtap_dumper *wdh, int *err);
gboolean k12text_dump_open(wtap_dumper *wdh, int *err, gchar **err_info);
#endif

View File

@ -549,7 +549,7 @@ k12text_dump(wtap_dumper *wdh, const wtap_rec *rec,
gboolean
k12text_dump_open(wtap_dumper *wdh, int *err _U_)
k12text_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_)
{
wdh->subtype_write = k12text_dump;

View File

@ -262,7 +262,8 @@ static gboolean lanalyzer_read(wtap *wth, wtap_rec *rec,
Buffer *buf, int *err, gchar **err_info, gint64 *data_offset);
static gboolean lanalyzer_seek_read(wtap *wth, gint64 seek_off,
wtap_rec *rec, Buffer *buf, int *err, gchar **err_info);
static gboolean lanalyzer_dump_finish(wtap_dumper *wdh, int *err);
static gboolean lanalyzer_dump_finish(wtap_dumper *wdh, int *err,
gchar **err_info);
wtap_open_return_val lanalyzer_open(wtap *wth, int *err, gchar **err_info)
{
@ -786,7 +787,7 @@ int lanalyzer_dump_can_write_encap(int encap)
* Returns TRUE on success, FALSE on failure; sets "*err" to an
* error code on failure
*---------------------------------------------------*/
gboolean lanalyzer_dump_open(wtap_dumper *wdh, int *err)
gboolean lanalyzer_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_)
{
int jump;
void *tmp;
@ -952,7 +953,8 @@ static gboolean lanalyzer_dump_header(wtap_dumper *wdh, int *err)
* Finish writing to a dump file.
* Returns TRUE on success, FALSE on failure.
*---------------------------------------------------*/
static gboolean lanalyzer_dump_finish(wtap_dumper *wdh, int *err)
static gboolean lanalyzer_dump_finish(wtap_dumper *wdh, int *err,
gchar **err_info _U_)
{
lanalyzer_dump_header(wdh,err);
return *err ? FALSE : TRUE;

View File

@ -13,7 +13,7 @@
#include "wtap.h"
wtap_open_return_val lanalyzer_open(wtap *wth, int *err, gchar **err_info);
gboolean lanalyzer_dump_open(wtap_dumper *wdh, int *err);
gboolean lanalyzer_dump_open(wtap_dumper *wdh, int *err, gchar **err_info);
int lanalyzer_dump_can_write_encap(int encap);
#endif

View File

@ -952,7 +952,7 @@ int libpcap_dump_can_write_encap(int encap)
/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on
failure */
gboolean libpcap_dump_open(wtap_dumper *wdh, int *err)
gboolean libpcap_dump_open(wtap_dumper *wdh, int *err, gchar **err_info)
{
guint32 magic;
struct pcap_hdr file_hdr;
@ -981,7 +981,9 @@ gboolean libpcap_dump_open(wtap_dumper *wdh, int *err)
default:
/* We should never get here - our open routine
should only get called for the types above. */
*err = WTAP_ERR_UNWRITABLE_FILE_TYPE;
*err = WTAP_ERR_INTERNAL;
*err_info = g_strdup_printf("libpcap: invalid file type/subtype %u",
wdh->file_type_subtype);
return FALSE;
}

View File

@ -97,7 +97,7 @@ struct pcaprec_nokia_hdr {
};
wtap_open_return_val libpcap_open(wtap *wth, int *err, gchar **err_info);
gboolean libpcap_dump_open(wtap_dumper *wdh, int *err);
gboolean libpcap_dump_open(wtap_dumper *wdh, int *err, gchar **err_info);
int libpcap_dump_can_write_encap(int encap);
#endif

View File

@ -352,7 +352,8 @@ static gboolean logcat_binary_dump(wtap_dumper *wdh,
return TRUE;
}
gboolean logcat_binary_dump_open(wtap_dumper *wdh, int *err _U_)
gboolean logcat_binary_dump_open(wtap_dumper *wdh, int *err _U_,
gchar **err_info _U_)
{
wdh->subtype_write = logcat_binary_dump;

View File

@ -47,7 +47,7 @@ struct logger_entry_v2 {
wtap_open_return_val logcat_open(wtap *wth, int *err, gchar **err_info);
gboolean logcat_binary_dump_open(wtap_dumper *wdh, int *err);
gboolean logcat_binary_dump_open(wtap_dumper *wdh, int *err, gchar **err_info);
int logcat_dump_can_write_encap(int encap);

View File

@ -578,7 +578,7 @@ static gboolean logcat_text_dump_text(wtap_dumper *wdh,
return TRUE;
}
static gboolean logcat_text_dump_open(wtap_dumper *wdh, guint dump_type, int *err _U_) {
static gboolean logcat_text_dump_open(wtap_dumper *wdh, guint dump_type) {
struct dumper_t *dumper;
dumper = (struct dumper_t *) g_malloc(sizeof(struct dumper_t));
@ -590,32 +590,32 @@ static gboolean logcat_text_dump_open(wtap_dumper *wdh, guint dump_type, int *er
return TRUE;
}
gboolean logcat_text_brief_dump_open(wtap_dumper *wdh, int *err) {
return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_BRIEF, err);
gboolean logcat_text_brief_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) {
return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_BRIEF);
}
gboolean logcat_text_process_dump_open(wtap_dumper *wdh, int *err) {
return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_PROCESS, err);
gboolean logcat_text_process_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) {
return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_PROCESS);
}
gboolean logcat_text_tag_dump_open(wtap_dumper *wdh, int *err) {
return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_TAG, err);
gboolean logcat_text_tag_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) {
return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_TAG);
}
gboolean logcat_text_time_dump_open(wtap_dumper *wdh, int *err) {
return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_TIME, err);
gboolean logcat_text_time_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) {
return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_TIME);
}
gboolean logcat_text_thread_dump_open(wtap_dumper *wdh, int *err) {
return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_THREAD, err);
gboolean logcat_text_thread_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) {
return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_THREAD);
}
gboolean logcat_text_threadtime_dump_open(wtap_dumper *wdh, int *err) {
return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_THREADTIME, err);
gboolean logcat_text_threadtime_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) {
return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_THREADTIME);
}
gboolean logcat_text_long_dump_open(wtap_dumper *wdh, int *err) {
return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_LONG, err);
gboolean logcat_text_long_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) {
return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_LONG);
}
/*

View File

@ -24,13 +24,13 @@
wtap_open_return_val logcat_text_open(wtap *wth, int *err, gchar **err_info);
gboolean logcat_text_brief_dump_open(wtap_dumper *wdh, int *err);
gboolean logcat_text_process_dump_open(wtap_dumper *wdh, int *err);
gboolean logcat_text_tag_dump_open(wtap_dumper *wdh, int *err);
gboolean logcat_text_time_dump_open(wtap_dumper *wdh, int *err);
gboolean logcat_text_thread_dump_open(wtap_dumper *wdh, int *err);
gboolean logcat_text_threadtime_dump_open(wtap_dumper *wdh, int *err);
gboolean logcat_text_long_dump_open(wtap_dumper *wdh, int *err);
gboolean logcat_text_brief_dump_open(wtap_dumper *wdh, int *err, gchar **err_info);
gboolean logcat_text_process_dump_open(wtap_dumper *wdh, int *err, gchar **err_info);
gboolean logcat_text_tag_dump_open(wtap_dumper *wdh, int *err, gchar **err_info);
gboolean logcat_text_time_dump_open(wtap_dumper *wdh, int *err, gchar **err_info);
gboolean logcat_text_thread_dump_open(wtap_dumper *wdh, int *err, gchar **err_info);
gboolean logcat_text_threadtime_dump_open(wtap_dumper *wdh, int *err, gchar **err_info);
gboolean logcat_text_long_dump_open(wtap_dumper *wdh, int *err, gchar **err_info);
int logcat_text_brief_dump_can_write_encap(int encap);
int logcat_text_tag_dump_can_write_encap(int encap);

View File

@ -946,7 +946,7 @@ merge_process_packets(wtap_dumper *pdh, const int file_type,
cb->callback_func(MERGE_EVENT_DONE, count, in_files, in_file_count, cb->data);
if (status == MERGE_OK || status == MERGE_USER_ABORTED) {
if (!wtap_dump_close(pdh, err))
if (!wtap_dump_close(pdh, err, err_info))
status = MERGE_ERR_CANT_CLOSE_OUTFILE;
} else {
/*
@ -956,7 +956,9 @@ merge_process_packets(wtap_dumper *pdh, const int file_type,
* Don't overwrite the earlier error.
*/
int close_err = 0;
(void)wtap_dump_close(pdh, &close_err);
gchar *close_err_info = NULL;
(void)wtap_dump_close(pdh, &close_err, &close_err_info);
g_free(close_err_info);
}
/* Close the input files after the output file in case the latter still
@ -1050,12 +1052,15 @@ merge_files_common(const gchar* out_filename, /* normal output mode */
params.dsbs_growing = dsb_combined;
}
if (out_filename) {
pdh = wtap_dump_open(out_filename, file_type, WTAP_UNCOMPRESSED, &params, err);
pdh = wtap_dump_open(out_filename, file_type, WTAP_UNCOMPRESSED,
&params, err, err_info);
} else if (out_filenamep) {
pdh = wtap_dump_open_tempfile(out_filenamep, pfx, file_type,
WTAP_UNCOMPRESSED, &params, err);
WTAP_UNCOMPRESSED, &params, err,
err_info);
} else {
pdh = wtap_dump_open_stdout(file_type, WTAP_UNCOMPRESSED, &params, err);
pdh = wtap_dump_open_stdout(file_type, WTAP_UNCOMPRESSED, &params, err,
err_info);
}
if (pdh == NULL) {
merge_close_in_files(in_file_count, in_files);

View File

@ -224,7 +224,8 @@ static gboolean netmon_read_atm_pseudoheader(FILE_T fh,
static void netmon_close(wtap *wth);
static gboolean netmon_dump(wtap_dumper *wdh, const wtap_rec *rec,
const guint8 *pd, int *err, gchar **err_info);
static gboolean netmon_dump_finish(wtap_dumper *wdh, int *err);
static gboolean netmon_dump_finish(wtap_dumper *wdh, int *err,
gchar **err_info);
/*
* Convert a counted UTF-16 string, which is probably also null-terminated
@ -1618,7 +1619,7 @@ int netmon_dump_can_write_encap_2_x(int encap)
/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on
failure */
gboolean netmon_dump_open(wtap_dumper *wdh, int *err)
gboolean netmon_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_)
{
netmon_dump_t *netmon;
@ -1893,7 +1894,8 @@ static gboolean netmon_dump(wtap_dumper *wdh, const wtap_rec *rec,
/* Finish writing to a dump file.
Returns TRUE on success, FALSE on failure. */
static gboolean netmon_dump_finish(wtap_dumper *wdh, int *err)
static gboolean netmon_dump_finish(wtap_dumper *wdh, int *err,
gchar **err_info _U_)
{
netmon_dump_t *netmon = (netmon_dump_t *)wdh->priv;
size_t n_to_write;

View File

@ -13,7 +13,7 @@
#include "wtap.h"
wtap_open_return_val netmon_open(wtap *wth, int *err, gchar **err_info);
gboolean netmon_dump_open(wtap_dumper *wdh, int *err);
gboolean netmon_dump_open(wtap_dumper *wdh, int *err, gchar **err_info);
int netmon_dump_can_write_encap_1_x(int encap);
int netmon_dump_can_write_encap_2_x(int encap);

View File

@ -2039,7 +2039,7 @@ int nstrace_35_dump_can_write_encap(int encap)
/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on
** failure */
gboolean nstrace_dump_open(wtap_dumper *wdh, int *err _U_)
gboolean nstrace_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_)
{
nstrace_dump_t *nstrace;

View File

@ -113,7 +113,7 @@ int nstrace_20_dump_can_write_encap(int encap);
int nstrace_30_dump_can_write_encap(int encap);
int nstrace_35_dump_can_write_encap(int encap);
gboolean nstrace_dump_open(wtap_dumper *wdh, int *err);
gboolean nstrace_dump_open(wtap_dumper *wdh, int *err, char **err_info);
#endif /* _NETSCALER_H */

View File

@ -642,7 +642,7 @@ int nettl_dump_can_write_encap(int encap)
/* Returns TRUE on success, FALSE on failure;
sets "*err" to an error code on failure */
gboolean nettl_dump_open(wtap_dumper *wdh, int *err)
gboolean nettl_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_)
{
struct nettl_file_hdr file_hdr;

View File

@ -117,7 +117,7 @@
#define NETTL_HDR_PDU_MASK 0x30000000
wtap_open_return_val nettl_open(wtap *wth, int *err, gchar **err_info);
gboolean nettl_dump_open(wtap_dumper *wdh, int *err);
gboolean nettl_dump_open(wtap_dumper *wdh, int *err, gchar **err_info);
int nettl_dump_can_write_encap(int encap);
#endif

View File

@ -819,7 +819,6 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_
{
int import_file_fd;
wtap_dumper* wdh_exp_pdu;
int exp_pdu_file_err;
wtap_open_return_val result = WTAP_OPEN_MINE;
/* pcapng defs */
@ -832,8 +831,6 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_
gint64 file_size;
int packet_size;
char *packet_buf = NULL;
int wrt_err;
gchar *wrt_err_info = NULL;
wtap_rec rec;
nstime_t start_time, packet_time;
int scan_found;
@ -907,7 +904,7 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_
};
wdh_exp_pdu = wtap_dump_fdopen(import_file_fd, WTAP_FILE_TYPE_SUBTYPE_PCAPNG,
WTAP_UNCOMPRESSED, &params,
&exp_pdu_file_err);
err, err_info);
if (wdh_exp_pdu == NULL) {
result = WTAP_OPEN_ERROR;
goto end;
@ -954,7 +951,7 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_
packet_buf[10] = 0;
packet_buf[11] = 0;
if (!wtap_read_bytes(wth->fh, packet_buf + 12, packet_size, &wrt_err, &wrt_err_info)){
if (!wtap_read_bytes(wth->fh, packet_buf + 12, packet_size, err, err_info)){
result = WTAP_OPEN_ERROR;
goto end;
}
@ -1001,15 +998,7 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_
rec.rec_header.packet_header.len = packet_size + 12;
/* XXX: report errors! */
if (!wtap_dump(wdh_exp_pdu, &rec, packet_buf, &wrt_err, &wrt_err_info)) {
switch (wrt_err) {
case WTAP_ERR_UNWRITABLE_REC_DATA:
break;
default:
break;
}
if (!wtap_dump(wdh_exp_pdu, &rec, packet_buf, err, err_info)) {
result = WTAP_OPEN_ERROR;
goto end;
}
@ -1138,18 +1127,16 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_
curr_pos = raw_msg_pos;
curr_pos = curr_pos + 7;
/* Add the raw msg*/
temp_val = write_packet_data(wdh_exp_pdu, &rec, &wrt_err, &wrt_err_info, curr_pos, packet_time, &exported_pdu_info, name_str);
temp_val = write_packet_data(wdh_exp_pdu, &rec, err, err_info, curr_pos, packet_time, &exported_pdu_info, name_str);
if (temp_val != WTAP_OPEN_MINE){
result = temp_val;
*err = wrt_err;
*err_info = g_strdup(wrt_err_info);
goto end;
}
curr_pos = next_msg_pos;
}
/* Close the written file*/
if (!wtap_dump_close(wdh_exp_pdu, err)){
if (!wtap_dump_close(wdh_exp_pdu, err, err_info)){
result = WTAP_OPEN_ERROR;
goto end;
}
@ -1169,7 +1156,6 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_
}
end:
g_free(wrt_err_info);
g_free(packet_buf);
wtap_block_array_free(shb_hdrs);
wtap_free_idb_info(idb_inf);

View File

@ -126,6 +126,7 @@ wtap_open_return_val network_instruments_open(wtap *wth, int *err, gchar **err_i
guint seek_increment;
packet_entry_header packet_header;
observer_dump_private_state * private_state = NULL;
const char *err_str;
offset = 0;
@ -299,15 +300,10 @@ wtap_open_return_val network_instruments_open(wtap *wth, int *err, gchar **err_i
if (file_seek(wth->fh, header_offset, SEEK_SET, err) == -1)
return WTAP_OPEN_ERROR;
if (init_gmt_to_localtime_offset() != NULL) {
err_str = init_gmt_to_localtime_offset();
if (err_str != NULL) {
*err = WTAP_ERR_INTERNAL;
/*
* XXX - we should return the error string, so the caller
* can report the details of the internal error, but that
* would require plugin file readers to do so for internal
* errors as well, which could break binary compatibility;
* we'll do that in the next release.
*/
*err_info = g_strdup_printf("network_instruments: %s", err_str);
return WTAP_OPEN_ERROR;
}
@ -664,11 +660,13 @@ int network_instruments_dump_can_write_encap(int encap)
/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on
failure. */
gboolean network_instruments_dump_open(wtap_dumper *wdh, int *err)
gboolean network_instruments_dump_open(wtap_dumper *wdh, int *err,
gchar **err_info)
{
observer_dump_private_state * private_state = NULL;
capture_file_header file_header;
guint header_offset;
const gchar *err_str;
tlv_header comment_header;
tlv_time_info time_header;
char comment[64];
@ -755,7 +753,12 @@ gboolean network_instruments_dump_open(wtap_dumper *wdh, int *err)
wdh->bytes_dumped += sizeof(time_header);
}
init_gmt_to_localtime_offset();
err_str = init_gmt_to_localtime_offset();
if (err_str != NULL) {
*err = WTAP_ERR_INTERNAL;
*err_info = g_strdup_printf("network_instruments: %s", err_str);
return FALSE;
}
return TRUE;
}

View File

@ -20,7 +20,7 @@
wtap_open_return_val network_instruments_open(wtap *wth, int *err, gchar **err_info);
int network_instruments_dump_can_write_encap(int encap);
gboolean network_instruments_dump_open(wtap_dumper *wdh, int *err);
gboolean network_instruments_dump_open(wtap_dumper *wdh, int *err, gchar **err_info);
/*
* In v15 the high_byte was added to allow a larger offset This was done by

View File

@ -400,11 +400,13 @@ static void netxray_guess_atm_type(wtap *wth, wtap_rec *rec,
static gboolean netxray_dump_1_1(wtap_dumper *wdh,
const wtap_rec *rec,
const guint8 *pd, int *err, gchar **err_info);
static gboolean netxray_dump_finish_1_1(wtap_dumper *wdh, int *err);
static gboolean netxray_dump_finish_1_1(wtap_dumper *wdh, int *err,
gchar **err_info);
static gboolean netxray_dump_2_0(wtap_dumper *wdh,
const wtap_rec *rec,
const guint8 *pd, int *err, gchar **err_info);
static gboolean netxray_dump_finish_2_0(wtap_dumper *wdh, int *err);
static gboolean netxray_dump_finish_2_0(wtap_dumper *wdh, int *err,
gchar **err_info);
wtap_open_return_val
netxray_open(wtap *wth, int *err, gchar **err_info)
@ -1697,7 +1699,7 @@ netxray_dump_can_write_encap_1_1(int encap)
/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on
failure */
gboolean
netxray_dump_open_1_1(wtap_dumper *wdh, int *err)
netxray_dump_open_1_1(wtap_dumper *wdh, int *err, gchar **err_info _U_)
{
netxray_dump_t *netxray;
@ -1799,7 +1801,7 @@ netxray_dump_1_1(wtap_dumper *wdh,
/* Finish writing to a dump file.
Returns TRUE on success, FALSE on failure. */
static gboolean
netxray_dump_finish_1_1(wtap_dumper *wdh, int *err)
netxray_dump_finish_1_1(wtap_dumper *wdh, int *err, gchar **err_info _U_)
{
char hdr_buf[CAPTUREFILE_HEADER_SIZE - sizeof(netxray_magic)];
netxray_dump_t *netxray = (netxray_dump_t *)wdh->priv;
@ -1883,7 +1885,7 @@ netxray_dump_can_write_encap_2_0(int encap)
/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on
failure */
gboolean
netxray_dump_open_2_0(wtap_dumper *wdh, int *err)
netxray_dump_open_2_0(wtap_dumper *wdh, int *err, gchar **err_info _U_)
{
netxray_dump_t *netxray;
@ -2017,7 +2019,7 @@ netxray_dump_2_0(wtap_dumper *wdh,
/* Finish writing to a dump file.
Returns TRUE on success, FALSE on failure. */
static gboolean
netxray_dump_finish_2_0(wtap_dumper *wdh, int *err)
netxray_dump_finish_2_0(wtap_dumper *wdh, int *err, gchar **err_info _U_)
{
char hdr_buf[CAPTUREFILE_HEADER_SIZE - sizeof(netxray_magic)];
netxray_dump_t *netxray = (netxray_dump_t *)wdh->priv;

View File

@ -14,8 +14,8 @@
wtap_open_return_val netxray_open(wtap *wth, int *err, gchar **err_info);
int netxray_dump_can_write_encap_1_1(int encap);
gboolean netxray_dump_open_1_1(wtap_dumper *wdh, int *err);
gboolean netxray_dump_open_1_1(wtap_dumper *wdh, int *err, gchar **err_info);
int netxray_dump_can_write_encap_2_0(int encap);
gboolean netxray_dump_open_2_0(wtap_dumper *wdh, int *err);
gboolean netxray_dump_open_2_0(wtap_dumper *wdh, int *err, gchar **err_info);
#endif

View File

@ -515,7 +515,8 @@ static void ngsniffer_sequential_close(wtap *wth);
static void ngsniffer_close(wtap *wth);
static gboolean ngsniffer_dump(wtap_dumper *wdh, const wtap_rec *rec,
const guint8 *pd, int *err, gchar **err_info);
static gboolean ngsniffer_dump_finish(wtap_dumper *wdh, int *err);
static gboolean ngsniffer_dump_finish(wtap_dumper *wdh, int *err,
gchar **err_info);
static int SnifferDecompress( unsigned char * inbuf, size_t inlen,
unsigned char * outbuf, size_t outlen, int *err, gchar **err_info );
static gboolean ng_read_bytes_or_eof(wtap *wth, void *buffer,
@ -2020,7 +2021,7 @@ ngsniffer_dump_can_write_encap(int encap)
/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on
failure */
gboolean
ngsniffer_dump_open(wtap_dumper *wdh, int *err)
ngsniffer_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_)
{
ngsniffer_dump_t *ngsniffer;
char buf[6] = {REC_VERS, 0x00, 0x12, 0x00, 0x00, 0x00}; /* version record */
@ -2194,7 +2195,7 @@ ngsniffer_dump(wtap_dumper *wdh, const wtap_rec *rec,
/* Finish writing to a dump file.
Returns TRUE on success, FALSE on failure. */
static gboolean
ngsniffer_dump_finish(wtap_dumper *wdh, int *err)
ngsniffer_dump_finish(wtap_dumper *wdh, int *err, gchar **err_info _U_)
{
/* EOF record */
char buf[6] = {REC_EOF, 0x00, 0x00, 0x00, 0x00, 0x00};

View File

@ -13,7 +13,7 @@
#include "wtap.h"
wtap_open_return_val ngsniffer_open(wtap *wth, int *err, gchar **err_info);
gboolean ngsniffer_dump_open(wtap_dumper *wdh, int *err);
gboolean ngsniffer_dump_open(wtap_dumper *wdh, int *err, gchar **err_info);
int ngsniffer_dump_can_write_encap(int encap);
#endif

View File

@ -3445,7 +3445,7 @@ pcapng_write_section_header_block(wtap_dumper *wdh, int *err)
static gboolean
pcapng_write_enhanced_packet_block(wtap_dumper *wdh, const wtap_rec *rec,
const guint8 *pd, int *err)
const guint8 *pd, int *err, gchar **err_info)
{
const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header;
pcapng_block_header_t bh;
@ -3545,6 +3545,8 @@ pcapng_write_enhanced_packet_block(wtap_dumper *wdh, const wtap_rec *rec,
* Our caller is doing something bad.
*/
*err = WTAP_ERR_INTERNAL;
*err_info = g_strdup_printf("pcapng: epb.interface_id (%u) >= wdh->interface_data->len (%u)",
epb.interface_id, wdh->interface_data->len);
return FALSE;
}
int_data = g_array_index(wdh->interface_data, wtap_block_t,
@ -4763,7 +4765,7 @@ pcapng_write_if_descr_block(wtap_dumper *wdh, wtap_block_t int_data, int *err)
static gboolean pcapng_dump(wtap_dumper *wdh,
const wtap_rec *rec,
const guint8 *pd, int *err, gchar **err_info _U_)
const guint8 *pd, int *err, gchar **err_info)
{
#ifdef HAVE_PLUGINS
block_handler *handler;
@ -4796,7 +4798,8 @@ static gboolean pcapng_dump(wtap_dumper *wdh,
* stamp or other information that doesn't appear in an
* SPB?
*/
if (!pcapng_write_enhanced_packet_block(wdh, rec, pd, err)) {
if (!pcapng_write_enhanced_packet_block(wdh, rec, pd, err,
err_info)) {
return FALSE;
}
break;
@ -4846,7 +4849,8 @@ static gboolean pcapng_dump(wtap_dumper *wdh,
/* Finish writing to a dump file.
Returns TRUE on success, FALSE on failure. */
static gboolean pcapng_dump_finish(wtap_dumper *wdh, int *err)
static gboolean pcapng_dump_finish(wtap_dumper *wdh, int *err,
gchar **err_info _U_)
{
guint i, j;
@ -4881,7 +4885,7 @@ static gboolean pcapng_dump_finish(wtap_dumper *wdh, int *err)
/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on
failure */
gboolean
pcapng_dump_open(wtap_dumper *wdh, int *err)
pcapng_dump_open(wtap_dumper *wdh, int *err, gchar **err_info)
{
guint i;
@ -4894,6 +4898,7 @@ pcapng_dump_open(wtap_dumper *wdh, int *err)
if (wdh->interface_data->len == 0) {
pcapng_debug("There are no interfaces. Can't handle that...");
*err = WTAP_ERR_INTERNAL;
*err_info = g_strdup("pcapng: there are no interfaces");
return FALSE;
}

View File

@ -73,7 +73,7 @@ struct pcapng_option_header {
#define MIN_DSB_SIZE ((guint32)(MIN_BLOCK_SIZE + sizeof(pcapng_decryption_secrets_block_t)))
wtap_open_return_val pcapng_open(wtap *wth, int *err, gchar **err_info);
gboolean pcapng_dump_open(wtap_dumper *wdh, int *err);
gboolean pcapng_dump_open(wtap_dumper *wdh, int *err, gchar **err_info);
int pcapng_dump_can_write_encap(int encap);
#endif

View File

@ -786,7 +786,7 @@ int snoop_dump_can_write_encap(int encap)
/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on
failure */
gboolean snoop_dump_open(wtap_dumper *wdh, int *err)
gboolean snoop_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_)
{
struct snoop_hdr file_hdr;

View File

@ -14,7 +14,7 @@
#include "ws_symbol_export.h"
wtap_open_return_val snoop_open(wtap *wth, int *err, gchar **err_info);
gboolean snoop_dump_open(wtap_dumper *wdh, int *err);
gboolean snoop_dump_open(wtap_dumper *wdh, int *err, gchar **err_info);
int snoop_dump_can_write_encap(int encap);
#endif

View File

@ -153,7 +153,8 @@ static gboolean visual_read_packet(wtap *wth, FILE_T fh,
wtap_rec *rec, Buffer *buf, int *err, gchar **err_info);
static gboolean visual_dump(wtap_dumper *wdh, const wtap_rec *rec,
const guint8 *pd, int *err, gchar **err_info);
static gboolean visual_dump_finish(wtap_dumper *wdh, int *err);
static gboolean visual_dump_finish(wtap_dumper *wdh, int *err,
gchar **err_info);
static void visual_dump_free(wtap_dumper *wdh);
@ -601,7 +602,7 @@ int visual_dump_can_write_encap(int encap)
/* Open a file for writing.
Returns TRUE on success, FALSE on failure; sets "*err" to an
error code on failure */
gboolean visual_dump_open(wtap_dumper *wdh, int *err)
gboolean visual_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_)
{
struct visual_write_info *visual;
@ -761,7 +762,8 @@ static gboolean visual_dump(wtap_dumper *wdh, const wtap_rec *rec,
/* Finish writing to a dump file.
Returns TRUE on success, FALSE on failure. */
static gboolean visual_dump_finish(wtap_dumper *wdh, int *err)
static gboolean visual_dump_finish(wtap_dumper *wdh, int *err,
gchar **err_info _U_)
{
struct visual_write_info * visual = (struct visual_write_info *)wdh->priv;
size_t n_to_write;

View File

@ -19,7 +19,7 @@
#include "ws_symbol_export.h"
wtap_open_return_val visual_open(wtap *wth, int *err, gchar **err_info);
gboolean visual_dump_open(wtap_dumper *wdh, int *err);
gboolean visual_dump_open(wtap_dumper *wdh, int *err, gchar **err_info);
int visual_dump_can_write_encap(int encap);
#endif

View File

@ -82,7 +82,7 @@ typedef void *WFILE_T;
typedef gboolean (*subtype_write_func)(struct wtap_dumper*,
const wtap_rec *rec,
const guint8*, int*, gchar**);
typedef gboolean (*subtype_finish_func)(struct wtap_dumper*, int*);
typedef gboolean (*subtype_finish_func)(struct wtap_dumper*, int*, gchar**);
struct wtap_dumper {
WFILE_T fh;

View File

@ -1748,7 +1748,7 @@ struct file_type_subtype_info {
/* the function to open the capture file for writing */
/* should be NULL is this file type don't have write support */
int (*dump_open)(wtap_dumper *, int *);
int (*dump_open)(wtap_dumper *, int *, gchar **);
/* if can_write_encap returned WTAP_ERR_CHECK_WSLUA, then this is used instead */
/* this should be NULL for everyone except Lua-based file writers */
@ -1770,9 +1770,9 @@ void wtap_init(gboolean load_wiretap_plugins);
*
* @param filename Name of the file to open
* @param type WTAP_TYPE_AUTO for automatic recognize file format or explicit choose format type
* @param err a positive "errno" value if the capture file can't be opened;
* @param[out] err a positive "errno" value if the capture file can't be opened;
* a negative number, indicating the type of error, on other failures.
* @param err_info for some errors, a string giving more details of
* @param[out] err_info for some errors, a string giving more details of
* the error
* @param do_random TRUE if random access to the file will be done,
* FALSE if not
@ -2117,12 +2117,14 @@ void wtap_dump_params_cleanup(wtap_dump_params *params);
* @param compression_type Type of compression to use when writing, if any
* @param params The per-file information for this file.
* @param[out] err Will be set to an error code on failure.
* @param[out] err_info for some errors, a string giving more details of
* the error
* @return The newly created dumper object, or NULL on failure.
*/
WS_DLL_PUBLIC
wtap_dumper* wtap_dump_open(const char *filename, int file_type_subtype,
wtap_compression_type compression_type, const wtap_dump_params *params,
int *err);
int *err, gchar **err_info);
/**
* @brief Creates a dumper for a temporary file.
@ -2134,12 +2136,14 @@ wtap_dumper* wtap_dump_open(const char *filename, int file_type_subtype,
* @param compression_type Type of compression to use when writing, if any
* @param params The per-file information for this file.
* @param[out] err Will be set to an error code on failure.
* @param[out] err_info for some errors, a string giving more details of
* the error
* @return The newly created dumper object, or NULL on failure.
*/
WS_DLL_PUBLIC
wtap_dumper* wtap_dump_open_tempfile(char **filenamep, const char *pfx,
int file_type_subtype, wtap_compression_type compression_type,
const wtap_dump_params *params, int *err);
const wtap_dump_params *params, int *err, gchar **err_info);
/**
* @brief Creates a dumper for an existing file descriptor.
@ -2149,12 +2153,14 @@ wtap_dumper* wtap_dump_open_tempfile(char **filenamep, const char *pfx,
* @param compression_type Type of compression to use when writing, if any
* @param params The per-file information for this file.
* @param[out] err Will be set to an error code on failure.
* @param[out] err_info for some errors, a string giving more details of
* the error
* @return The newly created dumper object, or NULL on failure.
*/
WS_DLL_PUBLIC
wtap_dumper* wtap_dump_fdopen(int fd, int file_type_subtype,
wtap_compression_type compression_type, const wtap_dump_params *params,
int *err);
int *err, gchar **err_info);
/**
* @brief Creates a dumper for the standard output.
@ -2163,12 +2169,14 @@ wtap_dumper* wtap_dump_fdopen(int fd, int file_type_subtype,
* @param compression_type Type of compression to use when writing, if any
* @param params The per-file information for this file.
* @param[out] err Will be set to an error code on failure.
* @param[out] err_info for some errors, a string giving more details of
* the error
* @return The newly created dumper object, or NULL on failure.
*/
WS_DLL_PUBLIC
wtap_dumper* wtap_dump_open_stdout(int file_type_subtype,
wtap_compression_type compression_type, const wtap_dump_params *params,
int *err);
int *err, gchar **err_info);
WS_DLL_PUBLIC
gboolean wtap_dump(wtap_dumper *, const wtap_rec *, const guint8 *,
@ -2194,7 +2202,7 @@ void wtap_dump_discard_decryption_secrets(wtap_dumper *wdh);
* shb_hdr, idb_inf and nrb_hdr are not freed by this routine.
*/
WS_DLL_PUBLIC
gboolean wtap_dump_close(wtap_dumper *wdh, int *err);
gboolean wtap_dump_close(wtap_dumper *wdh, int *err, gchar **err_info);
/**
* Return TRUE if we can write a file out with the given GArray of file