2 * Routines to print various "standard" failure messages used in multiple
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
17 #include <wiretap/wtap.h>
18 #include <wsutil/filesystem.h>
19 #include <wsutil/report_message.h>
20 #include <wsutil/cmdarg_err.h>
22 #include "ui/failure_message.h"
25 * Generic error message.
28 failure_message(const char *msg_format
, va_list ap
)
30 vcmdarg_err(msg_format
, ap
);
34 * Error message for a failed attempt to open or create a file
35 * other than a capture file.
36 * "filename" is the name of the file being opened; "err" is assumed
37 * to be a UNIX-style errno; "for_writing" is true if we're opening
38 * the file for writing and false if we're opening it for reading.
41 open_failure_message(const char *filename
, int err
, bool for_writing
)
43 cmdarg_err(file_open_error_message(err
, for_writing
), filename
);
47 * Error message for a failed attempt to read from a file other than
49 * "filename" is the name of the file being read from; "err" is assumed
50 * to be a UNIX-style errno.
53 read_failure_message(const char *filename
, int err
)
55 cmdarg_err("An error occurred while reading from the file \"%s\": %s.",
56 filename
, g_strerror(err
));
60 * Error message for a failed attempt to write to a file other than
62 * "filename" is the name of the file being written to; "err" is assumed
63 * to be a UNIX-style errno.
66 write_failure_message(const char *filename
, int err
)
68 cmdarg_err("An error occurred while writing to the file \"%s\": %s.",
69 filename
, g_strerror(err
));
73 * Error message for a failed attempt to rename a file other than
75 * "old_filename" is the name of the file being renamed; "new_filename"
76 * is the name to which it's being renamed; "err" is assumed to be a
80 rename_failure_message(const char *old_filename
, const char *new_filename
,
83 cmdarg_err("An error occurred while renaming the file \"%s\" to \"%s\": %s.",
84 old_filename
, new_filename
, g_strerror(err
));
88 input_file_description(const char *fname
)
92 if (strcmp(fname
, "-") == 0) {
93 /* We're reading from the standard input */
94 fstring
= g_strdup("standard input");
96 /* We're reading from a file */
97 fstring
= ws_strdup_printf("file \"%s\"", fname
);
103 output_file_description(const char *fname
)
107 if (strcmp(fname
, "-") == 0) {
108 /* We're writing to the standard output */
109 fstring
= g_strdup("standard output");
111 /* We're writing to a file */
112 fstring
= ws_strdup_printf("file \"%s\"", fname
);
118 * Error message for a failed attempt to open a capture file for reading.
119 * "filename" is the name of the file being opened; "err" is assumed
120 * to be a UNIX-style errno or a WTAP_ERR_ value; "err_info" is assumed
121 * to be a string giving further information for some WTAP_ERR_ values.
124 cfile_open_failure_message(const char *filename
, int err
, char *err_info
)
129 * Get a string that describes what we're opening.
131 char *file_description
= input_file_description(filename
);
135 case WTAP_ERR_NOT_REGULAR_FILE
:
136 cmdarg_err("The %s is a \"special file\" or socket or other non-regular file.",
140 case WTAP_ERR_RANDOM_OPEN_PIPE
:
141 cmdarg_err("The %s is a pipe or FIFO; %s can't read pipe or FIFO files in two-pass mode.",
142 file_description
, get_friendly_program_name());
145 case WTAP_ERR_FILE_UNKNOWN_FORMAT
:
146 cmdarg_err("The %s isn't a capture file in a format %s understands.",
147 file_description
, get_friendly_program_name());
150 case WTAP_ERR_UNSUPPORTED
:
151 cmdarg_err("The %s contains record data that %s doesn't support.\n"
153 file_description
, get_friendly_program_name(),
154 err_info
!= NULL
? err_info
: "no information supplied");
158 case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED
:
159 cmdarg_err("The %s is a capture for a network type that %s doesn't support.",
160 file_description
, get_friendly_program_name());
163 case WTAP_ERR_BAD_FILE
:
164 cmdarg_err("The %s appears to be damaged or corrupt.\n"
167 err_info
!= NULL
? err_info
: "no information supplied");
171 case WTAP_ERR_CANT_OPEN
:
172 cmdarg_err("The %s could not be opened for some unknown reason.",
176 case WTAP_ERR_SHORT_READ
:
177 cmdarg_err("The %s appears to have been cut short in the middle of a packet or other data.",
181 case WTAP_ERR_DECOMPRESS
:
182 cmdarg_err("The %s cannot be decompressed; it may be damaged or corrupt."
185 err_info
!= NULL
? err_info
: "no information supplied");
189 case WTAP_ERR_INTERNAL
:
190 cmdarg_err("An internal error occurred opening the %s.\n"
193 err_info
!= NULL
? err_info
: "no information supplied");
197 case WTAP_ERR_DECOMPRESSION_NOT_SUPPORTED
:
198 cmdarg_err("The %s cannot be decompressed; it is compressed in a way that we don't support."
201 err_info
!= NULL
? err_info
: "no information supplied");
206 cmdarg_err("The %s could not be opened: %s.",
211 g_free(file_description
);
213 cmdarg_err(file_open_error_message(err
, false), filename
);
217 * Error message for a failed attempt to open a capture file for writing.
218 * "filename" is the name of the file being opened; "err" is assumed
219 * to be a UNIX-style errno or a WTAP_ERR_ value; "err_info" is assumed
220 * to be a string giving further information for some WTAP_ERR_ values;
221 * "file_type_subtype" is a WTAP_FILE_TYPE_SUBTYPE_ value for the type
222 * and subtype of file being opened.
225 cfile_dump_open_failure_message(const char *filename
, int err
, char *err_info
,
226 int file_type_subtype
)
231 * Get a string that describes what we're opening.
233 char *file_description
= output_file_description(filename
);
237 case WTAP_ERR_NOT_REGULAR_FILE
:
238 cmdarg_err("The %s is a \"special file\" or socket or other non-regular file.",
242 case WTAP_ERR_CANT_WRITE_TO_PIPE
:
243 cmdarg_err("The %s is a pipe, and \"%s\" capture files can't be written to a pipe.",
245 wtap_file_type_subtype_name(file_type_subtype
));
248 case WTAP_ERR_UNWRITABLE_FILE_TYPE
:
249 cmdarg_err("%s doesn't support writing capture files in that format.",
250 get_friendly_program_name());
253 case WTAP_ERR_UNWRITABLE_ENCAP
:
254 cmdarg_err("The capture file being read can't be written as a \"%s\" file.",
255 wtap_file_type_subtype_name(file_type_subtype
));
258 case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED
:
259 cmdarg_err("The capture file being read can't be written as a \"%s\" file.",
260 wtap_file_type_subtype_name(file_type_subtype
));
263 case WTAP_ERR_CANT_OPEN
:
264 cmdarg_err("The %s could not be created for some unknown reason.",
268 case WTAP_ERR_SHORT_WRITE
:
269 cmdarg_err("A full header couldn't be written to the %s.",
273 case WTAP_ERR_COMPRESSION_NOT_SUPPORTED
:
274 cmdarg_err("This file type cannot be written as a compressed file.");
277 case WTAP_ERR_INTERNAL
:
278 cmdarg_err("An internal error occurred creating the %s.\n"
281 err_info
!= NULL
? err_info
: "no information supplied");
286 cmdarg_err("The %s could not be created: %s.",
291 g_free(file_description
);
293 cmdarg_err(file_open_error_message(err
, true), filename
);
297 * Error message for a failed attempt to read from a capture file.
298 * "filename" is the name of the file being opened; "err" is assumed
299 * to be a UNIX-style errno or a WTAP_ERR_ value; "err_info" is assumed
300 * to be a string giving further information for some WTAP_ERR_ values.
303 cfile_read_failure_message(const char *filename
, int err
, char *err_info
)
307 /* Get a string that describes what we're reading from */
308 file_string
= input_file_description(filename
);
312 case WTAP_ERR_UNSUPPORTED
:
313 cmdarg_err("The %s contains record data that %s doesn't support.\n"
315 file_string
, get_friendly_program_name(),
316 err_info
!= NULL
? err_info
: "no information supplied");
320 case WTAP_ERR_SHORT_READ
:
321 cmdarg_err("The %s appears to have been cut short in the middle of a packet.",
325 case WTAP_ERR_BAD_FILE
:
326 cmdarg_err("The %s appears to be damaged or corrupt.\n"
329 err_info
!= NULL
? err_info
: "no information supplied");
333 case WTAP_ERR_DECOMPRESS
:
334 cmdarg_err("The %s cannot be decompressed; it may be damaged or corrupt.\n"
337 err_info
!= NULL
? err_info
: "no information supplied");
341 case WTAP_ERR_INTERNAL
:
342 cmdarg_err("An internal error occurred while reading the %s.\n(%s)",
344 err_info
!= NULL
? err_info
: "no information supplied");
348 case WTAP_ERR_DECOMPRESSION_NOT_SUPPORTED
:
349 cmdarg_err("The %s cannot be decompressed; it is compressed in a way that we don't support.\n"
352 err_info
!= NULL
? err_info
: "no information supplied");
357 cmdarg_err("An error occurred while reading the %s: %s.",
358 file_string
, wtap_strerror(err
));
365 * Error message for a failed attempt to write to a capture file.
366 * "in_filename" is the name of the file from which the record
367 * being written came; "out_filename" is the name of the file to
368 * which we're writing; "err" is assumed "err" is assumed to be a
369 * UNIX-style errno or a WTAP_ERR_ value; "err_info" is assumed to be
370 * a string giving further information for some WTAP_ERR_ values;
371 * "framenum" is the frame number of the record on which the error
372 * occurred; "file_type_subtype" is a WTAP_FILE_TYPE_SUBTYPE_ value
373 * for the type and subtype of file being written.
376 cfile_write_failure_message(const char *in_filename
, const char *out_filename
,
377 int err
, char *err_info
,
378 uint64_t framenum
, int file_type_subtype
)
380 char *in_file_string
;
381 char *in_frame_string
;
382 char *out_file_string
;
384 /* Get a string that describes what we're reading from */
385 if (in_filename
== NULL
) {
386 in_frame_string
= g_strdup("");
388 in_file_string
= input_file_description(in_filename
);
389 in_frame_string
= ws_strdup_printf(" %" PRIu64
" of %s", framenum
,
391 g_free(in_file_string
);
394 /* Get a string that describes what we're writing to */
395 out_file_string
= output_file_description(out_filename
);
399 case WTAP_ERR_UNWRITABLE_ENCAP
:
401 * This is a problem with the particular frame we're writing
402 * and the file type and subtype we're writing; note that,
403 * and report the frame number and file type/subtype.
405 cmdarg_err("Frame%s has a network type that can't be saved in a \"%s\" file.",
407 wtap_file_type_subtype_name(file_type_subtype
));
410 case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED
:
412 * This is a problem with the particular frame we're writing and
413 * the file type and subtype we're writing; note that, and report
414 * the frame number and file type/subtype.
416 cmdarg_err("Frame%s has a network type that differs from the network type of earlier packets, which isn't supported in a \"%s\" file.",
418 wtap_file_type_subtype_description(file_type_subtype
));
421 case WTAP_ERR_PACKET_TOO_LARGE
:
423 * This is a problem with the particular frame we're writing
424 * and the file type and subtype we're writing; note that,
425 * and report the frame number and file type/subtype.
427 cmdarg_err("Frame%s is larger than %s supports in a \"%s\" file.",
428 in_frame_string
, get_friendly_program_name(),
429 wtap_file_type_subtype_name(file_type_subtype
));
432 case WTAP_ERR_UNWRITABLE_REC_TYPE
:
434 * This is a problem with the particular record we're writing
435 * and the file type and subtype we're writing; note that,
436 * and report the record number and file type/subtype.
438 cmdarg_err("Record%s has a record type that can't be saved in a \"%s\" file.",
440 wtap_file_type_subtype_name(file_type_subtype
));
443 case WTAP_ERR_UNWRITABLE_REC_DATA
:
445 * This is a problem with the particular record we're writing
446 * and the file type and subtype we're writing; note that,
447 * and report the record number and file type/subtype.
449 cmdarg_err("Record%s has data that can't be saved in a \"%s\" file.\n"
452 wtap_file_type_subtype_name(file_type_subtype
),
453 err_info
!= NULL
? err_info
: "no information supplied");
457 case WTAP_ERR_SHORT_WRITE
:
458 cmdarg_err("A full write couldn't be done to the %s.",
462 case WTAP_ERR_INTERNAL
:
463 cmdarg_err("An internal error occurred while writing record%s to the %s.\n(%s)",
464 in_frame_string
, out_file_string
,
465 err_info
!= NULL
? err_info
: "no information supplied");
470 cmdarg_err("Not all the packets could be written to the %s because there is "
471 "no space left on the file system.",
477 cmdarg_err("Not all the packets could be written to the %s because you are "
478 "too close to, or over your disk quota.",
484 cmdarg_err("An error occurred while writing to the %s: %s.",
485 out_file_string
, wtap_strerror(err
));
488 g_free(in_frame_string
);
489 g_free(out_file_string
);
493 * Error message for a failed attempt to close a capture file.
494 * "filename" is the name of the file being closed; "err" is assumed
495 * to be a UNIX-style errno or a WTAP_ERR_ value; "err_info" is assumed
496 * to be a string giving further information for some WTAP_ERR_ values.
498 * When closing a capture file:
500 * some information in the file that can't be determined until
501 * all packets have been written might be written to the file
502 * (such as a table of the file offsets of all packets);
504 * data buffered in the low-level file writing code might be
505 * flushed to the file;
507 * for remote file systems, data written to the file but not
508 * yet sent to the server might be sent to the server or, if
509 * that data was sent asynchronously, "out of space", "disk
510 * quota exceeded", or "I/O error" indications might have
511 * been received but not yet delivered, and the close operation
512 * could deliver them;
514 * so we have to check for write errors here.
517 cfile_close_failure_message(const char *filename
, int err
, char *err_info
)
521 /* Get a string that describes what we're writing to */
522 file_string
= output_file_description(filename
);
526 case WTAP_ERR_CANT_CLOSE
:
527 cmdarg_err("The %s couldn't be closed for some unknown reason.",
531 case WTAP_ERR_SHORT_WRITE
:
532 cmdarg_err("A full write couldn't be done to the %s.",
536 case WTAP_ERR_INTERNAL
:
537 cmdarg_err("An internal error occurred closing the file \"%s\".\n"
540 err_info
!= NULL
? err_info
: "no information supplied");
545 cmdarg_err("Not all the packets could be written to the %s because there is "
546 "no space left on the file system.",
552 cmdarg_err("Not all the packets could be written to the %s because you are "
553 "too close to, or over your disk quota.",
559 cmdarg_err("An error occurred while closing the file %s: %s.",
560 file_string
, wtap_strerror(err
));
567 * Register these routines with the report_message mechanism.
570 init_report_failure_message(const char *friendly_program_name
)
572 static const struct report_message_routines report_failure_routines
= {
575 open_failure_message
,
576 read_failure_message
,
577 write_failure_message
,
578 rename_failure_message
,
579 cfile_open_failure_message
,
580 cfile_dump_open_failure_message
,
581 cfile_read_failure_message
,
582 cfile_write_failure_message
,
583 cfile_close_failure_message
586 init_report_message(friendly_program_name
, &report_failure_routines
);