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/cmdarg_err.h>
21 #include "ui/failure_message.h"
24 input_file_description(const char *fname)
28 if (strcmp(fname, "-") == 0) {
29 /* We're reading from the standard input */
30 fstring = g_strdup("standard input");
32 /* We're reading from a file */
33 fstring = g_strdup_printf("file \"%s\"", fname);
39 output_file_description(const char *fname)
43 if (strcmp(fname, "-") == 0) {
44 /* We're writing to to the standard output */
45 fstring = g_strdup("standard output");
47 /* We're writing to a file */
48 fstring = g_strdup_printf("file \"%s\"", fname);
54 * Error message for a failed attempt to open a capture file for reading.
55 * "progname" is the name of the program trying to open the file;
56 * "filename" is the name of the file being opened; "err" is assumed
57 * to be a UNIX-style errno or a WTAP_ERR_ value; "err_info" is assumed
58 * to be a string giving further information for some WTAP_ERR_ values.
61 cfile_open_failure_message(const char *progname, const char *filename,
62 int err, gchar *err_info)
67 * Get a string that describes what we're opening.
69 char *file_description = input_file_description(filename);
73 case WTAP_ERR_NOT_REGULAR_FILE:
74 cmdarg_err("The %s is a \"special file\" or socket or other non-regular file.",
78 case WTAP_ERR_RANDOM_OPEN_PIPE:
79 cmdarg_err("The %s is a pipe or FIFO; %s can't read pipe or FIFO files in two-pass mode.",
80 file_description, progname);
83 case WTAP_ERR_FILE_UNKNOWN_FORMAT:
84 cmdarg_err("The %s isn't a capture file in a format %s understands.",
85 file_description, progname);
88 case WTAP_ERR_UNSUPPORTED:
89 cmdarg_err("The %s contains record data that %s doesn't support.\n"
91 file_description, progname,
92 err_info != NULL ? err_info : "no information supplied");
96 case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED:
97 cmdarg_err("The %s is a capture for a network type that %s doesn't support.",
98 file_description, progname);
101 case WTAP_ERR_BAD_FILE:
102 cmdarg_err("The %s appears to be damaged or corrupt.\n"
105 err_info != NULL ? err_info : "no information supplied");
109 case WTAP_ERR_CANT_OPEN:
110 cmdarg_err("The %s could not be opened for some unknown reason.",
114 case WTAP_ERR_SHORT_READ:
115 cmdarg_err("The %s appears to have been cut short in the middle of a packet or other data.",
119 case WTAP_ERR_DECOMPRESS:
120 cmdarg_err("The %s cannot be decompressed; it may be damaged or corrupt."
123 err_info != NULL ? err_info : "no information supplied");
127 case WTAP_ERR_DECOMPRESSION_NOT_SUPPORTED:
128 cmdarg_err("The %s cannot be decompressed; it is compressed in a way that we don't support."
131 err_info != NULL ? err_info : "no information supplied");
136 cmdarg_err("The %s could not be opened: %s.",
141 g_free(file_description);
143 cmdarg_err(file_open_error_message(err, FALSE), filename);
147 * Error message for a failed attempt to open a capture file for writing.
148 * "progname" is the name of the program trying to open the file;
149 * "filename" is the name of the file being opened; "err" is assumed
150 * to be a UNIX-style errno or a WTAP_ERR_ value; "file_type_subtype" is
151 * a WTAP_FILE_TYPE_SUBTYPE_ value for the type and subtype of file being
155 cfile_dump_open_failure_message(const char *progname, const char *filename,
156 int err, int file_type_subtype)
161 * Get a string that describes what we're opening.
163 char *file_description = input_file_description(filename);
167 case WTAP_ERR_NOT_REGULAR_FILE:
168 cmdarg_err("The %s is a \"special file\" or socket or other non-regular file.",
172 case WTAP_ERR_CANT_WRITE_TO_PIPE:
173 cmdarg_err("The %s is a pipe, and \"%s\" capture files can't be written to a pipe.",
175 wtap_file_type_subtype_short_string(file_type_subtype));
178 case WTAP_ERR_UNWRITABLE_FILE_TYPE:
179 cmdarg_err("%s doesn't support writing capture files in that format.",
183 case WTAP_ERR_UNWRITABLE_ENCAP:
184 cmdarg_err("The capture file being read can't be written as a \"%s\" file.",
185 wtap_file_type_subtype_short_string(file_type_subtype));
188 case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED:
189 cmdarg_err("The capture file being read can't be written as a \"%s\" file.",
190 wtap_file_type_subtype_short_string(file_type_subtype));
193 case WTAP_ERR_CANT_OPEN:
194 cmdarg_err("The %s could not be created for some unknown reason.",
198 case WTAP_ERR_SHORT_WRITE:
199 cmdarg_err("A full header couldn't be written to the %s.",
203 case WTAP_ERR_COMPRESSION_NOT_SUPPORTED:
204 cmdarg_err("This file type cannot be written as a compressed file.");
208 cmdarg_err("The %s could not be created: %s.",
213 g_free(file_description);
215 cmdarg_err(file_open_error_message(err, TRUE), filename);
219 * Error message for a failed attempt to read from a capture file.
220 * "progname" is the name of the program trying to open the file;
221 * "filename" is the name of the file being opened; "err" is assumed
222 * to be a UNIX-style errno or a WTAP_ERR_ value; "err_info" is assumed
223 * to be a string giving further information for some WTAP_ERR_ values.
226 cfile_read_failure_message(const char *progname, const char *filename,
227 int err, gchar *err_info)
231 /* Get a string that describes what we're reading from */
232 file_string = input_file_description(filename);
236 case WTAP_ERR_UNSUPPORTED:
237 cmdarg_err("The %s contains record data that %s doesn't support.\n"
239 file_string, progname,
240 err_info != NULL ? err_info : "no information supplied");
244 case WTAP_ERR_SHORT_READ:
245 cmdarg_err("The %s appears to have been cut short in the middle of a packet.",
249 case WTAP_ERR_BAD_FILE:
250 cmdarg_err("The %s appears to be damaged or corrupt.\n"
253 err_info != NULL ? err_info : "no information supplied");
257 case WTAP_ERR_DECOMPRESS:
258 cmdarg_err("The %s cannot be decompressed; it may be damaged or corrupt.\n"
261 err_info != NULL ? err_info : "no information supplied");
265 case WTAP_ERR_DECOMPRESSION_NOT_SUPPORTED:
266 cmdarg_err("The %s cannot be decompressed; it is compressed in a way that we don't support.\n"
269 err_info != NULL ? err_info : "no information supplied");
274 cmdarg_err("An error occurred while reading the %s: %s.",
275 file_string, wtap_strerror(err));
282 * Error message for a failed attempt to write to a capture file.
283 * "progname" is the name of the program trying to open the file;
284 * "in_filename" is the name of the file from which the record
285 * being written came; "out_filename" is the name of the file to
286 * which we're writing; "err" is assumed "err" is assumed to be a
287 * UNIX-style errno or a WTAP_ERR_ value; "err_info" is assumed to be
288 * a string giving further information for some WTAP_ERR_ values;
289 * "framenum" is the frame number of the record on which the error
290 * occurred; "file_type_subtype" is a WTAP_FILE_TYPE_SUBTYPE_ value
291 * for the type and subtype of file being written.
294 cfile_write_failure_message(const char *progname, const char *in_filename,
295 const char *out_filename, int err, gchar *err_info,
296 guint32 framenum, int file_type_subtype)
298 char *in_file_string;
299 char *in_frame_string;
300 char *out_file_string;
302 /* Get a string that describes what we're reading from */
303 if (in_filename == NULL) {
304 in_frame_string = g_strdup("");
306 in_file_string = input_file_description(in_filename);
307 in_frame_string = g_strdup_printf(" %u of %s", framenum,
309 g_free(in_file_string);
312 /* Get a string that describes what we're writing to */
313 out_file_string = output_file_description(out_filename);
317 case WTAP_ERR_UNWRITABLE_ENCAP:
319 * This is a problem with the particular frame we're writing
320 * and the file type and subtype we're writing; note that,
321 * and report the frame number and file type/subtype.
323 cmdarg_err("Frame%s has a network type that can't be saved in a \"%s\" file.",
325 wtap_file_type_subtype_short_string(file_type_subtype));
328 case WTAP_ERR_PACKET_TOO_LARGE:
330 * This is a problem with the particular frame we're writing
331 * and the file type and subtype we're writing; note that,
332 * and report the frame number and file type/subtype.
334 cmdarg_err("Frame%s is larger than %s supports in a \"%s\" file.",
335 in_frame_string, progname,
336 wtap_file_type_subtype_short_string(file_type_subtype));
339 case WTAP_ERR_UNWRITABLE_REC_TYPE:
341 * This is a problem with the particular record we're writing
342 * and the file type and subtype we're writing; note that,
343 * and report the record number and file type/subtype.
345 cmdarg_err("Record%s has a record type that can't be saved in a \"%s\" file.",
347 wtap_file_type_subtype_short_string(file_type_subtype));
350 case WTAP_ERR_UNWRITABLE_REC_DATA:
352 * This is a problem with the particular record we're writing
353 * and the file type and subtype we're writing; note that,
354 * and report the record number and file type/subtype.
356 cmdarg_err("Record%s has data that can't be saved in a \"%s\" file.\n"
359 wtap_file_type_subtype_short_string(file_type_subtype),
360 err_info != NULL ? err_info : "no information supplied");
365 cmdarg_err("Not all the packets could be written to the %s because there is "
366 "no space left on the file system.",
372 cmdarg_err("Not all the packets could be written to the %s because you are "
373 "too close to, or over your disk quota.",
378 case WTAP_ERR_SHORT_WRITE:
379 cmdarg_err("A full write couldn't be done to the %s.",
384 cmdarg_err("An error occurred while writing to the %s: %s.",
385 out_file_string, wtap_strerror(err));
388 g_free(in_frame_string);
389 g_free(out_file_string);
393 * Error message for a failed attempt to close a capture file.
394 * "filename" is the name of the file being closed; "err" is assumed
395 * to be a UNIX-style errno or a WTAP_ERR_ value.
397 * When closing a capture file:
399 * some information in the file that can't be determined until
400 * all packets have been written might be written to the file
401 * (such as a table of the file offsets of all packets);
403 * data buffered in the low-level file writing code might be
404 * flushed to the file;
406 * for remote file systems, data written to the file but not
407 * yet sent to the server might be sent to the server or, if
408 * that data was sent asynchronously, "out of space", "disk
409 * quota exceeded", or "I/O error" indications might have
410 * been received but not yet delivered, and the close operation
411 * could deliver them;
413 * so we have to check for write errors here.
416 cfile_close_failure_message(const char *filename, int err)
420 /* Get a string that describes what we're writing to */
421 file_string = output_file_description(filename);
426 cmdarg_err("Not all the packets could be written to the %s because there is "
427 "no space left on the file system.",
433 cmdarg_err("Not all the packets could be written to the %s because you are "
434 "too close to, or over your disk quota.",
439 case WTAP_ERR_CANT_CLOSE:
440 cmdarg_err("The %s couldn't be closed for some unknown reason.",
444 case WTAP_ERR_SHORT_WRITE:
445 cmdarg_err("A full write couldn't be done to the %s.",
450 cmdarg_err("An error occurred while closing the file %s: %s.",
451 file_string, wtap_strerror(err));