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 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <wiretap/wtap.h>
30 #include <wsutil/filesystem.h>
31 #include <wsutil/cmdarg_err.h>
33 #include "ui/failure_message.h"
36 input_file_description(const char *fname)
40 if (strcmp(fname, "-") == 0) {
41 /* We're reading from the standard input */
42 fstring = g_strdup("standard input");
44 /* We're reading from a file */
45 fstring = g_strdup_printf("file \"%s\"", fname);
51 output_file_description(const char *fname)
55 if (strcmp(fname, "-") == 0) {
56 /* We're writing to to the standard output */
57 fstring = g_strdup("standard output");
59 /* We're writing to a file */
60 fstring = g_strdup_printf("file \"%s\"", fname);
66 * Error message for a failed attempt to open a capture file for reading.
67 * "progname" is the name of the program trying to open the file;
68 * "filename" is the name of the file being opened; "err" is assumed
69 * to be a UNIX-style errno or a WTAP_ERR_ value; "err_info" is assumed
70 * to be a string giving further information for some WTAP_ERR_ values.
73 cfile_open_failure_message(const char *progname, const char *filename,
74 int err, gchar *err_info)
76 char *file_description;
78 /* Get a string that describes what we're opening */
79 file_description = input_file_description(filename);
85 case WTAP_ERR_NOT_REGULAR_FILE:
86 cmdarg_err("The %s is a \"special file\" or socket or other non-regular file.",
90 case WTAP_ERR_RANDOM_OPEN_PIPE:
91 cmdarg_err("The %s is a pipe or FIFO; %s can't read pipe or FIFO files in two-pass mode.",
92 file_description, progname);
95 case WTAP_ERR_FILE_UNKNOWN_FORMAT:
96 cmdarg_err("The %s isn't a capture file in a format %s understands.",
97 file_description, progname);
100 case WTAP_ERR_UNSUPPORTED:
101 cmdarg_err("The %s contains record data that %s doesn't support.\n"
103 file_description, progname,
104 err_info != NULL ? err_info : "no information supplied");
108 case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED:
109 cmdarg_err("The %s is a capture for a network type that %s doesn't support.",
110 file_description, progname);
113 case WTAP_ERR_BAD_FILE:
114 cmdarg_err("The %s appears to be damaged or corrupt.\n"
117 err_info != NULL ? err_info : "no information supplied");
121 case WTAP_ERR_CANT_OPEN:
122 cmdarg_err("The %s could not be opened for some unknown reason.",
126 case WTAP_ERR_SHORT_READ:
127 cmdarg_err("The %s appears to have been cut short in the middle of a packet or other data.",
131 case WTAP_ERR_DECOMPRESS:
132 cmdarg_err("The %s cannot be decompressed; it may be damaged or corrupt."
135 err_info != NULL ? err_info : "no information supplied");
139 case WTAP_ERR_DECOMPRESSION_NOT_SUPPORTED:
140 cmdarg_err("The %s cannot be decompressed; it is compressed in a way that we don't support."
143 err_info != NULL ? err_info : "no information supplied");
148 cmdarg_err("The %s could not be opened: %s.",
153 g_free(file_description);
155 cmdarg_err(file_open_error_message(err, FALSE), filename);
159 * Error message for a failed attempt to open a capture file for writing.
160 * "progname" is the name of the program trying to open the file;
161 * "filename" is the name of the file being opened; "err" is assumed
162 * to be a UNIX-style errno or a WTAP_ERR_ value; "file_type_subtype" is
163 * a WTAP_FILE_TYPE_SUBTYPE_ value for the type and subtype of file being
167 cfile_dump_open_failure_message(const char *progname, const char *filename,
168 int err, int file_type_subtype)
170 char *file_description;
172 /* Get a string that describes what we're opening */
173 file_description = output_file_description(filename);
179 case WTAP_ERR_NOT_REGULAR_FILE:
180 cmdarg_err("The %s is a \"special file\" or socket or other non-regular file.",
184 case WTAP_ERR_CANT_WRITE_TO_PIPE:
185 cmdarg_err("The %s is a pipe, and \"%s\" capture files can't be written to a pipe.",
187 wtap_file_type_subtype_short_string(file_type_subtype));
190 case WTAP_ERR_UNWRITABLE_FILE_TYPE:
191 cmdarg_err("%s doesn't support writing capture files in that format.",
195 case WTAP_ERR_UNWRITABLE_ENCAP:
196 cmdarg_err("The capture file being read can't be written as a \"%s\" file.",
197 wtap_file_type_subtype_short_string(file_type_subtype));
200 case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED:
201 cmdarg_err("The capture file being read can't be written as a \"%s\" file.",
202 wtap_file_type_subtype_short_string(file_type_subtype));
205 case WTAP_ERR_CANT_OPEN:
206 cmdarg_err("The %s could not be created for some unknown reason.",
210 case WTAP_ERR_SHORT_WRITE:
211 cmdarg_err("A full header couldn't be written to the %s.",
215 case WTAP_ERR_COMPRESSION_NOT_SUPPORTED:
216 cmdarg_err("This file type cannot be written as a compressed file.");
220 cmdarg_err("The %s could not be created: %s.",
225 g_free(file_description);
227 cmdarg_err(file_open_error_message(err, TRUE), filename);
231 * Error message for a failed attempt to read from a capture file.
232 * "progname" is the name of the program trying to open the file;
233 * "filename" is the name of the file being opened; "err" is assumed
234 * to be a UNIX-style errno or a WTAP_ERR_ value; "err_info" is assumed
235 * to be a string giving further information for some WTAP_ERR_ values.
238 cfile_read_failure_message(const char *progname, const char *filename,
239 int err, gchar *err_info)
243 /* Get a string that describes what we're reading from */
244 file_string = input_file_description(filename);
248 case WTAP_ERR_UNSUPPORTED:
249 cmdarg_err("The %s contains record data that %s doesn't support.\n"
251 file_string, progname,
252 err_info != NULL ? err_info : "no information supplied");
256 case WTAP_ERR_SHORT_READ:
257 cmdarg_err("The %s appears to have been cut short in the middle of a packet.",
261 case WTAP_ERR_BAD_FILE:
262 cmdarg_err("The %s appears to be damaged or corrupt.\n"
265 err_info != NULL ? err_info : "no information supplied");
269 case WTAP_ERR_DECOMPRESS:
270 cmdarg_err("The %s cannot be decompressed; it may be damaged or corrupt.\n"
273 err_info != NULL ? err_info : "no information supplied");
277 case WTAP_ERR_DECOMPRESSION_NOT_SUPPORTED:
278 cmdarg_err("The %s cannot be decompressed; it is compressed in a way that we don't support.\n"
281 err_info != NULL ? err_info : "no information supplied");
286 cmdarg_err("An error occurred while reading the %s: %s.",
287 file_string, wtap_strerror(err));
294 * Error message for a failed attempt to write to a capture file.
295 * "progname" is the name of the program trying to open the file;
296 * "in_filename" is the name of the file from which the record
297 * being written came; "out_filename" is the name of the file to
298 * which we're writing; "err" is assumed "err" is assumed to be a
299 * UNIX-style errno or a WTAP_ERR_ value; "err_info" is assumed to be
300 * a string giving further information for some WTAP_ERR_ values;
301 * "framenum" is the frame number of the record on which the error
302 * occurred; "file_type_subtype" is a WTAP_FILE_TYPE_SUBTYPE_ value
303 * for the type and subtype of file being written.
306 cfile_write_failure_message(const char *progname, const char *in_filename,
307 const char *out_filename, int err, gchar *err_info,
308 guint32 framenum, int file_type_subtype)
310 char *in_file_string;
311 char *in_frame_string;
312 char *out_file_string;
314 /* Get a string that describes what we're reading from */
315 if (in_filename == NULL) {
316 in_frame_string = g_strdup("");
318 in_file_string = input_file_description(in_filename);
319 in_frame_string = g_strdup_printf(" %u of %s", framenum,
321 g_free(in_file_string);
324 /* Get a string that describes what we're writing to */
325 out_file_string = output_file_description(out_filename);
329 case WTAP_ERR_UNWRITABLE_ENCAP:
331 * This is a problem with the particular frame we're writing
332 * and the file type and subtype we're writing; note that,
333 * and report the frame number and file type/subtype.
335 cmdarg_err("Frame%s has a network type that can't be saved in a \"%s\" file.",
337 wtap_file_type_subtype_short_string(file_type_subtype));
340 case WTAP_ERR_PACKET_TOO_LARGE:
342 * This is a problem with the particular frame we're writing
343 * and the file type and subtype we're writing; note that,
344 * and report the frame number and file type/subtype.
346 cmdarg_err("Frame%s is larger than %s supports in a \"%s\" file.",
347 in_frame_string, progname,
348 wtap_file_type_subtype_short_string(file_type_subtype));
351 case WTAP_ERR_UNWRITABLE_REC_TYPE:
353 * This is a problem with the particular record we're writing
354 * and the file type and subtype we're writing; note that,
355 * and report the record number and file type/subtype.
357 cmdarg_err("Record%s has a record type that can't be saved in a \"%s\" file.",
359 wtap_file_type_subtype_short_string(file_type_subtype));
362 case WTAP_ERR_UNWRITABLE_REC_DATA:
364 * This is a problem with the particular record we're writing
365 * and the file type and subtype we're writing; note that,
366 * and report the record number and file type/subtype.
368 cmdarg_err("Record%s has data that can't be saved in a \"%s\" file.\n"
371 wtap_file_type_subtype_short_string(file_type_subtype),
372 err_info != NULL ? err_info : "no information supplied");
377 cmdarg_err("Not all the packets could be written to the %s because there is "
378 "no space left on the file system.",
384 cmdarg_err("Not all the packets could be written to the %s because you are "
385 "too close to, or over your disk quota.",
390 case WTAP_ERR_SHORT_WRITE:
391 cmdarg_err("A full write couldn't be done to the %s.",
396 cmdarg_err("An error occurred while writing to the %s: %s.",
397 out_file_string, wtap_strerror(err));
400 g_free(in_frame_string);
401 g_free(out_file_string);
405 * Error message for a failed attempt to close a capture file.
406 * "filename" is the name of the file being closed; "err" is assumed
407 * to be a UNIX-style errno or a WTAP_ERR_ value.
409 * When closing a capture file:
411 * some information in the file that can't be determined until
412 * all packets have been written might be written to the file
413 * (such as a table of the file offsets of all packets);
415 * data buffered in the low-level file writing code might be
416 * flushed to the file;
418 * for remote file systems, data written to the file but not
419 * yet sent to the server might be sent to the server or, if
420 * that data was sent asynchronously, "out of space", "disk
421 * quota exceeded", or "I/O error" indications might have
422 * been received but not yet delivered, and the close operation
423 * could deliver them;
425 * so we have to check for write errors here.
428 cfile_close_failure_message(const char *filename, int err)
432 /* Get a string that describes what we're writing to */
433 file_string = output_file_description(filename);
438 cmdarg_err("Not all the packets could be written to the %s because there is "
439 "no space left on the file system.",
445 cmdarg_err("Not all the packets could be written to the %s because you are "
446 "too close to, or over your disk quota.",
451 case WTAP_ERR_CANT_CLOSE:
452 cmdarg_err("The %s couldn't be closed for some unknown reason.",
456 case WTAP_ERR_SHORT_WRITE:
457 cmdarg_err("A full write couldn't be done to the %s.",
462 cmdarg_err("An error occurred while closing the file %s: %s.",
463 file_string, wtap_strerror(err));