[capture_info] Move capture_info_new_file() to capture.c
Change-Id: I9137af6461921d7553a8968743f61f2265424061 Reviewed-on: https://code.wireshark.org/review/24767 Petri-Dish: Anders Broman <a.broman58@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
parent
84f905786e
commit
c9546dfceb
126
capture_info.c
126
capture_info.c
|
@ -21,132 +21,6 @@
|
|||
|
||||
#include <epan/capture_dissectors.h>
|
||||
|
||||
#include <wsutil/filesystem.h>
|
||||
|
||||
|
||||
static const char *
|
||||
cf_open_error_message(int err, gchar *err_info, gboolean for_writing,
|
||||
int file_type)
|
||||
{
|
||||
const char *errmsg;
|
||||
static char errmsg_errno[1024+1];
|
||||
|
||||
if (err < 0) {
|
||||
/* Wiretap error. */
|
||||
switch (err) {
|
||||
|
||||
case WTAP_ERR_NOT_REGULAR_FILE:
|
||||
errmsg = "The file \"%s\" is a \"special file\" or socket or other non-regular file.";
|
||||
break;
|
||||
|
||||
case WTAP_ERR_FILE_UNKNOWN_FORMAT:
|
||||
/* Seen only when opening a capture file for reading. */
|
||||
errmsg = "The file \"%s\" isn't a capture file in a format Wireshark understands.";
|
||||
break;
|
||||
|
||||
case WTAP_ERR_UNSUPPORTED:
|
||||
/* Seen only when opening a capture file for reading. */
|
||||
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
|
||||
"The file \"%%s\" contains record data that Wireshark doesn't support.\n"
|
||||
"(%s)", err_info != NULL ? err_info : "no information supplied");
|
||||
g_free(err_info);
|
||||
errmsg = errmsg_errno;
|
||||
break;
|
||||
|
||||
case WTAP_ERR_CANT_WRITE_TO_PIPE:
|
||||
/* Seen only when opening a capture file for writing. */
|
||||
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
|
||||
"The file \"%%s\" is a pipe, and %s capture files can't be "
|
||||
"written to a pipe.", wtap_file_type_subtype_string(file_type));
|
||||
errmsg = errmsg_errno;
|
||||
break;
|
||||
|
||||
case WTAP_ERR_UNWRITABLE_FILE_TYPE:
|
||||
/* Seen only when opening a capture file for writing. */
|
||||
errmsg = "Wireshark doesn't support writing capture files in that format.";
|
||||
break;
|
||||
|
||||
case WTAP_ERR_UNWRITABLE_ENCAP:
|
||||
/* Seen only when opening a capture file for writing. */
|
||||
errmsg = "Wireshark can't save this capture in that format.";
|
||||
break;
|
||||
|
||||
case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED:
|
||||
if (for_writing)
|
||||
errmsg = "Wireshark can't save this capture in that format.";
|
||||
else
|
||||
errmsg = "The file \"%s\" is a capture for a network type that Wireshark doesn't support.";
|
||||
break;
|
||||
|
||||
case WTAP_ERR_BAD_FILE:
|
||||
/* Seen only when opening a capture file for reading. */
|
||||
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
|
||||
"The file \"%%s\" appears to be damaged or corrupt.\n"
|
||||
"(%s)", err_info != NULL ? err_info : "no information supplied");
|
||||
g_free(err_info);
|
||||
errmsg = errmsg_errno;
|
||||
break;
|
||||
|
||||
case WTAP_ERR_CANT_OPEN:
|
||||
if (for_writing)
|
||||
errmsg = "The file \"%s\" could not be created for some unknown reason.";
|
||||
else
|
||||
errmsg = "The file \"%s\" could not be opened for some unknown reason.";
|
||||
break;
|
||||
|
||||
case WTAP_ERR_SHORT_READ:
|
||||
errmsg = "The file \"%s\" appears to have been cut short"
|
||||
" in the middle of a packet or other data.";
|
||||
break;
|
||||
|
||||
case WTAP_ERR_SHORT_WRITE:
|
||||
errmsg = "A full header couldn't be written to the file \"%s\".";
|
||||
break;
|
||||
|
||||
case WTAP_ERR_DECOMPRESS:
|
||||
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
|
||||
"The compressed file \"%%s\" appears to be damaged or corrupt.\n"
|
||||
"(%s)", err_info != NULL ? err_info : "no information supplied");
|
||||
g_free(err_info);
|
||||
errmsg = errmsg_errno;
|
||||
break;
|
||||
|
||||
default:
|
||||
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
|
||||
"The file \"%%s\" could not be %s: %s.",
|
||||
for_writing ? "created" : "opened",
|
||||
wtap_strerror(err));
|
||||
errmsg = errmsg_errno;
|
||||
break;
|
||||
}
|
||||
} else
|
||||
errmsg = file_open_error_message(err, for_writing);
|
||||
return errmsg;
|
||||
}
|
||||
|
||||
/* new file arrived */
|
||||
gboolean capture_info_new_file(const char *new_filename, info_data_t* cap_info)
|
||||
{
|
||||
int err;
|
||||
gchar *err_info;
|
||||
gchar *err_msg;
|
||||
|
||||
|
||||
if(cap_info->wtap != NULL) {
|
||||
wtap_close(cap_info->wtap);
|
||||
}
|
||||
|
||||
cap_info->wtap = wtap_open_offline(new_filename, WTAP_TYPE_AUTO, &err, &err_info, FALSE);
|
||||
if (!cap_info->wtap) {
|
||||
err_msg = g_strdup_printf(cf_open_error_message(err, err_info, FALSE, WTAP_FILE_TYPE_SUBTYPE_UNKNOWN),
|
||||
new_filename);
|
||||
g_warning("capture_info_new_file: %d (%s)", err, err_msg);
|
||||
g_free (err_msg);
|
||||
return FALSE;
|
||||
} else
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
capture_info_packet(info_data_t* cap_info, gint wtap_linktype, const guchar *pd, guint32 caplen, union wtap_pseudo_header *pseudo_header)
|
||||
{
|
||||
|
|
|
@ -49,10 +49,6 @@ typedef struct _info_data {
|
|||
capture_info ui; /* user interface data */
|
||||
} info_data_t;
|
||||
|
||||
|
||||
/* new file arrived - (eventually close old wtap), open wtap */
|
||||
extern gboolean capture_info_new_file(const char *new_filename, info_data_t* cap_info);
|
||||
|
||||
/* new packets arrived - read from wtap, count */
|
||||
extern void capture_info_new_packets(int to_read, info_data_t* cap_info);
|
||||
|
||||
|
|
115
ui/capture.c
115
ui/capture.c
|
@ -39,6 +39,7 @@
|
|||
|
||||
#include "wsutil/file_util.h"
|
||||
#include "wsutil/str_util.h"
|
||||
#include <wsutil/filesystem.h>
|
||||
#include "log.h"
|
||||
|
||||
typedef struct if_stat_cache_item_s {
|
||||
|
@ -287,6 +288,106 @@ capture_input_read_all(capture_session *cap_session, gboolean is_tempfile,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static const char *
|
||||
cf_open_error_message(int err, gchar *err_info, gboolean for_writing,
|
||||
int file_type)
|
||||
{
|
||||
const char *errmsg;
|
||||
static char errmsg_errno[1024 + 1];
|
||||
|
||||
if (err < 0) {
|
||||
/* Wiretap error. */
|
||||
switch (err) {
|
||||
|
||||
case WTAP_ERR_NOT_REGULAR_FILE:
|
||||
errmsg = "The file \"%s\" is a \"special file\" or socket or other non-regular file.";
|
||||
break;
|
||||
|
||||
case WTAP_ERR_FILE_UNKNOWN_FORMAT:
|
||||
/* Seen only when opening a capture file for reading. */
|
||||
errmsg = "The file \"%s\" isn't a capture file in a format Wireshark understands.";
|
||||
break;
|
||||
|
||||
case WTAP_ERR_UNSUPPORTED:
|
||||
/* Seen only when opening a capture file for reading. */
|
||||
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
|
||||
"The file \"%%s\" contains record data that Wireshark doesn't support.\n"
|
||||
"(%s)", err_info != NULL ? err_info : "no information supplied");
|
||||
g_free(err_info);
|
||||
errmsg = errmsg_errno;
|
||||
break;
|
||||
|
||||
case WTAP_ERR_CANT_WRITE_TO_PIPE:
|
||||
/* Seen only when opening a capture file for writing. */
|
||||
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
|
||||
"The file \"%%s\" is a pipe, and %s capture files can't be "
|
||||
"written to a pipe.", wtap_file_type_subtype_string(file_type));
|
||||
errmsg = errmsg_errno;
|
||||
break;
|
||||
|
||||
case WTAP_ERR_UNWRITABLE_FILE_TYPE:
|
||||
/* Seen only when opening a capture file for writing. */
|
||||
errmsg = "Wireshark doesn't support writing capture files in that format.";
|
||||
break;
|
||||
|
||||
case WTAP_ERR_UNWRITABLE_ENCAP:
|
||||
/* Seen only when opening a capture file for writing. */
|
||||
errmsg = "Wireshark can't save this capture in that format.";
|
||||
break;
|
||||
|
||||
case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED:
|
||||
if (for_writing)
|
||||
errmsg = "Wireshark can't save this capture in that format.";
|
||||
else
|
||||
errmsg = "The file \"%s\" is a capture for a network type that Wireshark doesn't support.";
|
||||
break;
|
||||
|
||||
case WTAP_ERR_BAD_FILE:
|
||||
/* Seen only when opening a capture file for reading. */
|
||||
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
|
||||
"The file \"%%s\" appears to be damaged or corrupt.\n"
|
||||
"(%s)", err_info != NULL ? err_info : "no information supplied");
|
||||
g_free(err_info);
|
||||
errmsg = errmsg_errno;
|
||||
break;
|
||||
|
||||
case WTAP_ERR_CANT_OPEN:
|
||||
if (for_writing)
|
||||
errmsg = "The file \"%s\" could not be created for some unknown reason.";
|
||||
else
|
||||
errmsg = "The file \"%s\" could not be opened for some unknown reason.";
|
||||
break;
|
||||
|
||||
case WTAP_ERR_SHORT_READ:
|
||||
errmsg = "The file \"%s\" appears to have been cut short"
|
||||
" in the middle of a packet or other data.";
|
||||
break;
|
||||
|
||||
case WTAP_ERR_SHORT_WRITE:
|
||||
errmsg = "A full header couldn't be written to the file \"%s\".";
|
||||
break;
|
||||
|
||||
case WTAP_ERR_DECOMPRESS:
|
||||
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
|
||||
"The compressed file \"%%s\" appears to be damaged or corrupt.\n"
|
||||
"(%s)", err_info != NULL ? err_info : "no information supplied");
|
||||
g_free(err_info);
|
||||
errmsg = errmsg_errno;
|
||||
break;
|
||||
|
||||
default:
|
||||
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
|
||||
"The file \"%%s\" could not be %s: %s.",
|
||||
for_writing ? "created" : "opened",
|
||||
wtap_strerror(err));
|
||||
errmsg = errmsg_errno;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
errmsg = file_open_error_message(err, for_writing);
|
||||
return errmsg;
|
||||
}
|
||||
|
||||
/* capture child tells us we have a new (or the first) capture file */
|
||||
gboolean
|
||||
|
@ -295,6 +396,8 @@ capture_input_new_file(capture_session *cap_session, gchar *new_file)
|
|||
capture_options *capture_opts = cap_session->capture_opts;
|
||||
gboolean is_tempfile;
|
||||
int err;
|
||||
gchar *err_info;
|
||||
gchar *err_msg;
|
||||
|
||||
if(cap_session->state == CAPTURE_PREPARING) {
|
||||
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture started");
|
||||
|
@ -346,9 +449,19 @@ capture_input_new_file(capture_session *cap_session, gchar *new_file)
|
|||
}
|
||||
|
||||
if(capture_opts->show_info) {
|
||||
if (!capture_info_new_file(new_file, cap_session->cap_data_info))
|
||||
if (cap_session->cap_data_info->wtap != NULL) {
|
||||
wtap_close(cap_session->cap_data_info->wtap);
|
||||
}
|
||||
|
||||
cap_session->cap_data_info->wtap = wtap_open_offline(new_file, WTAP_TYPE_AUTO, &err, &err_info, FALSE);
|
||||
if (!cap_session->cap_data_info->wtap) {
|
||||
err_msg = g_strdup_printf(cf_open_error_message(err, err_info, FALSE, WTAP_FILE_TYPE_SUBTYPE_UNKNOWN),
|
||||
new_file);
|
||||
g_warning("capture_info_new_file: %d (%s)", err, err_msg);
|
||||
g_free(err_msg);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if(capture_opts->real_time_mode) {
|
||||
capture_callback_invoke(capture_cb_capture_update_started, cap_session);
|
||||
|
|
Loading…
Reference in New Issue