5 * Wireshark Protocol Analyzer Library
7 * Copyright (c) 2001 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 <Python.h> /* to get the Python version number (PY_VERSION) */
31 #include <wsutil/wsgcrypt.h>
32 #endif /* HAVE_LIBGCRYPT */
35 #include <gnutls/gnutls.h>
36 #endif /* HAVE_LIBGNUTLS */
42 #include "dfilter/dfilter.h"
43 #include "epan_dissect.h"
45 #include "conversation.h"
50 #include "column-utils.h"
52 #include "addr_resolv.h"
55 #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 /* initialize memory allocation subsystems */
104 /* initialize the GUID to name mapping table */
107 /* initialize name resolution (addr_resolv.c) */
111 #ifdef HAVE_LIBGCRYPT
112 /* initialize libgcrypt (beware, it won't be thread-safe) */
113 gcry_check_version(NULL);
114 gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
115 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
117 #ifdef HAVE_LIBGNUTLS
118 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 expert_packet_init();
131 wslua_init(cb, client_data);
146 #ifdef HAVE_LIBGNUTLS
147 gnutls_global_deinit();
150 addr_resolv_cleanup();
157 epan_t *session = g_slice_new(epan_t);
159 /* XXX, it should take session as param */
166 epan_get_user_comment(const epan_t *session, const frame_data *fd)
168 if (session->get_user_comment)
169 return session->get_user_comment(session->data, fd);
175 epan_get_interface_name(const epan_t *session, guint32 interface_id)
177 if (session->get_interface_name)
178 return session->get_interface_name(session->data, interface_id);
184 epan_get_frame_ts(const epan_t *session, guint32 frame_num)
186 const nstime_t *abs_ts = NULL;
188 if (session->get_frame_ts)
189 abs_ts = session->get_frame_ts(session->data, frame_num);
192 g_warning("!!! couldn't get frame ts for %u !!!\n", frame_num);
198 epan_free(epan_t *session)
201 /* XXX, it should take session as param */
202 cleanup_dissection();
204 g_slice_free(epan_t, session);
209 epan_conversation_init(void)
215 epan_conversation_cleanup(void)
217 conversation_cleanup();
221 epan_circuit_init(void)
227 epan_circuit_cleanup(void)
233 epan_dissect_init(epan_dissect_t *edt, epan_t *session, const gboolean create_proto_tree, const gboolean proto_tree_visible)
237 edt->session = session;
239 memset(&edt->pi, 0, sizeof(edt->pi));
240 if (pinfo_pool_cache != NULL) {
241 edt->pi.pool = pinfo_pool_cache;
242 pinfo_pool_cache = NULL;
245 edt->pi.pool = wmem_allocator_new(WMEM_ALLOCATOR_BLOCK);
248 if (create_proto_tree) {
249 edt->tree = proto_tree_create_root(&edt->pi);
250 proto_tree_set_visible(edt->tree, proto_tree_visible);
262 epan_dissect_reset(epan_dissect_t *edt)
264 /* We have to preserve the pool pointer across the memzeroing */
265 wmem_allocator_t *tmp;
269 g_slist_free(edt->pi.proto_data);
270 g_slist_free(edt->pi.dependent_frames);
272 /* Free the data sources list. */
273 free_data_sources(&edt->pi);
276 /* Free all tvb's chained from this tvb */
277 tvb_free_chain(edt->tvb);
282 proto_tree_reset(edt->tree);
287 memset(&edt->pi, 0, sizeof(edt->pi));
292 epan_dissect_new(epan_t *session, const gboolean create_proto_tree, const gboolean proto_tree_visible)
296 edt = g_new0(epan_dissect_t, 1);
298 return epan_dissect_init(edt, session, create_proto_tree, proto_tree_visible);
302 epan_dissect_fake_protocols(epan_dissect_t *edt, const gboolean fake_protocols)
305 proto_tree_set_fake_protocols(edt->tree, fake_protocols);
309 epan_dissect_run(epan_dissect_t *edt, struct wtap_pkthdr *phdr,
310 tvbuff_t *tvb, frame_data *fd, column_info *cinfo)
313 wslua_prime_dfilter(edt); /* done before entering wmem scope */
315 wmem_enter_packet_scope();
316 dissect_packet(edt, phdr, tvb, fd, cinfo);
318 /* free all memory allocated */
320 wmem_leave_packet_scope();
324 epan_dissect_run_with_taps(epan_dissect_t *edt, struct wtap_pkthdr *phdr,
325 tvbuff_t *tvb, frame_data *fd, column_info *cinfo)
327 wmem_enter_packet_scope();
329 dissect_packet(edt, phdr, tvb, fd, cinfo);
330 tap_push_tapped_queue(edt);
332 /* free all memory allocated */
334 wmem_leave_packet_scope();
338 epan_dissect_file_run(epan_dissect_t *edt, struct wtap_pkthdr *phdr,
339 tvbuff_t *tvb, frame_data *fd, column_info *cinfo)
342 wslua_prime_dfilter(edt); /* done before entering wmem scope */
344 wmem_enter_packet_scope();
345 dissect_file(edt, phdr, tvb, fd, cinfo);
347 /* free all memory allocated */
349 wmem_leave_packet_scope();
353 epan_dissect_file_run_with_taps(epan_dissect_t *edt, struct wtap_pkthdr *phdr,
354 tvbuff_t *tvb, frame_data *fd, column_info *cinfo)
356 wmem_enter_packet_scope();
358 dissect_file(edt, phdr, tvb, fd, cinfo);
359 tap_push_tapped_queue(edt);
361 /* free all memory allocated */
363 wmem_leave_packet_scope();
367 epan_dissect_cleanup(epan_dissect_t* edt)
371 g_slist_free(edt->pi.proto_data);
372 g_slist_free(edt->pi.dependent_frames);
374 /* Free the data sources list. */
375 free_data_sources(&edt->pi);
378 /* Free all tvb's chained from this tvb */
379 tvb_free_chain(edt->tvb);
383 proto_tree_free(edt->tree);
386 if (pinfo_pool_cache == NULL) {
387 wmem_free_all(edt->pi.pool);
388 pinfo_pool_cache = edt->pi.pool;
391 wmem_destroy_allocator(edt->pi.pool);
396 epan_dissect_free(epan_dissect_t* edt)
398 epan_dissect_cleanup(edt);
403 epan_dissect_prime_dfilter(epan_dissect_t *edt, const dfilter_t* dfcode)
405 dfilter_prime_proto_tree(dfcode, edt->tree);
408 /* ----------------------- */
410 epan_custom_set(epan_dissect_t *edt, int field_id,
413 gchar *expr, const int size )
415 return proto_custom_set(edt->tree, field_id, occurrence, result, expr, size);
419 epan_dissect_fill_in_columns(epan_dissect_t *edt, const gboolean fill_col_exprs, const gboolean fill_fd_colums)
421 col_custom_set_edt(edt, edt->pi.cinfo);
422 col_fill_in(&edt->pi, fill_col_exprs, fill_fd_colums);
426 epan_dissect_packet_contains_field(epan_dissect_t* edt,
427 const char *field_name)
431 gboolean contains_field;
433 if (!edt || !edt->tree)
435 field_id = proto_get_id_by_filter_name(field_name);
438 array = proto_find_finfo(edt->tree, field_id);
439 contains_field = (array->len > 0) ? TRUE : FALSE;
440 g_ptr_array_free(array, TRUE);
441 return contains_field;
445 * Get compile-time information for libraries used by libwireshark.
448 epan_get_compiled_version_info(GString *str)
451 g_string_append(str, ", ");
453 g_string_append(str, "with SMI " SMI_VERSION_STRING);
454 #else /* no SNMP library */
455 g_string_append(str, "without SMI");
459 g_string_append(str, ", ");
461 g_string_append(str, "with c-ares " ARES_VERSION_STR);
463 g_string_append(str, "without c-ares");
465 /* ADNS - only add if no c-ares */
466 g_string_append(str, ", ");
468 g_string_append(str, "with ADNS");
470 g_string_append(str, "without ADNS");
471 #endif /* HAVE_GNU_ADNS */
472 #endif /* HAVE_C_ARES */
475 g_string_append(str, ", ");
477 g_string_append(str, "with ");
478 g_string_append(str, LUA_VERSION);
480 g_string_append(str, "without Lua");
481 #endif /* HAVE_LUA */
483 g_string_append(str, ", ");
485 g_string_append(str, "with Python");
487 g_string_append(str, " " PY_VERSION);
488 #endif /* PY_VERSION */
490 g_string_append(str, "without Python");
491 #endif /* HAVE_PYTHON */
494 g_string_append(str, ", ");
495 #ifdef HAVE_LIBGNUTLS
496 g_string_append(str, "with GnuTLS " LIBGNUTLS_VERSION);
498 g_string_append(str, "without GnuTLS");
499 #endif /* HAVE_LIBGNUTLS */
502 g_string_append(str, ", ");
503 #ifdef HAVE_LIBGCRYPT
504 g_string_append(str, "with Gcrypt " GCRYPT_VERSION);
506 g_string_append(str, "without Gcrypt");
507 #endif /* HAVE_LIBGCRYPT */
510 /* XXX - I don't see how to get the version number, at least for KfW */
511 g_string_append(str, ", ");
513 #ifdef HAVE_MIT_KERBEROS
514 g_string_append(str, "with MIT Kerberos");
516 /* HAVE_HEIMDAL_KERBEROS */
517 g_string_append(str, "with Heimdal Kerberos");
520 g_string_append(str, "without Kerberos");
521 #endif /* HAVE_KERBEROS */
524 g_string_append(str, ", ");
526 g_string_append(str, "with GeoIP");
528 g_string_append(str, "without GeoIP");
529 #endif /* HAVE_GEOIP */
534 * Get runtime information for libraries used by libwireshark.
537 epan_get_runtime_version_info(GString *str
538 #if !defined(HAVE_LIBGNUTLS) && !defined(HAVE_LIBGCRYPT)
544 #ifdef HAVE_LIBGNUTLS
545 g_string_append_printf(str, ", GnuTLS %s", gnutls_check_version(NULL));
546 #endif /* HAVE_LIBGNUTLS */
549 #ifdef HAVE_LIBGCRYPT
550 g_string_append_printf(str, ", Gcrypt %s", gcry_check_version(NULL));
551 #endif /* HAVE_LIBGCRYPT */
555 * Editor modelines - http://www.wireshark.org/tools/modelines.html
560 * indent-tabs-mode: t
563 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
564 * :indentSize=8:tabSize=8:noTabs=false: