aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/file_access.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2012-06-17 01:32:50 +0000
committerGuy Harris <guy@alum.mit.edu>2012-06-17 01:32:50 +0000
commitc63aa61658903b0203cbfe1596a970cf541425ad (patch)
tree4f19cff5e52cab740848359985fadec8002cb650 /wiretap/file_access.c
parent5237a5efa28980a944083a6f5fef85bf1c8f69bc (diff)
Have wtap_get_savable_file_types() take an array of encapsulations and
only return file types that could handle a single file with all those encapsulations - this means that 1) if there's more then one encapsulation, the file format has to handle per-packet encapsulation; 2) just because a file format handles per-packet encapsulation, that doesn't mean that it can handle the *particular* encapsulations being handed to it. This fixes some cases where we were claiming that a file could be saved in a format that doesn't actually support it (e.g., ISDN files being reported as savable in pcap-NG format - there's no LINKTYPE_ value for ISDN including B and D channels). svn path=/trunk/; revision=43300
Diffstat (limited to 'wiretap/file_access.c')
-rw-r--r--wiretap/file_access.c49
1 files changed, 36 insertions, 13 deletions
diff --git a/wiretap/file_access.c b/wiretap/file_access.c
index 34dfaff038..8255cff423 100644
--- a/wiretap/file_access.c
+++ b/wiretap/file_access.c
@@ -766,19 +766,42 @@ int wtap_get_num_file_types(void)
* to save a file of a given type with a given WTAP_ENCAP_ type.
*/
static gboolean
-can_save_with_wiretap(int ft, int encap)
+can_save_with_wiretap(int ft, const GArray *file_encaps)
{
+ guint i;
+
/*
- * To save a file in a given file format, we have to handle that
- * format, and the code to handle that format must be able to
- * write a file with that file's encapsulation type.
+ * Can we write in this format?
*/
- return wtap_dump_can_open(ft) &&
- wtap_dump_can_write_encap(ft, encap);
+ if (!wtap_dump_can_open(ft)) {
+ /* No. */
+ return FALSE;
+ }
+
+ /*
+ * OK, we can write in that format; can we write out all the
+ * specified encapsulation types in that format?
+ */
+ if (file_encaps->len > 1) {
+ /*
+ * We have more than one encapsulation type,
+ * so that format needs to support
+ * WTAP_ENCAP_PER_PACKET.
+ */
+ if (!wtap_dump_can_write_encap(ft, WTAP_ENCAP_PER_PACKET))
+ return FALSE;
+ }
+
+ for (i = 0; i < file_encaps->len; i++) {
+ if (!wtap_dump_can_write_encap(ft,
+ g_array_index(file_encaps, int, i)))
+ return FALSE;
+ }
+ return TRUE;
}
GArray *
-wtap_get_savable_file_types(int file_type, int file_encap)
+wtap_get_savable_file_types(int file_type, const GArray *file_encaps)
{
GArray *savable_file_types;
int ft;
@@ -786,19 +809,19 @@ wtap_get_savable_file_types(int file_type, int file_encap)
int other_file_type = -1;
/* Can we save this file in its own file type? */
- if (can_save_with_wiretap(file_type, file_encap)) {
+ if (can_save_with_wiretap(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_encap)) {
+ if (can_save_with_wiretap(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_encap)) {
+ if (can_save_with_wiretap(ft, file_encaps)) {
/* OK, got it. */
default_file_type = ft;
}
@@ -820,10 +843,10 @@ wtap_get_savable_file_types(int file_type, int file_encap)
/* 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_encap))
+ if (can_save_with_wiretap(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_encap))
+ if (can_save_with_wiretap(WTAP_FILE_PCAP, file_encaps))
other_file_type = WTAP_FILE_PCAP;
}
if (other_file_type != -1)
@@ -835,7 +858,7 @@ wtap_get_savable_file_types(int file_type, int file_encap)
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_encap)) {
+ if (can_save_with_wiretap(ft, file_encaps)) {
/* OK, we can write it out in this type. */
g_array_append_val(savable_file_types, ft);
}