2 * Routines to put up various "standard" alert boxes 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
16 #include <wiretap/wtap.h>
17 #include <wsutil/filesystem.h>
19 #include "ui/alert_box.h"
21 #include "ui/simple_dialog.h"
24 * Alert box for general errors.
27 failure_alert_box(const char *msg_format, ...)
31 va_start(ap, msg_format);
32 vsimple_error_message_box(msg_format, ap);
37 vfailure_alert_box(const char *msg_format, va_list ap)
39 vsimple_error_message_box(msg_format, ap);
43 vwarning_alert_box(const char *msg_format, va_list ap)
45 vsimple_warning_message_box(msg_format, ap);
49 * Alert box for a failed attempt to open a capture file for reading.
50 * "filename" is the name of the file being opened; "err" is assumed
51 * to be a UNIX-style errno or a WTAP_ERR_ value; "err_info" is assumed
52 * to be a string giving further information for some WTAP_ERR_ values..
54 * XXX - add explanatory secondary text for at least some of the errors;
55 * various HIGs suggest that you should, for example, suggest that the
56 * user remove files if the file system is full. Perhaps that's because
57 * they're providing guidelines for people less sophisticated than the
58 * typical Wireshark user is, but....
61 cfile_open_failure_alert_box(const char *filename, int err, gchar *err_info)
63 gchar *display_basename;
67 display_basename = g_filename_display_basename(filename);
70 case WTAP_ERR_NOT_REGULAR_FILE:
71 simple_error_message_box(
72 "The file \"%s\" is a \"special file\" or socket or other non-regular file.",
76 case WTAP_ERR_RANDOM_OPEN_PIPE:
77 simple_error_message_box(
78 "The file \"%s\" is a pipe or FIFO; Wireshark can't read pipe or FIFO files.\n"
79 "To capture from a pipe or FIFO use wireshark -i -",
83 case WTAP_ERR_FILE_UNKNOWN_FORMAT:
84 simple_error_message_box(
85 "The file \"%s\" isn't a capture file in a format Wireshark understands.",
89 case WTAP_ERR_UNSUPPORTED:
90 simple_error_message_box(
91 "The file \"%s\" contains record data that Wireshark doesn't support.\n"
94 err_info != NULL ? err_info : "no information supplied");
98 case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED:
99 simple_error_message_box(
100 "The file \"%s\" is a capture for a network type that Wireshark doesn't support.",
104 case WTAP_ERR_BAD_FILE:
105 simple_error_message_box(
106 "The file \"%s\" appears to be damaged or corrupt.\n"
109 err_info != NULL ? err_info : "no information supplied");
113 case WTAP_ERR_CANT_OPEN:
114 simple_error_message_box(
115 "The file \"%s\" could not be opened for some unknown reason.",
119 case WTAP_ERR_SHORT_READ:
120 simple_error_message_box(
121 "The file \"%s\" appears to have been cut short"
122 " in the middle of a packet or other data.",
126 case WTAP_ERR_DECOMPRESS:
127 simple_error_message_box(
128 "The file \"%s\" cannot be decompressed; it may be damaged or corrupt.\n"
129 "(%s)", display_basename,
130 err_info != NULL ? err_info : "no information supplied");
134 case WTAP_ERR_DECOMPRESSION_NOT_SUPPORTED:
135 simple_error_message_box(
136 "The file \"%s\" cannot be decompressed; it is compressed in a way that we don't support.\n"
137 "(%s)", display_basename,
138 err_info != NULL ? err_info : "no information supplied");
143 simple_error_message_box(
144 "The file \"%s\" could not be opened: %s.",
149 g_free(display_basename);
152 open_failure_alert_box(filename, err, FALSE);
157 * Alert box for a failed attempt to open a capture file for writing.
158 * "filename" is the name of the file being opened; "err" is assumed
159 * to be a UNIX-style errno or a WTAP_ERR_ value; "file_type_subtype"
160 * is a WTAP_FILE_TYPE_SUBTYPE_ value for the type and subtype of file
163 * XXX - add explanatory secondary text for at least some of the errors;
164 * various HIGs suggest that you should, for example, suggest that the
165 * user remove files if the file system is full. Perhaps that's because
166 * they're providing guidelines for people less sophisticated than the
167 * typical Wireshark user is, but....
170 cfile_dump_open_failure_alert_box(const char *filename, int err,
171 int file_type_subtype)
173 gchar *display_basename;
177 display_basename = g_filename_display_basename(filename);
180 case WTAP_ERR_NOT_REGULAR_FILE:
181 simple_error_message_box(
182 "The file \"%s\" is a \"special file\" or socket or other non-regular file.",
186 case WTAP_ERR_CANT_WRITE_TO_PIPE:
187 simple_error_message_box(
188 "The file \"%s\" is a pipe, and %s capture files can't be "
189 "written to a pipe.",
190 display_basename, wtap_file_type_subtype_string(file_type_subtype));
193 case WTAP_ERR_UNWRITABLE_FILE_TYPE:
194 simple_error_message_box(
195 "Wireshark doesn't support writing capture files in that format.");
198 case WTAP_ERR_UNWRITABLE_ENCAP:
199 simple_error_message_box("Wireshark can't save this capture in that format.");
202 case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED:
203 simple_error_message_box(
204 "Wireshark can't save this capture in that format.");
207 case WTAP_ERR_CANT_OPEN:
208 simple_error_message_box(
209 "The file \"%s\" could not be created for some unknown reason.",
213 case WTAP_ERR_SHORT_WRITE:
214 simple_error_message_box(
215 "A full header couldn't be written to the file \"%s\".",
219 case WTAP_ERR_COMPRESSION_NOT_SUPPORTED:
220 simple_error_message_box(
221 "This file type cannot be written as a compressed file.");
225 simple_error_message_box(
226 "The file \"%s\" could not be created: %s.",
231 g_free(display_basename);
234 open_failure_alert_box(filename, err, TRUE);
239 * Alert box for a failed attempt to read from a capture file.
240 * "err" is assumed to be a UNIX-style errno or a WTAP_ERR_ value;
241 * "err_info" is assumed to be a string giving further information for
242 * some WTAP_ERR_ values.
245 cfile_read_failure_alert_box(const char *filename, int err, gchar *err_info)
249 if (filename == NULL)
250 display_name = g_strdup("capture file");
252 gchar *display_basename;
254 display_basename = g_filename_display_basename(filename);
255 display_name = g_strdup_printf("capture file \"%s\"", display_basename);
256 g_free(display_basename);
261 case WTAP_ERR_UNSUPPORTED:
262 simple_error_message_box(
263 "The %s contains record data that Wireshark doesn't support.\n"
266 err_info != NULL ? err_info : "no information supplied");
270 case WTAP_ERR_SHORT_READ:
271 simple_error_message_box(
272 "The %s appears to have been cut short in the middle of a packet.",
276 case WTAP_ERR_BAD_FILE:
277 simple_error_message_box(
278 "The %s appears to be damaged or corrupt.\n"
281 err_info != NULL ? err_info : "no information supplied");
285 case WTAP_ERR_DECOMPRESS:
286 simple_error_message_box(
287 "The %s cannot be decompressed; it may be damaged or corrupt.\n"
290 err_info != NULL ? err_info : "no information supplied");
294 case WTAP_ERR_DECOMPRESSION_NOT_SUPPORTED:
295 simple_error_message_box(
296 "The %s cannot be decompressed; it is compressed in a way that we don't support.\n"
299 err_info != NULL ? err_info : "no information supplied");
304 simple_error_message_box(
305 "An error occurred while reading the %s: %s.",
310 g_free(display_name);
314 * Alert box for a failed attempt to write to a capture file.
315 * "in_filename" is the name of the file from which the record being
316 * written came; "out_filename" is the name of the file to which we're
317 * writing; "err" is assumed "err" is assumed to be a UNIX-style errno
318 * or a WTAP_ERR_ value; "err_info" is assumed to be a string giving
319 * further information for some WTAP_ERR_ values; "framenum" is the frame
320 * number of the record on which the error occurred; "file_type_subtype"
321 * is a WTAP_FILE_TYPE_SUBTYPE_ value for the type and subtype of file
325 cfile_write_failure_alert_box(const char *in_filename, const char *out_filename,
326 int err, gchar *err_info, guint32 framenum,
327 int file_type_subtype)
329 char *in_file_string;
330 char *out_display_basename;
334 if (in_filename == NULL)
335 in_file_string = g_strdup("");
337 in_file_string = g_strdup_printf(" of file \"%s\"", in_filename);
341 case WTAP_ERR_UNWRITABLE_ENCAP:
343 * This is a problem with the particular frame we're writing and
344 * the file type and subtype we're writing; note that, and report
345 * the frame number and file type/subtype.
347 simple_error_message_box(
348 "Frame %u%s has a network type that can't be saved in a \"%s\" file.",
349 framenum, in_file_string,
350 wtap_file_type_subtype_string(file_type_subtype));
353 case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED:
355 * This is a problem with the particular frame we're writing and
356 * the file type and subtype we're writing; note that, and report
357 * the frame number and file type/subtype.
359 simple_error_message_box(
360 "Frame %u%s has a network type that differs from the network type of earlier packets, which isn't supported in a \"%s\" file.",
361 framenum, in_file_string,
362 wtap_file_type_subtype_string(file_type_subtype));
365 case WTAP_ERR_PACKET_TOO_LARGE:
367 * This is a problem with the particular frame we're writing and
368 * the file type and subtype we're writing; note that, and report
369 * the frame number and file type/subtype.
371 simple_error_message_box(
372 "Frame %u%s is larger than Wireshark supports in a \"%s\" file.",
373 framenum, in_file_string,
374 wtap_file_type_subtype_string(file_type_subtype));
377 case WTAP_ERR_UNWRITABLE_REC_TYPE:
379 * This is a problem with the particular record we're writing and
380 * the file type and subtype we're writing; note that, and report
381 * the record number and file type/subtype.
383 simple_error_message_box(
384 "Record %u%s has a record type that can't be saved in a \"%s\" file.",
385 framenum, in_file_string,
386 wtap_file_type_subtype_string(file_type_subtype));
389 case WTAP_ERR_UNWRITABLE_REC_DATA:
391 * This is a problem with the particular record we're writing and
392 * the file type and subtype we're writing; note that, and report
393 * the record number and file type/subtype.
395 simple_error_message_box(
396 "Record %u%s has data that can't be saved in a \"%s\" file.\n"
398 framenum, in_file_string,
399 wtap_file_type_subtype_string(file_type_subtype),
400 err_info != NULL ? err_info : "no information supplied");
404 case WTAP_ERR_SHORT_WRITE:
405 out_display_basename = g_filename_display_basename(out_filename);
406 simple_error_message_box(
407 "A full write couldn't be done to the file \"%s\".",
408 out_display_basename);
409 g_free(out_display_basename);
413 out_display_basename = g_filename_display_basename(out_filename);
414 simple_error_message_box(
415 "An error occurred while writing to the file \"%s\": %s.",
416 out_display_basename, wtap_strerror(err));
417 g_free(out_display_basename);
420 g_free(in_file_string);
423 write_failure_alert_box(out_filename, err);
428 * Alert box for a failed attempt to close a capture file.
429 * "err" is assumed to be a UNIX-style errno or a WTAP_ERR_ value.
431 * When closing a capture file:
433 * some information in the file that can't be determined until
434 * all packets have been written might be written to the file
435 * (such as a table of the file offsets of all packets);
437 * data buffered in the low-level file writing code might be
438 * flushed to the file;
440 * for remote file systems, data written to the file but not
441 * yet sent to the server might be sent to the server or, if
442 * that data was sent asynchronously, "out of space", "disk
443 * quota exceeded", or "I/O error" indications might have
444 * been received but not yet delivered, and the close operation
445 * could deliver them;
447 * so we have to check for write errors here.
449 * XXX - add explanatory secondary text for at least some of the errors;
450 * various HIGs suggest that you should, for example, suggest that the
451 * user remove files if the file system is full. Perhaps that's because
452 * they're providing guidelines for people less sophisticated than the
453 * typical Wireshark user is, but....
456 cfile_close_failure_alert_box(const char *filename, int err)
458 gchar *display_basename;
462 display_basename = g_filename_display_basename(filename);
465 case WTAP_ERR_CANT_CLOSE:
466 simple_error_message_box(
467 "The file \"%s\" couldn't be closed for some unknown reason.",
471 case WTAP_ERR_SHORT_WRITE:
472 simple_error_message_box(
473 "A full write couldn't be done to the file \"%s\".",
478 simple_error_message_box(
479 "An error occurred while closing the file \"%s\": %s.",
480 display_basename, wtap_strerror(err));
483 g_free(display_basename);
486 We assume that a close error from the OS is really a write error. */
487 write_failure_alert_box(filename, err);
492 * Alert box for a failed attempt to open or create a file.
493 * "err" is assumed to be a UNIX-style errno; "for_writing" is TRUE if
494 * the file is being opened for writing and FALSE if it's being opened
497 * XXX - add explanatory secondary text for at least some of the errors;
498 * various HIGs suggest that you should, for example, suggest that the
499 * user remove files if the file system is full. Perhaps that's because
500 * they're providing guidelines for people less sophisticated than the
501 * typical Wireshark user is, but....
504 open_failure_alert_box(const char *filename, int err, gboolean for_writing)
506 gchar *display_basename;
508 display_basename = g_filename_display_basename(filename);
509 simple_message_box(ESD_TYPE_ERROR, NULL, NULL,
510 file_open_error_message(err, for_writing),
512 g_free(display_basename);
516 * Alert box for a failed attempt to read a file.
517 * "err" is assumed to be a UNIX-style errno.
520 read_failure_alert_box(const char *filename, int err)
522 gchar *display_basename;
524 display_basename = g_filename_display_basename(filename);
525 simple_message_box(ESD_TYPE_ERROR, NULL, NULL,
526 "An error occurred while reading from the file \"%s\": %s.",
527 display_basename, g_strerror(err));
528 g_free(display_basename);
532 * Alert box for a failed attempt to write to a file.
533 * "err" is assumed to be a UNIX-style errno if positive and a
534 * Wiretap error if negative.
536 * XXX - add explanatory secondary text for at least some of the errors;
537 * various HIGs suggest that you should, for example, suggest that the
538 * user remove files if the file system is full. Perhaps that's because
539 * they're providing guidelines for people less sophisticated than the
540 * typical Wireshark user is, but....
543 write_failure_alert_box(const char *filename, int err)
545 gchar *display_basename;
547 display_basename = g_filename_display_basename(filename);
551 case WTAP_ERR_SHORT_WRITE:
552 simple_message_box(ESD_TYPE_ERROR, NULL, NULL,
553 "A full write couldn't be done to the file \"%s\".",
558 simple_message_box(ESD_TYPE_ERROR, NULL, NULL,
559 "An error occurred while writing to the file \"%s\": %s.",
560 display_basename, wtap_strerror(err));
564 simple_message_box(ESD_TYPE_ERROR, NULL, NULL,
565 file_write_error_message(err), display_basename);
567 g_free(display_basename);
576 * indent-tabs-mode: nil
579 * ex: set shiftwidth=4 tabstop=8 expandtab:
580 * :indentSize=4:tabSize=8:noTabs=true: