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.
26 #include <wsutil/wsgcrypt.h>
29 #include <gnutls/gnutls.h>
30 #endif /* HAVE_LIBGNUTLS */
34 #include <wsutil/report_err.h>
36 #include <epan/exceptions.h>
40 #include "dfilter/dfilter.h"
41 #include "epan_dissect.h"
43 #include "conversation.h"
48 #include "column-utils.h"
50 #include "addr_resolv.h"
52 #include "wmem/wmem.h"
58 #include <wslua/wslua.h>
66 #include <ares_version.h>
69 static wmem_allocator_t *pinfo_pool_cache = NULL;
72 epan_get_version(void) {
77 * Register all the plugin types that are part of libwireshark, namely
78 * dissector and tap plugins.
80 * Must be called before init_plugins(), which must be called before
81 * any registration routines are called.
84 epan_register_plugin_types(void)
87 register_dissector_plugin_type();
88 register_tap_plugin_type();
93 epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_data),
94 void (*register_all_handoffs_func)(register_cb cb, gpointer client_data),
98 volatile gboolean status = TRUE;
100 /* initialize memory allocation subsystem */
103 /* initialize the GUID to name mapping table */
106 /* initialize name resolution (addr_resolv.c) */
110 #ifdef HAVE_LIBGCRYPT
111 /* initialize libgcrypt (beware, it won't be thread-safe) */
112 gcry_check_version(NULL);
113 gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
114 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
116 #ifdef HAVE_LIBGNUTLS
117 gnutls_global_init();
124 proto_init(register_all_protocols_func, register_all_handoffs_func,
126 packet_cache_proto_handles();
128 final_registration_all_protocols();
129 print_cache_field_handles();
130 expert_packet_init();
132 wslua_init(cb, client_data);
135 CATCH(DissectorError) {
137 * This is probably a dissector, or something it calls,
138 * calling REPORT_DISSECTOR_ERROR() in a registration
139 * routine or something else outside the normal dissection
142 const char *exception_message = GET_MESSAGE;
143 static const char dissector_error_nomsg[] =
144 "Dissector writer didn't bother saying what the error was";
146 report_failure("Dissector bug: %s",
147 exception_message == NULL ?
148 dissector_error_nomsg : exception_message);
149 if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
168 #ifdef HAVE_LIBGNUTLS
169 gnutls_global_deinit();
172 addr_resolv_cleanup();
174 if (pinfo_pool_cache != NULL) {
175 wmem_destroy_allocator(pinfo_pool_cache);
176 pinfo_pool_cache = NULL;
185 epan_t *session = g_slice_new(epan_t);
187 /* XXX, it should take session as param */
194 epan_get_user_comment(const epan_t *session, const frame_data *fd)
196 if (session->get_user_comment)
197 return session->get_user_comment(session->data, fd);
203 epan_get_interface_name(const epan_t *session, guint32 interface_id)
205 if (session->get_interface_name)
206 return session->get_interface_name(session->data, interface_id);
212 epan_get_frame_ts(const epan_t *session, guint32 frame_num)
214 const nstime_t *abs_ts = NULL;
216 if (session->get_frame_ts)
217 abs_ts = session->get_frame_ts(session->data, frame_num);
220 g_warning("!!! couldn't get frame ts for %u !!!\n", frame_num);
226 epan_free(epan_t *session)
229 /* XXX, it should take session as param */
230 cleanup_dissection();
232 g_slice_free(epan_t, session);
237 epan_conversation_init(void)
243 epan_conversation_cleanup(void)
245 conversation_cleanup();
249 epan_circuit_init(void)
255 epan_circuit_cleanup(void)
260 /* Overrides proto_tree_visible i epan_dissect_init to make all fields visible.
261 * This is > 0 if a Lua script wanted to see all fields all the time.
262 * This is ref-counted, so clearing it won't override other taps/scripts wanting it.
264 static gint always_visible_refcount = 0;
267 epan_set_always_visible(gboolean force)
270 always_visible_refcount++;
271 else if (always_visible_refcount > 0)
272 always_visible_refcount--;
276 epan_dissect_init(epan_dissect_t *edt, epan_t *session, const gboolean create_proto_tree, const gboolean proto_tree_visible)
280 edt->session = session;
282 memset(&edt->pi, 0, sizeof(edt->pi));
283 if (pinfo_pool_cache != NULL) {
284 edt->pi.pool = pinfo_pool_cache;
285 pinfo_pool_cache = NULL;
288 edt->pi.pool = wmem_allocator_new(WMEM_ALLOCATOR_BLOCK_FAST);
291 if (create_proto_tree) {
292 edt->tree = proto_tree_create_root(&edt->pi);
293 proto_tree_set_visible(edt->tree, (always_visible_refcount > 0) ? TRUE : proto_tree_visible);
305 epan_dissect_reset(epan_dissect_t *edt)
307 /* We have to preserve the pool pointer across the memzeroing */
308 wmem_allocator_t *tmp;
312 g_slist_free(edt->pi.proto_data);
313 g_slist_free(edt->pi.dependent_frames);
315 /* Free the data sources list. */
316 free_data_sources(&edt->pi);
319 /* Free all tvb's chained from this tvb */
320 tvb_free_chain(edt->tvb);
325 proto_tree_reset(edt->tree);
330 memset(&edt->pi, 0, sizeof(edt->pi));
335 epan_dissect_new(epan_t *session, const gboolean create_proto_tree, const gboolean proto_tree_visible)
339 edt = g_new0(epan_dissect_t, 1);
341 return epan_dissect_init(edt, session, create_proto_tree, proto_tree_visible);
345 epan_dissect_fake_protocols(epan_dissect_t *edt, const gboolean fake_protocols)
348 proto_tree_set_fake_protocols(edt->tree, fake_protocols);
352 epan_dissect_run(epan_dissect_t *edt, int file_type_subtype,
353 struct wtap_pkthdr *phdr, tvbuff_t *tvb, frame_data *fd,
357 wslua_prime_dfilter(edt); /* done before entering wmem scope */
359 wmem_enter_packet_scope();
360 dissect_record(edt, file_type_subtype, phdr, tvb, fd, cinfo);
362 /* free all memory allocated */
363 wmem_leave_packet_scope();
367 epan_dissect_run_with_taps(epan_dissect_t *edt, int file_type_subtype,
368 struct wtap_pkthdr *phdr, tvbuff_t *tvb, frame_data *fd,
371 wmem_enter_packet_scope();
373 dissect_record(edt, file_type_subtype, phdr, tvb, fd, cinfo);
374 tap_push_tapped_queue(edt);
376 /* free all memory allocated */
377 wmem_leave_packet_scope();
381 epan_dissect_file_run(epan_dissect_t *edt, struct wtap_pkthdr *phdr,
382 tvbuff_t *tvb, frame_data *fd, column_info *cinfo)
385 wslua_prime_dfilter(edt); /* done before entering wmem scope */
387 wmem_enter_packet_scope();
388 dissect_file(edt, phdr, tvb, fd, cinfo);
390 /* free all memory allocated */
391 wmem_leave_packet_scope();
395 epan_dissect_file_run_with_taps(epan_dissect_t *edt, struct wtap_pkthdr *phdr,
396 tvbuff_t *tvb, frame_data *fd, column_info *cinfo)
398 wmem_enter_packet_scope();
400 dissect_file(edt, phdr, tvb, fd, cinfo);
401 tap_push_tapped_queue(edt);
403 /* free all memory allocated */
404 wmem_leave_packet_scope();
408 epan_dissect_cleanup(epan_dissect_t* edt)
412 g_slist_free(edt->pi.proto_data);
413 g_slist_free(edt->pi.dependent_frames);
415 /* Free the data sources list. */
416 free_data_sources(&edt->pi);
419 /* Free all tvb's chained from this tvb */
420 tvb_free_chain(edt->tvb);
424 proto_tree_free(edt->tree);
427 if (pinfo_pool_cache == NULL) {
428 wmem_free_all(edt->pi.pool);
429 pinfo_pool_cache = edt->pi.pool;
432 wmem_destroy_allocator(edt->pi.pool);
437 epan_dissect_free(epan_dissect_t* edt)
439 epan_dissect_cleanup(edt);
444 epan_dissect_prime_dfilter(epan_dissect_t *edt, const dfilter_t* dfcode)
446 dfilter_prime_proto_tree(dfcode, edt->tree);
449 /* ----------------------- */
451 epan_custom_set(epan_dissect_t *edt, GSList *field_ids,
454 gchar *expr, const int size )
456 return proto_custom_set(edt->tree, field_ids, occurrence, result, expr, size);
460 epan_dissect_fill_in_columns(epan_dissect_t *edt, const gboolean fill_col_exprs, const gboolean fill_fd_colums)
462 col_custom_set_edt(edt, edt->pi.cinfo);
463 col_fill_in(&edt->pi, fill_col_exprs, fill_fd_colums);
467 epan_dissect_packet_contains_field(epan_dissect_t* edt,
468 const char *field_name)
472 gboolean contains_field;
474 if (!edt || !edt->tree)
476 field_id = proto_get_id_by_filter_name(field_name);
479 array = proto_find_finfo(edt->tree, field_id);
480 contains_field = (array->len > 0) ? TRUE : FALSE;
481 g_ptr_array_free(array, TRUE);
482 return contains_field;
486 * Get compile-time information for libraries used by libwireshark.
489 epan_get_compiled_version_info(GString *str)
492 g_string_append(str, ", ");
494 g_string_append(str, "with SMI " SMI_VERSION_STRING);
495 #else /* no SNMP library */
496 g_string_append(str, "without SMI");
500 g_string_append(str, ", ");
502 g_string_append(str, "with c-ares " ARES_VERSION_STR);
504 g_string_append(str, "without c-ares");
506 /* ADNS - only add if no c-ares */
507 g_string_append(str, ", ");
509 g_string_append(str, "with ADNS");
511 g_string_append(str, "without ADNS");
512 #endif /* HAVE_GNU_ADNS */
513 #endif /* HAVE_C_ARES */
516 g_string_append(str, ", ");
518 g_string_append(str, "with ");
519 g_string_append(str, LUA_VERSION);
521 g_string_append(str, "without Lua");
522 #endif /* HAVE_LUA */
525 g_string_append(str, ", ");
526 #ifdef HAVE_LIBGNUTLS
527 g_string_append(str, "with GnuTLS " LIBGNUTLS_VERSION);
529 g_string_append(str, "without GnuTLS");
530 #endif /* HAVE_LIBGNUTLS */
533 g_string_append(str, ", ");
534 #ifdef HAVE_LIBGCRYPT
535 g_string_append(str, "with Gcrypt " GCRYPT_VERSION);
537 g_string_append(str, "without Gcrypt");
538 #endif /* HAVE_LIBGCRYPT */
541 /* XXX - I don't see how to get the version number, at least for KfW */
542 g_string_append(str, ", ");
544 #ifdef HAVE_MIT_KERBEROS
545 g_string_append(str, "with MIT Kerberos");
547 /* HAVE_HEIMDAL_KERBEROS */
548 g_string_append(str, "with Heimdal Kerberos");
551 g_string_append(str, "without Kerberos");
552 #endif /* HAVE_KERBEROS */
555 g_string_append(str, ", ");
557 g_string_append(str, "with GeoIP");
559 g_string_append(str, "without GeoIP");
560 #endif /* HAVE_GEOIP */
565 * Get runtime information for libraries used by libwireshark.
568 epan_get_runtime_version_info(GString *str
569 #if !defined(HAVE_LIBGNUTLS) && !defined(HAVE_LIBGCRYPT)
575 #ifdef HAVE_LIBGNUTLS
576 g_string_append_printf(str, ", with GnuTLS %s", gnutls_check_version(NULL));
577 #endif /* HAVE_LIBGNUTLS */
580 #ifdef HAVE_LIBGCRYPT
581 g_string_append_printf(str, ", with Gcrypt %s", gcry_check_version(NULL));
582 #endif /* HAVE_LIBGCRYPT */
586 * Editor modelines - http://www.wireshark.org/tools/modelines.html
591 * indent-tabs-mode: t
594 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
595 * :indentSize=8:tabSize=8:noTabs=false: