3 * Wireshark Protocol Analyzer Library
5 * Copyright (c) 2001 by Gerald Combs <gerald@wireshark.org>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <wsutil/wsgcrypt.h>
28 #endif /* HAVE_LIBGCRYPT */
31 #include <gnutls/gnutls.h>
32 #endif /* HAVE_LIBGNUTLS */
36 #include <wsutil/report_err.h>
38 #include <epan/exceptions.h>
42 #include "dfilter/dfilter.h"
43 #include "epan_dissect.h"
45 #include "conversation.h"
50 #include "column-utils.h"
52 #include "addr_resolv.h"
54 #include "wmem/wmem.h"
60 #include <wslua/wslua.h>
68 #include <ares_version.h>
71 static wmem_allocator_t *pinfo_pool_cache = NULL;
74 epan_get_version(void) {
79 * Register all the plugin types that are part of libwireshark, namely
80 * dissector and tap plugins.
82 * Must be called before init_plugins(), which must be called before
83 * any registration routines are called.
86 epan_register_plugin_types(void)
89 register_dissector_plugin_type();
90 register_tap_plugin_type();
95 epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_data),
96 void (*register_all_handoffs_func)(register_cb cb, gpointer client_data),
100 volatile gboolean status = TRUE;
102 /* initialize memory allocation subsystem */
105 /* initialize the GUID to name mapping table */
108 /* initialize name resolution (addr_resolv.c) */
112 #ifdef HAVE_LIBGCRYPT
113 /* initialize libgcrypt (beware, it won't be thread-safe) */
114 gcry_check_version(NULL);
115 gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
116 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
118 #ifdef HAVE_LIBGNUTLS
119 gnutls_global_init();
126 proto_init(register_all_protocols_func, register_all_handoffs_func,
128 packet_cache_proto_handles();
130 final_registration_all_protocols();
131 print_cache_field_handles();
132 expert_packet_init();
134 wslua_init(cb, client_data);
137 CATCH(DissectorError) {
139 * This is probably a dissector, or something it calls,
140 * calling REPORT_DISSECTOR_ERROR() in a registration
141 * routine or something else outside the normal dissection
144 const char *exception_message = GET_MESSAGE;
145 static const char dissector_error_nomsg[] =
146 "Dissector writer didn't bother saying what the error was";
148 report_failure("Dissector bug: %s",
149 exception_message == NULL ?
150 dissector_error_nomsg : exception_message);
151 if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
170 #ifdef HAVE_LIBGNUTLS
171 gnutls_global_deinit();
174 addr_resolv_cleanup();
176 if (pinfo_pool_cache != NULL) {
177 wmem_destroy_allocator(pinfo_pool_cache);
178 pinfo_pool_cache = NULL;
187 epan_t *session = g_slice_new(epan_t);
189 /* XXX, it should take session as param */
196 epan_get_user_comment(const epan_t *session, const frame_data *fd)
198 if (session->get_user_comment)
199 return session->get_user_comment(session->data, fd);
205 epan_get_interface_name(const epan_t *session, guint32 interface_id)
207 if (session->get_interface_name)
208 return session->get_interface_name(session->data, interface_id);
214 epan_get_frame_ts(const epan_t *session, guint32 frame_num)
216 const nstime_t *abs_ts = NULL;
218 if (session->get_frame_ts)
219 abs_ts = session->get_frame_ts(session->data, frame_num);
222 g_warning("!!! couldn't get frame ts for %u !!!\n", frame_num);
228 epan_free(epan_t *session)
231 /* XXX, it should take session as param */
232 cleanup_dissection();
234 g_slice_free(epan_t, session);
239 epan_conversation_init(void)
245 epan_conversation_cleanup(void)
247 conversation_cleanup();
251 epan_circuit_init(void)
257 epan_circuit_cleanup(void)
262 /* Overrides proto_tree_visible i epan_dissect_init to make all fields visible.
263 * This is > 0 if a Lua script wanted to see all fields all the time.
264 * This is ref-counted, so clearing it won't override other taps/scripts wanting it.
266 static gint always_visible_refcount = 0;
269 epan_set_always_visible(gboolean force)
272 always_visible_refcount++;
273 else if (always_visible_refcount > 0)
274 always_visible_refcount--;
278 epan_dissect_init(epan_dissect_t *edt, epan_t *session, const gboolean create_proto_tree, const gboolean proto_tree_visible)
282 edt->session = session;
284 memset(&edt->pi, 0, sizeof(edt->pi));
285 if (pinfo_pool_cache != NULL) {
286 edt->pi.pool = pinfo_pool_cache;
287 pinfo_pool_cache = NULL;
290 edt->pi.pool = wmem_allocator_new(WMEM_ALLOCATOR_BLOCK_FAST);
293 if (create_proto_tree) {
294 edt->tree = proto_tree_create_root(&edt->pi);
295 proto_tree_set_visible(edt->tree, (always_visible_refcount > 0) ? TRUE : proto_tree_visible);
307 epan_dissect_reset(epan_dissect_t *edt)
309 /* We have to preserve the pool pointer across the memzeroing */
310 wmem_allocator_t *tmp;
314 g_slist_free(edt->pi.proto_data);
315 g_slist_free(edt->pi.dependent_frames);
317 /* Free the data sources list. */
318 free_data_sources(&edt->pi);
321 /* Free all tvb's chained from this tvb */
322 tvb_free_chain(edt->tvb);
327 proto_tree_reset(edt->tree);
332 memset(&edt->pi, 0, sizeof(edt->pi));
337 epan_dissect_new(epan_t *session, const gboolean create_proto_tree, const gboolean proto_tree_visible)
341 edt = g_new0(epan_dissect_t, 1);
343 return epan_dissect_init(edt, session, create_proto_tree, proto_tree_visible);
347 epan_dissect_fake_protocols(epan_dissect_t *edt, const gboolean fake_protocols)
350 proto_tree_set_fake_protocols(edt->tree, fake_protocols);
354 epan_dissect_run(epan_dissect_t *edt, int file_type_subtype,
355 struct wtap_pkthdr *phdr, tvbuff_t *tvb, frame_data *fd,
359 wslua_prime_dfilter(edt); /* done before entering wmem scope */
361 wmem_enter_packet_scope();
362 dissect_record(edt, file_type_subtype, phdr, tvb, fd, cinfo);
364 /* free all memory allocated */
365 wmem_leave_packet_scope();
369 epan_dissect_run_with_taps(epan_dissect_t *edt, int file_type_subtype,
370 struct wtap_pkthdr *phdr, tvbuff_t *tvb, frame_data *fd,
373 wmem_enter_packet_scope();
375 dissect_record(edt, file_type_subtype, phdr, tvb, fd, cinfo);
376 tap_push_tapped_queue(edt);
378 /* free all memory allocated */
379 wmem_leave_packet_scope();
383 epan_dissect_file_run(epan_dissect_t *edt, struct wtap_pkthdr *phdr,
384 tvbuff_t *tvb, frame_data *fd, column_info *cinfo)
387 wslua_prime_dfilter(edt); /* done before entering wmem scope */
389 wmem_enter_packet_scope();
390 dissect_file(edt, phdr, tvb, fd, cinfo);
392 /* free all memory allocated */
393 wmem_leave_packet_scope();
397 epan_dissect_file_run_with_taps(epan_dissect_t *edt, struct wtap_pkthdr *phdr,
398 tvbuff_t *tvb, frame_data *fd, column_info *cinfo)
400 wmem_enter_packet_scope();
402 dissect_file(edt, phdr, tvb, fd, cinfo);
403 tap_push_tapped_queue(edt);
405 /* free all memory allocated */
406 wmem_leave_packet_scope();
410 epan_dissect_cleanup(epan_dissect_t* edt)
414 g_slist_free(edt->pi.proto_data);
415 g_slist_free(edt->pi.dependent_frames);
417 /* Free the data sources list. */
418 free_data_sources(&edt->pi);
421 /* Free all tvb's chained from this tvb */
422 tvb_free_chain(edt->tvb);
426 proto_tree_free(edt->tree);
429 if (pinfo_pool_cache == NULL) {
430 wmem_free_all(edt->pi.pool);
431 pinfo_pool_cache = edt->pi.pool;
434 wmem_destroy_allocator(edt->pi.pool);
439 epan_dissect_free(epan_dissect_t* edt)
441 epan_dissect_cleanup(edt);
446 epan_dissect_prime_dfilter(epan_dissect_t *edt, const dfilter_t* dfcode)
448 dfilter_prime_proto_tree(dfcode, edt->tree);
451 /* ----------------------- */
453 epan_custom_set(epan_dissect_t *edt, GSList *field_ids,
456 gchar *expr, const int size )
458 return proto_custom_set(edt->tree, field_ids, occurrence, result, expr, size);
462 epan_dissect_fill_in_columns(epan_dissect_t *edt, const gboolean fill_col_exprs, const gboolean fill_fd_colums)
464 col_custom_set_edt(edt, edt->pi.cinfo);
465 col_fill_in(&edt->pi, fill_col_exprs, fill_fd_colums);
469 epan_dissect_packet_contains_field(epan_dissect_t* edt,
470 const char *field_name)
474 gboolean contains_field;
476 if (!edt || !edt->tree)
478 field_id = proto_get_id_by_filter_name(field_name);
481 array = proto_find_finfo(edt->tree, field_id);
482 contains_field = (array->len > 0) ? TRUE : FALSE;
483 g_ptr_array_free(array, TRUE);
484 return contains_field;
488 * Get compile-time information for libraries used by libwireshark.
491 epan_get_compiled_version_info(GString *str)
494 g_string_append(str, ", ");
496 g_string_append(str, "with SMI " SMI_VERSION_STRING);
497 #else /* no SNMP library */
498 g_string_append(str, "without SMI");
502 g_string_append(str, ", ");
504 g_string_append(str, "with c-ares " ARES_VERSION_STR);
506 g_string_append(str, "without c-ares");
508 /* ADNS - only add if no c-ares */
509 g_string_append(str, ", ");
511 g_string_append(str, "with ADNS");
513 g_string_append(str, "without ADNS");
514 #endif /* HAVE_GNU_ADNS */
515 #endif /* HAVE_C_ARES */
518 g_string_append(str, ", ");
520 g_string_append(str, "with ");
521 g_string_append(str, LUA_VERSION);
523 g_string_append(str, "without Lua");
524 #endif /* HAVE_LUA */
527 g_string_append(str, ", ");
528 #ifdef HAVE_LIBGNUTLS
529 g_string_append(str, "with GnuTLS " LIBGNUTLS_VERSION);
531 g_string_append(str, "without GnuTLS");
532 #endif /* HAVE_LIBGNUTLS */
535 g_string_append(str, ", ");
536 #ifdef HAVE_LIBGCRYPT
537 g_string_append(str, "with Gcrypt " GCRYPT_VERSION);
539 g_string_append(str, "without Gcrypt");
540 #endif /* HAVE_LIBGCRYPT */
543 /* XXX - I don't see how to get the version number, at least for KfW */
544 g_string_append(str, ", ");
546 #ifdef HAVE_MIT_KERBEROS
547 g_string_append(str, "with MIT Kerberos");
549 /* HAVE_HEIMDAL_KERBEROS */
550 g_string_append(str, "with Heimdal Kerberos");
553 g_string_append(str, "without Kerberos");
554 #endif /* HAVE_KERBEROS */
557 g_string_append(str, ", ");
559 g_string_append(str, "with GeoIP");
561 g_string_append(str, "without GeoIP");
562 #endif /* HAVE_GEOIP */
567 * Get runtime information for libraries used by libwireshark.
570 epan_get_runtime_version_info(GString *str
571 #if !defined(HAVE_LIBGNUTLS) && !defined(HAVE_LIBGCRYPT)
577 #ifdef HAVE_LIBGNUTLS
578 g_string_append_printf(str, ", with GnuTLS %s", gnutls_check_version(NULL));
579 #endif /* HAVE_LIBGNUTLS */
582 #ifdef HAVE_LIBGCRYPT
583 g_string_append_printf(str, ", with Gcrypt %s", gcry_check_version(NULL));
584 #endif /* HAVE_LIBGCRYPT */
588 * Editor modelines - http://www.wireshark.org/tools/modelines.html
593 * indent-tabs-mode: t
596 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
597 * :indentSize=8:tabSize=8:noTabs=false: