forked from osmocom/wireshark
Use the new cfile_XXX_failure_message() routines more broadly.
Change-Id: I7814b3fd0353f4836ae61cbdbd4e13f659cbcb59 Reviewed-on: https://code.wireshark.org/review/21239 Reviewed-by: Guy Harris <guy@alum.mit.edu>pespin/osmux-stats
parent
b0c48f3b4f
commit
bce5ec919e
|
@ -2425,6 +2425,7 @@ endif()
|
|||
|
||||
if(BUILD_reordercap)
|
||||
set(reordercap_LIBS
|
||||
ui
|
||||
wiretap
|
||||
${ZLIB_LIBRARIES}
|
||||
${CMAKE_DL_LIBS}
|
||||
|
@ -2443,6 +2444,7 @@ endif()
|
|||
|
||||
if(BUILD_capinfos)
|
||||
set(capinfos_LIBS
|
||||
ui
|
||||
wiretap
|
||||
wsutil
|
||||
${ZLIB_LIBRARIES}
|
||||
|
@ -2463,6 +2465,7 @@ endif()
|
|||
|
||||
if(BUILD_captype)
|
||||
set(captype_LIBS
|
||||
ui
|
||||
wiretap
|
||||
wsutil
|
||||
${ZLIB_LIBRARIES}
|
||||
|
|
|
@ -642,6 +642,7 @@ capinfos_CPPFLAGS = $(AM_CPPFLAGS) $(GLIB_CFLAGS)
|
|||
|
||||
# Libraries with which to link capinfos.
|
||||
capinfos_LDADD = \
|
||||
ui/libui.a \
|
||||
wiretap/libwiretap.la \
|
||||
wsutil/libwsutil.la \
|
||||
@GLIB_LIBS@ \
|
||||
|
@ -655,6 +656,7 @@ captype_CPPFLAGS = $(AM_CPPFLAGS) $(GLIB_CFLAGS)
|
|||
|
||||
# Libraries with which to link captype.
|
||||
captype_LDADD = \
|
||||
ui/libui.a \
|
||||
wiretap/libwiretap.la \
|
||||
wsutil/libwsutil.la \
|
||||
@GLIB_LIBS@
|
||||
|
@ -681,6 +683,7 @@ reordercap_CPPFLAGS = $(AM_CPPFLAGS) $(GLIB_CFLAGS)
|
|||
|
||||
# Libraries with which to link reordercap.
|
||||
reordercap_LDADD = \
|
||||
ui/libui.a \
|
||||
wiretap/libwiretap.la \
|
||||
wsutil/libwsutil.la \
|
||||
@GLIB_LIBS@
|
||||
|
|
30
capinfos.c
30
capinfos.c
|
@ -71,6 +71,7 @@
|
|||
|
||||
#include <wiretap/wtap.h>
|
||||
|
||||
#include <wsutil/cmdarg_err.h>
|
||||
#include <wsutil/crash_info.h>
|
||||
#include <wsutil/filesystem.h>
|
||||
#include <wsutil/privileges.h>
|
||||
|
@ -95,6 +96,8 @@
|
|||
#include <wsutil/unicode-utils.h>
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#include "ui/failure_message.h"
|
||||
|
||||
#define INVALID_OPTION 1
|
||||
#define BAD_FLAG 1
|
||||
|
||||
|
@ -1219,8 +1222,9 @@ process_cap_file(wtap *wth, const char *filename)
|
|||
|
||||
if (err != 0) {
|
||||
fprintf(stderr,
|
||||
"capinfos: An error occurred after reading %u packets from \"%s\": %s.\n",
|
||||
packet, filename, wtap_strerror(err));
|
||||
"capinfos: An error occurred after reading %u packets from \"%s\".\n",
|
||||
packet, filename);
|
||||
cfile_read_failure_message("capinfos", filename, err, err_info);
|
||||
if (err == WTAP_ERR_SHORT_READ) {
|
||||
/* Don't give up completely with this one. */
|
||||
status = 1;
|
||||
|
@ -1376,7 +1380,6 @@ print_usage(FILE *output)
|
|||
fprintf(output, "output format.\n");
|
||||
}
|
||||
|
||||
#ifdef HAVE_PLUGINS
|
||||
/*
|
||||
* General errors and warnings are reported with an console message
|
||||
* in capinfos.
|
||||
|
@ -1388,7 +1391,16 @@ failure_warning_message(const char *msg_format, va_list ap)
|
|||
vfprintf(stderr, msg_format, ap);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Report additional information for an error in command-line arguments.
|
||||
*/
|
||||
static void
|
||||
failure_message_cont(const char *msg_format, va_list ap)
|
||||
{
|
||||
vfprintf(stderr, msg_format, ap);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
static void
|
||||
hash_to_str(const unsigned char *hash, size_t length, char *str) {
|
||||
|
@ -1425,6 +1437,8 @@ main(int argc, char *argv[])
|
|||
/* Set the C-language locale to the native environment. */
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
cmdarg_err_init(failure_warning_message, failure_message_cont);
|
||||
|
||||
/* Get the decimal point. */
|
||||
decimal_point = g_strdup(localeconv()->decimal_point);
|
||||
|
||||
|
@ -1711,12 +1725,8 @@ main(int argc, char *argv[])
|
|||
wth = wtap_open_offline(argv[opt], WTAP_TYPE_AUTO, &err, &err_info, FALSE);
|
||||
|
||||
if (!wth) {
|
||||
fprintf(stderr, "capinfos: Can't open %s: %s\n", argv[opt],
|
||||
wtap_strerror(err));
|
||||
if (err_info != NULL) {
|
||||
fprintf(stderr, "(%s)\n", err_info);
|
||||
g_free(err_info);
|
||||
}
|
||||
cfile_open_failure_message("capinfos", argv[opt], err, err_info, FALSE,
|
||||
WTAP_TYPE_AUTO);
|
||||
overall_error_status = 2; /* remember that an error has occurred */
|
||||
if (!continue_after_wtap_open_offline_failure)
|
||||
goto exit;
|
||||
|
|
25
captype.c
25
captype.c
|
@ -40,6 +40,7 @@
|
|||
|
||||
#include <wiretap/wtap.h>
|
||||
|
||||
#include <wsutil/cmdarg_err.h>
|
||||
#include <wsutil/crash_info.h>
|
||||
#include <wsutil/file_util.h>
|
||||
#include <wsutil/filesystem.h>
|
||||
|
@ -61,6 +62,8 @@
|
|||
#include "wsutil/wsgetopt.h"
|
||||
#endif
|
||||
|
||||
#include "ui/failure_message.h"
|
||||
|
||||
static void
|
||||
print_usage(FILE *output)
|
||||
{
|
||||
|
@ -68,7 +71,6 @@ print_usage(FILE *output)
|
|||
fprintf(output, "Usage: captype <infile> ...\n");
|
||||
}
|
||||
|
||||
#ifdef HAVE_PLUGINS
|
||||
/*
|
||||
* General errors and warnings are reported with an console message
|
||||
* in captype.
|
||||
|
@ -80,7 +82,16 @@ failure_warning_message(const char *msg_format, va_list ap)
|
|||
vfprintf(stderr, msg_format, ap);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Report additional information for an error in command-line arguments.
|
||||
*/
|
||||
static void
|
||||
failure_message_cont(const char *msg_format, va_list ap)
|
||||
{
|
||||
vfprintf(stderr, msg_format, ap);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
|
@ -103,6 +114,8 @@ main(int argc, char *argv[])
|
|||
/* Set the C-language locale to the native environment. */
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
cmdarg_err_init(failure_warning_message, failure_message_cont);
|
||||
|
||||
/* Get the compile-time version information string */
|
||||
comp_info_str = get_compiled_version_info(NULL, NULL);
|
||||
|
||||
|
@ -206,12 +219,8 @@ main(int argc, char *argv[])
|
|||
if (err == WTAP_ERR_FILE_UNKNOWN_FORMAT)
|
||||
printf("%s: unknown\n", argv[i]);
|
||||
else {
|
||||
fprintf(stderr, "captype: Can't open %s: %s\n", argv[i],
|
||||
wtap_strerror(err));
|
||||
if (err_info != NULL) {
|
||||
fprintf(stderr, "(%s)\n", err_info);
|
||||
g_free(err_info);
|
||||
}
|
||||
cfile_open_failure_message("captype", argv[i], err, err_info, FALSE,
|
||||
WTAP_TYPE_AUTO);
|
||||
overall_error_status = 2; /* remember that an error has occurred */
|
||||
}
|
||||
}
|
||||
|
|
42
editcap.c
42
editcap.c
|
@ -930,8 +930,8 @@ failure_warning_message(const char *msg_format, va_list ap)
|
|||
static void
|
||||
failure_message_cont(const char *msg_format, va_list ap)
|
||||
{
|
||||
vfprintf(stderr, msg_format, ap);
|
||||
fprintf(stderr, "\n");
|
||||
vfprintf(stderr, msg_format, ap);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
static wtap_dumper *
|
||||
|
@ -1423,8 +1423,9 @@ main(int argc, char *argv[])
|
|||
shb_hdrs, idb_inf, nrb_hdrs, &write_err);
|
||||
|
||||
if (pdh == NULL) {
|
||||
fprintf(stderr, "editcap: Can't open or create %s: %s\n",
|
||||
filename, wtap_strerror(write_err));
|
||||
cfile_open_failure_message("editcap", filename,
|
||||
write_err, NULL, TRUE,
|
||||
out_frame_type);
|
||||
ret = INVALID_FILE;
|
||||
goto clean_exit;
|
||||
}
|
||||
|
@ -1447,8 +1448,7 @@ main(int argc, char *argv[])
|
|||
&& phdr->ts.nsecs >= block_start.nsecs )) { /* time for the next file */
|
||||
|
||||
if (!wtap_dump_close(pdh, &write_err)) {
|
||||
fprintf(stderr, "editcap: Error writing to %s: %s\n",
|
||||
filename, wtap_strerror(write_err));
|
||||
cfile_close_failure_message(filename, write_err);
|
||||
ret = WRITE_ERROR;
|
||||
goto clean_exit;
|
||||
}
|
||||
|
@ -1465,8 +1465,9 @@ main(int argc, char *argv[])
|
|||
shb_hdrs, idb_inf, nrb_hdrs, &write_err);
|
||||
|
||||
if (pdh == NULL) {
|
||||
fprintf(stderr, "editcap: Can't open or create %s: %s\n",
|
||||
filename, wtap_strerror(write_err));
|
||||
cfile_open_failure_message("editcap", filename,
|
||||
write_err, NULL, TRUE,
|
||||
out_frame_type);
|
||||
ret = INVALID_FILE;
|
||||
goto clean_exit;
|
||||
}
|
||||
|
@ -1478,8 +1479,7 @@ main(int argc, char *argv[])
|
|||
/* time for the next file? */
|
||||
if (written_count > 0 && (written_count % split_packet_count) == 0) {
|
||||
if (!wtap_dump_close(pdh, &write_err)) {
|
||||
fprintf(stderr, "editcap: Error writing to %s: %s\n",
|
||||
filename, wtap_strerror(write_err));
|
||||
cfile_close_failure_message(filename, write_err);
|
||||
ret = WRITE_ERROR;
|
||||
goto clean_exit;
|
||||
}
|
||||
|
@ -1495,8 +1495,9 @@ main(int argc, char *argv[])
|
|||
snaplen ? MIN(snaplen, wtap_snapshot_length(wth)) : wtap_snapshot_length(wth),
|
||||
shb_hdrs, idb_inf, nrb_hdrs, &write_err);
|
||||
if (pdh == NULL) {
|
||||
fprintf(stderr, "editcap: Can't open or create %s: %s\n",
|
||||
filename, wtap_strerror(write_err));
|
||||
cfile_open_failure_message("editcap", filename,
|
||||
write_err, NULL, TRUE,
|
||||
out_frame_type);
|
||||
ret = INVALID_FILE;
|
||||
goto clean_exit;
|
||||
}
|
||||
|
@ -1793,13 +1794,8 @@ main(int argc, char *argv[])
|
|||
if (read_err != 0) {
|
||||
/* Print a message noting that the read failed somewhere along the
|
||||
* line. */
|
||||
fprintf(stderr,
|
||||
"editcap: An error occurred while reading \"%s\": %s.\n",
|
||||
argv[optind], wtap_strerror(read_err));
|
||||
if (read_err_info != NULL) {
|
||||
fprintf(stderr, "(%s)\n", read_err_info);
|
||||
g_free(read_err_info);
|
||||
}
|
||||
cfile_read_failure_message("editcap", argv[optind], read_err,
|
||||
read_err_info);
|
||||
}
|
||||
|
||||
if (!pdh) {
|
||||
|
@ -1812,16 +1808,16 @@ main(int argc, char *argv[])
|
|||
snaplen ? MIN(snaplen, wtap_snapshot_length(wth)): wtap_snapshot_length(wth),
|
||||
shb_hdrs, idb_inf, nrb_hdrs, &write_err);
|
||||
if (pdh == NULL) {
|
||||
fprintf(stderr, "editcap: Can't open or create %s: %s\n",
|
||||
filename, wtap_strerror(write_err));
|
||||
cfile_open_failure_message("editcap", filename,
|
||||
write_err, NULL, TRUE,
|
||||
out_frame_type);
|
||||
ret = INVALID_FILE;
|
||||
goto clean_exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (!wtap_dump_close(pdh, &write_err)) {
|
||||
fprintf(stderr, "editcap: Error writing to %s: %s\n", filename,
|
||||
wtap_strerror(write_err));
|
||||
cfile_close_failure_message(filename, write_err);
|
||||
ret = WRITE_ERROR;
|
||||
goto clean_exit;
|
||||
}
|
||||
|
|
48
reordercap.c
48
reordercap.c
|
@ -51,6 +51,8 @@
|
|||
|
||||
#include <wsutil/report_message.h>
|
||||
|
||||
#include "ui/failure_message.h"
|
||||
|
||||
#define INVALID_OPTION 1
|
||||
#define OPEN_ERROR 2
|
||||
#define OUTPUT_FILE_ERROR 1
|
||||
|
@ -92,7 +94,8 @@ typedef struct FrameRecord_t {
|
|||
|
||||
static void
|
||||
frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh,
|
||||
struct wtap_pkthdr *phdr, Buffer *buf, const char *infile)
|
||||
struct wtap_pkthdr *phdr, Buffer *buf, const char *infile,
|
||||
const char *outfile)
|
||||
{
|
||||
int err;
|
||||
gchar *err_info;
|
||||
|
@ -106,12 +109,9 @@ frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh,
|
|||
if (err != 0) {
|
||||
/* Print a message noting that the read failed somewhere along the line. */
|
||||
fprintf(stderr,
|
||||
"reordercap: An error occurred while re-reading \"%s\": %s.\n",
|
||||
infile, wtap_strerror(err));
|
||||
if (err_info != NULL) {
|
||||
fprintf(stderr, "(%s)\n", err_info);
|
||||
g_free(err_info);
|
||||
}
|
||||
"reordercap: An error occurred while re-reading \"%s\".\n",
|
||||
infile);
|
||||
cfile_read_failure_message("reordercap", infile, err, err_info);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
@ -123,12 +123,8 @@ frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh,
|
|||
|
||||
/* Dump frame to outfile */
|
||||
if (!wtap_dump(pdh, phdr, ws_buffer_start_ptr(buf), &err, &err_info)) {
|
||||
fprintf(stderr, "reordercap: Error (%s) writing frame to outfile\n",
|
||||
wtap_strerror(err));
|
||||
if (err_info != NULL) {
|
||||
fprintf(stderr, "(%s)\n", err_info);
|
||||
g_free(err_info);
|
||||
}
|
||||
cfile_write_failure_message(infile, outfile, err, err_info,
|
||||
frame->num, wtap_file_type_subtype(wth));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
@ -298,12 +294,8 @@ main(int argc, char *argv[])
|
|||
open_routine reader to use, then the following needs to change. */
|
||||
wth = wtap_open_offline(infile, WTAP_TYPE_AUTO, &err, &err_info, TRUE);
|
||||
if (wth == NULL) {
|
||||
fprintf(stderr, "reordercap: Can't open %s: %s\n", infile,
|
||||
wtap_strerror(err));
|
||||
if (err_info != NULL) {
|
||||
fprintf(stderr, "(%s)\n", err_info);
|
||||
g_free(err_info);
|
||||
}
|
||||
cfile_open_failure_message("reordercap", infile, err, err_info,
|
||||
FALSE, WTAP_TYPE_AUTO);
|
||||
ret = OPEN_ERROR;
|
||||
goto clean_exit;
|
||||
}
|
||||
|
@ -317,7 +309,6 @@ main(int argc, char *argv[])
|
|||
if (strcmp(outfile, "-") == 0) {
|
||||
pdh = wtap_dump_open_stdout_ng(wtap_file_type_subtype(wth), wtap_file_encap(wth),
|
||||
wtap_snapshot_length(wth), FALSE, shb_hdrs, idb_inf, nrb_hdrs, &err);
|
||||
outfile = "standard output";
|
||||
} else {
|
||||
pdh = wtap_dump_open_ng(outfile, wtap_file_type_subtype(wth), wtap_file_encap(wth),
|
||||
wtap_snapshot_length(wth), FALSE, shb_hdrs, idb_inf, nrb_hdrs, &err);
|
||||
|
@ -326,8 +317,8 @@ main(int argc, char *argv[])
|
|||
idb_inf = NULL;
|
||||
|
||||
if (pdh == NULL) {
|
||||
fprintf(stderr, "reordercap: Failed to open output file: (%s) - error %s\n",
|
||||
outfile, wtap_strerror(err));
|
||||
cfile_open_failure_message("reordercap", outfile, err, err_info, TRUE,
|
||||
wtap_file_type_subtype(wth));
|
||||
wtap_block_array_free(shb_hdrs);
|
||||
wtap_block_array_free(nrb_hdrs);
|
||||
ret = OUTPUT_FILE_ERROR;
|
||||
|
@ -361,13 +352,7 @@ main(int argc, char *argv[])
|
|||
}
|
||||
if (err != 0) {
|
||||
/* Print a message noting that the read failed somewhere along the line. */
|
||||
fprintf(stderr,
|
||||
"reordercap: An error occurred while reading \"%s\": %s.\n",
|
||||
infile, wtap_strerror(err));
|
||||
if (err_info != NULL) {
|
||||
fprintf(stderr, "(%s)\n", err_info);
|
||||
g_free(err_info);
|
||||
}
|
||||
cfile_read_failure_message("reordercap", infile, err, err_info);
|
||||
}
|
||||
|
||||
printf("%u frames, %u out of order\n", frames->len, wrong_order_count);
|
||||
|
@ -385,7 +370,7 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Avoid writing if already sorted and configured to */
|
||||
if (write_output_regardless || (wrong_order_count > 0)) {
|
||||
frame_write(frame, wth, pdh, &dump_phdr, &buf, infile);
|
||||
frame_write(frame, wth, pdh, &dump_phdr, &buf, infile, outfile);
|
||||
}
|
||||
g_slice_free(FrameRecord_t, frame);
|
||||
}
|
||||
|
@ -401,8 +386,7 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Close outfile */
|
||||
if (!wtap_dump_close(pdh, &err)) {
|
||||
fprintf(stderr, "reordercap: Error closing %s: %s\n", outfile,
|
||||
wtap_strerror(err));
|
||||
cfile_close_failure_message(outfile, err);
|
||||
wtap_block_array_free(shb_hdrs);
|
||||
wtap_block_array_free(nrb_hdrs);
|
||||
ret = OUTPUT_FILE_ERROR;
|
||||
|
|
4
tshark.c
4
tshark.c
|
@ -643,6 +643,7 @@ main(int argc, char *argv[])
|
|||
{0, 0, 0, 0 }
|
||||
};
|
||||
gboolean arg_error = FALSE;
|
||||
const char *exp_pdu_filename = NULL;
|
||||
|
||||
#ifdef _WIN32
|
||||
int result;
|
||||
|
@ -1864,7 +1865,6 @@ main(int argc, char *argv[])
|
|||
/* PDU export requested. Take the ownership of the '-w' file, apply tap
|
||||
* filters and start tapping. */
|
||||
if (pdu_export_arg) {
|
||||
const char *exp_pdu_filename;
|
||||
const char *exp_pdu_tap_name = pdu_export_arg;
|
||||
const char *exp_pdu_filter = dfilter; /* may be NULL to disable filter */
|
||||
char *exp_pdu_error;
|
||||
|
@ -1978,7 +1978,7 @@ main(int argc, char *argv[])
|
|||
if (pdu_export_arg) {
|
||||
err = exp_pdu_close(&exp_pdu_tap_data);
|
||||
if (err) {
|
||||
cmdarg_err("%s", wtap_strerror(err));
|
||||
cfile_close_failure_message(exp_pdu_filename, err);
|
||||
exit_status = 2;
|
||||
}
|
||||
g_free(pdu_export_arg);
|
||||
|
|
Loading…
Reference in New Issue