aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/wtap.c
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2021-02-01 15:56:47 -0800
committerGuy Harris <gharris@sonic.net>2021-02-01 16:50:01 -0800
commit0773147a5598f50d456a855e7169c50aa02df16f (patch)
treed76d7f769c0824876117c875a1364850ccac56a2 /wiretap/wtap.c
parent5837bcea5e347afd2a6e5860296de09cbb5a0b28 (diff)
wiretap: redo the way we handle if_filter IDB options.
Change the data structure for that option to have a type field, indicating that it's either a pcap filter string or a BPF program, followed by a union with a string-pointer member for pcap filter strings and an instruction-count-and-pointer-to-instructions structure for BPF programs. Have routines to add, set, and fetch that option that handle that structure; discard the "generic structured option" routines. That means there's more type checking possible at compile time. Add more code to handle BPF programs. When writing pcapng files, check, both for that option and for string options, whether the option length is too big for the data to fit in a pcapng option, and don't write it if it is. (XXX - truncate the data? Report an error?)
Diffstat (limited to 'wiretap/wtap.c')
-rw-r--r--wiretap/wtap.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/wiretap/wtap.c b/wiretap/wtap.c
index ff4479f68a..26615e3d3a 100644
--- a/wiretap/wtap.c
+++ b/wiretap/wtap.c
@@ -295,7 +295,7 @@ wtap_get_debug_if_descr(const wtap_block_t if_descr,
guint64 tmp64;
gint8 itmp8;
guint8 tmp8;
- wtapng_if_descr_filter_t* if_filter;
+ if_filter_opt_t if_filter;
g_assert(if_descr);
@@ -365,16 +365,30 @@ wtap_get_debug_if_descr(const wtap_block_t if_descr,
line_end);
}
- if (wtap_block_get_structured_option_value(if_descr, OPT_IDB_FILTER, (void**)&if_filter) == WTAP_OPTTYPE_SUCCESS) {
- g_string_append_printf(info,
- "%*cFilter string = %s%s", indent, ' ',
- if_filter->if_filter_str ? if_filter->if_filter_str : "NONE",
- line_end);
+ if (wtap_block_get_if_filter_option_value(if_descr, OPT_IDB_FILTER, &if_filter) == WTAP_OPTTYPE_SUCCESS) {
+ switch (if_filter.type) {
- g_string_append_printf(info,
- "%*cBPF filter length = %u%s", indent, ' ',
- if_filter->bpf_filter_len,
- line_end);
+ case if_filter_pcap:
+ g_string_append_printf(info,
+ "%*cFilter string = %s%s", indent, ' ',
+ if_filter.data.filter_str,
+ line_end);
+ break;
+
+ case if_filter_bpf:
+ g_string_append_printf(info,
+ "%*cBPF filter length = %u%s", indent, ' ',
+ if_filter.data.bpf_prog.bpf_prog_len,
+ line_end);
+ break;
+
+ default:
+ g_string_append_printf(info,
+ "%*cUnknown filter type %u%s", indent, ' ',
+ if_filter.type,
+ line_end);
+ break;
+ }
}
if (wtap_block_get_string_option_value(if_descr, OPT_IDB_OS, &tmp_content) == WTAP_OPTTYPE_SUCCESS) {