5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <epan/packet.h>
29 #include "tvbuff-int.h"
31 static int proto_mime_encap
= -1;
33 static heur_dissector_list_t heur_subdissector_list
;
34 static dissector_handle_t data_handle
;
36 static tvbuff_t
*file_tvbs
;
37 static tvbuff_t
*whole_tvb
;
43 tvb_free_chain(file_tvbs
);
50 dissect_mime_encap(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
57 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "MIME_FILE");
58 item
= proto_tree_add_item(tree
, proto_mime_encap
, tvb
, 0, -1, ENC_NA
);
60 /* frames with nsec >= 1000000000 means errors :) */
61 if (pinfo
->fd
->abs_ts
.nsecs
>= 1000000000) {
62 proto_item_append_text(item
, " (Error)");
63 /* return; */ /* dissect what we have */
66 len
= tvb_length(tvb
);
67 if (!pinfo
->fd
->flags
.visited
) {
69 tvbuff_t
*cloned_tvb
= tvb_clone(tvb
);
72 file_tvbs
= cloned_tvb
;
73 whole_tvb
= tvb_new_composite();
75 tvb_add_to_chain(file_tvbs
, cloned_tvb
);
77 tvb_composite_append(whole_tvb
, cloned_tvb
);
79 tvb_composite_finalize(whole_tvb
);
83 if (!len
&& whole_tvb
) {
85 * Here we're doing some trick.
87 * We don't want to call dissectors with composite tvb, cause dissectors can create subsets or real data child
88 * on it, which would append to whole_tvb chain and would be freed only in mime_encap_init.
90 * So we create some tvb which pass all calls to whole_tvb, but chain with tvb (which is freed in dissection cleanup)
92 tvbuff_t
*tmp_tvb
= tvb_new_chain(tvb
, whole_tvb
);
94 proto_item_append_text(item
, " (Final)");
96 add_new_data_source(pinfo
, tmp_tvb
, "Whole file");
98 if (!dissector_try_heuristic(heur_subdissector_list
, tmp_tvb
, pinfo
, tree
, NULL
)) {
99 proto_item_append_text(item
, " (Unhandled)");
100 call_dissector(data_handle
, tmp_tvb
, pinfo
, tree
);
106 proto_register_mime_encap(void)
108 proto_mime_encap
= proto_register_protocol("MIME file", "MIME_FILE", "mime_dlt");
110 register_dissector("mime_dlt", dissect_mime_encap
, proto_mime_encap
);
111 register_init_routine(mime_encap_init
);
112 register_heur_dissector_list("wtap_file", &heur_subdissector_list
);
116 proto_reg_handoff_mime_encap(void)
118 dissector_handle_t mime_encap_handle
;
120 data_handle
= find_dissector("data");
121 mime_encap_handle
= find_dissector("mime_dlt");
122 dissector_add_uint("wtap_encap", WTAP_ENCAP_MIME
, mime_encap_handle
);