Export a wtap_dump_can_write_encaps() routine from Wiretap; it takes a

file type and a GArray of encapsulation types and returns TRUE if a
capture with all those encapsulation types can be written to a file in
that file type and FALSE otherwise.  Use it where appropriate.

svn path=/trunk/; revision=43315
This commit is contained in:
Guy Harris 2012-06-17 16:44:09 +00:00
parent 4ad0bf65f2
commit 2bd813507a
5 changed files with 28 additions and 28 deletions

4
file.c
View File

@ -3843,8 +3843,8 @@ cf_can_save_as(capture_file *cf)
for (ft = 0; ft < WTAP_NUM_FILE_TYPES; ft++) {
/* To save a file with Wiretap, Wiretap has to handle that format,
and its code to handle that format must be able to write a file
with this file's encapsulation type. */
if (wtap_dump_can_open(ft) && wtap_dump_can_write_encap(ft, cf->lnk_t)) {
with this file's encapsulation types. */
if (wtap_dump_can_write_encaps(ft, cf->linktypes)) {
/* OK, we can write it out in this type. */
return TRUE;
}

View File

@ -1503,19 +1503,6 @@ open_file_hook_proc(HWND of_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
return 0;
}
/* XXX - Copied verbatim from ui/gtk/capture_file_dlg.c. Perhaps it
* should be in wiretap instead?
*/
static gboolean
can_save_with_wiretap(int ft)
{
/* To save a file with Wiretap, Wiretap has to handle that format,
and its code to handle that format must be able to write a file
with this file's encapsulation type. */
return wtap_dump_can_open(ft) && wtap_dump_can_write_encap(ft, cfile.lnk_t);
}
/* Generate a list of the file types we can save this file as.
"filetype" is the type it has now.
@ -1651,7 +1638,7 @@ build_file_format_list(HWND sf_hwnd) {
if (!packet_range_process_all(&g_range) || ft != cfile.cd_t) {
/* not all unfiltered packets or a different file type. We have to use Wiretap. */
if (!can_save_with_wiretap(ft))
if (!wtap_can_save_with_wiretap(ft, cfile.linktypes))
continue; /* We can't. */
}
@ -1707,7 +1694,7 @@ save_as_file_hook_proc(HWND sf_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
new_filetype = SendMessage(cur_ctrl, CB_GETITEMDATA, (WPARAM) index, 0);
if (new_filetype != CB_ERR) {
if (filetype != new_filetype) {
if (can_save_with_wiretap(new_filetype)) {
if (wtap_can_save_with_wiretap(new_filetype, cfile.linktypes)) {
cur_ctrl = GetDlgItem(sf_hwnd, EWFD_CAPTURED_BTN);
EnableWindow(cur_ctrl, TRUE);
cur_ctrl = GetDlgItem(sf_hwnd, EWFD_DISPLAYED_BTN);
@ -1810,7 +1797,7 @@ export_specified_packets_file_hook_proc(HWND sf_hwnd, UINT msg, WPARAM w_param,
new_filetype = SendMessage(cur_ctrl, CB_GETITEMDATA, (WPARAM) index, 0);
if (new_filetype != CB_ERR) {
if (filetype != new_filetype) {
if (can_save_with_wiretap(new_filetype)) {
if (wtap_can_save_with_wiretap(new_filetype, cfile.linktypes)) {
cur_ctrl = GetDlgItem(sf_hwnd, EWFD_CAPTURED_BTN);
EnableWindow(cur_ctrl, TRUE);
cur_ctrl = GetDlgItem(sf_hwnd, EWFD_DISPLAYED_BTN);

View File

@ -762,11 +762,11 @@ int wtap_get_num_file_types(void)
}
/*
* Get a GArray of WTAP_FILE_ values for file types that can be used
* to save a file of a given type with a given WTAP_ENCAP_ type.
* Return TRUE if a capture with a given GArray of WTAP_ENCAP_ types
* can be written in a specified format, and FALSE if it can't.
*/
static gboolean
can_save_with_wiretap(int ft, const GArray *file_encaps)
gboolean
wtap_dump_can_write_encaps(int ft, const GArray *file_encaps)
{
guint i;
@ -800,6 +800,11 @@ can_save_with_wiretap(int ft, const GArray *file_encaps)
return TRUE;
}
/*
* Get a GArray of WTAP_FILE_ values for file types that can be used
* to save a file of a given type with a given GArray of WTAP_ENCAP_
* types.
*/
GArray *
wtap_get_savable_file_types(int file_type, const GArray *file_encaps)
{
@ -809,19 +814,19 @@ wtap_get_savable_file_types(int file_type, const GArray *file_encaps)
int other_file_type = -1;
/* Can we save this file in its own file type? */
if (can_save_with_wiretap(file_type, file_encaps)) {
if (wtap_dump_can_write(file_type, file_encaps)) {
/* Yes - make that the default file type. */
default_file_type = file_type;
} else {
/* No - can we save it as a pcap-NG file? */
if (can_save_with_wiretap(WTAP_FILE_PCAPNG, file_encaps)) {
if (wtap_dump_can_write(WTAP_FILE_PCAPNG, file_encaps)) {
/* Yes - default to pcap-NG, instead. */
default_file_type = WTAP_FILE_PCAPNG;
} else {
/* OK, find the first file type we *can* save it as. */
default_file_type = -1;
for (ft = 0; ft < WTAP_NUM_FILE_TYPES; ft++) {
if (can_save_with_wiretap(ft, file_encaps)) {
if (wtap_dump_can_write(ft, file_encaps)) {
/* OK, got it. */
default_file_type = ft;
}
@ -843,10 +848,10 @@ wtap_get_savable_file_types(int file_type, const GArray *file_encaps)
/* If it's pcap, put pcap-NG right after it; otherwise, if it's
pcap-NG, put pcap right after it. */
if (default_file_type == WTAP_FILE_PCAP) {
if (can_save_with_wiretap(WTAP_FILE_PCAPNG, file_encaps))
if (wtap_dump_can_write(WTAP_FILE_PCAPNG, file_encaps))
other_file_type = WTAP_FILE_PCAPNG;
} else if (default_file_type == WTAP_FILE_PCAPNG) {
if (can_save_with_wiretap(WTAP_FILE_PCAP, file_encaps))
if (wtap_dump_can_write(WTAP_FILE_PCAP, file_encaps))
other_file_type = WTAP_FILE_PCAP;
}
if (other_file_type != -1)
@ -858,7 +863,7 @@ wtap_get_savable_file_types(int file_type, const GArray *file_encaps)
continue; /* not a real file type */
if (ft == default_file_type || ft == other_file_type)
continue; /* we've already done this one */
if (can_save_with_wiretap(ft, file_encaps)) {
if (wtap_dump_can_write(ft, file_encaps)) {
/* OK, we can write it out in this type. */
g_array_append_val(savable_file_types, ft);
}

View File

@ -30,6 +30,7 @@ wtap_default_file_extension
wtap_dump
wtap_dump_can_open
wtap_dump_can_write_encap
wtap_dump_can_write_encaps
wtap_dump_can_compress
wtap_dump_close
wtap_dump_fdopen

View File

@ -1097,6 +1097,13 @@ void wtap_close(wtap *wth);
/*** dump packets into a capture file ***/
gboolean wtap_dump_can_open(int filetype);
gboolean wtap_dump_can_write_encap(int filetype, int encap);
/**
* Return TRUE if a capture with a given GArray of WTAP_ENCAP_ types
* can be written in a specified format, and FALSE if it can't.
*/
gboolean wtap_dump_can_write_encaps(int ft, const GArray *file_encaps);
gboolean wtap_dump_can_compress(int filetype);
gboolean wtap_dump_has_name_resolution(int filetype);