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 */
41 #include "epan_dissect.h"
42 #include "wsutil/report_err.h"
44 #include "conversation.h"
49 #include "column-utils.h"
51 #include "addr_resolv.h"
54 #include "wmem/wmem.h"
59 #include <wslua/wslua.h>
67 #include <ares_version.h>
71 epan_get_version(void) {
76 epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_data),
77 void (*register_all_handoffs_func)(register_cb cb, gpointer client_data),
80 void (*report_failure_fcn_p)(const char *, va_list),
81 void (*report_open_failure_fcn_p)(const char *, int, gboolean),
82 void (*report_read_failure_fcn_p)(const char *, int),
83 void (*report_write_failure_fcn_p)(const char *, int))
85 init_report_err(report_failure_fcn_p, report_open_failure_fcn_p,
86 report_read_failure_fcn_p, report_write_failure_fcn_p);
88 /* initialize memory allocation subsystems */
92 /* initialize the GUID to name mapping table */
95 /* initialize name resolution (addr_resolv.c) */
100 /* initialize libgcrypt (beware, it won't be thread-safe) */
101 gcry_check_version(NULL);
102 gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
103 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
105 #ifdef HAVE_LIBGNUTLS
106 gnutls_global_init();
111 proto_init(register_all_protocols_func, register_all_handoffs_func,
115 final_registration_all_protocols();
116 expert_packet_init();
118 wslua_init(cb, client_data);
125 cleanup_dissection();
131 oid_resolv_cleanup();
132 #ifdef HAVE_LIBGNUTLS
133 gnutls_global_deinit();
136 addr_resolv_cleanup();
143 epan_t *session = g_slice_new(epan_t);
145 /* XXX, it should take session as param */
152 epan_get_user_comment(const epan_t *session, const frame_data *fd)
154 if (session->get_user_comment)
155 return session->get_user_comment(session->data, fd);
161 epan_get_interface_name(const epan_t *session, guint32 interface_id)
163 if (session->get_interface_name)
164 return session->get_interface_name(session->data, interface_id);
170 epan_get_frame_ts(const epan_t *session, guint32 frame_num)
172 const nstime_t *abs_ts = NULL;
174 if (session->get_frame_ts)
175 abs_ts = session->get_frame_ts(session->data, frame_num);
178 g_warning("!!! couldn't get frame ts for %u !!!\n", frame_num);
184 epan_free(epan_t *session)
186 /* XXX, it should take session as param */
187 cleanup_dissection();
189 g_slice_free(epan_t, session);
193 epan_conversation_init(void)
199 epan_conversation_cleanup(void)
201 conversation_cleanup();
205 epan_circuit_init(void)
211 epan_circuit_cleanup(void)
217 epan_dissect_init(epan_dissect_t *edt, epan_t *session, const gboolean create_proto_tree, const gboolean proto_tree_visible)
221 edt->session = session;
222 edt->pi.pool = wmem_allocator_new(WMEM_ALLOCATOR_SIMPLE);
224 if (create_proto_tree) {
225 edt->tree = proto_tree_create_root(&edt->pi);
226 proto_tree_set_visible(edt->tree, proto_tree_visible);
232 edt->pi.dependent_frames = NULL;
238 epan_dissect_new(epan_t *session, const gboolean create_proto_tree, const gboolean proto_tree_visible)
242 edt = g_new0(epan_dissect_t, 1);
244 return epan_dissect_init(edt, session, create_proto_tree, proto_tree_visible);
248 epan_dissect_fake_protocols(epan_dissect_t *edt, const gboolean fake_protocols)
251 proto_tree_set_fake_protocols(edt->tree, fake_protocols);
255 epan_dissect_run(epan_dissect_t *edt, struct wtap_pkthdr *phdr,
256 tvbuff_t *tvb, frame_data *fd, column_info *cinfo)
259 wslua_prime_dfilter(edt); /* done before entering wmem scope */
261 wmem_enter_packet_scope();
262 dissect_packet(edt, phdr, tvb, fd, cinfo);
264 /* free all memory allocated */
266 wmem_leave_packet_scope();
270 epan_dissect_run_with_taps(epan_dissect_t *edt, struct wtap_pkthdr *phdr,
271 tvbuff_t *tvb, frame_data *fd, column_info *cinfo)
273 wmem_enter_packet_scope();
275 dissect_packet(edt, phdr, tvb, fd, cinfo);
276 tap_push_tapped_queue(edt);
278 /* free all memory allocated */
280 wmem_leave_packet_scope();
284 epan_dissect_cleanup(epan_dissect_t* edt)
288 g_slist_free(edt->pi.dependent_frames);
290 /* Free the data sources list. */
291 free_data_sources(&edt->pi);
293 /* Free all tvb's chained from this tvb */
294 tvb_free_chain(edt->tvb);
297 proto_tree_free(edt->tree);
300 wmem_destroy_allocator(edt->pi.pool);
304 epan_dissect_free(epan_dissect_t* edt)
306 epan_dissect_cleanup(edt);
311 epan_dissect_prime_dfilter(epan_dissect_t *edt, const dfilter_t* dfcode)
313 dfilter_prime_proto_tree(dfcode, edt->tree);
316 /* ----------------------- */
318 epan_custom_set(epan_dissect_t *edt, int field_id,
321 gchar *expr, const int size )
323 return proto_custom_set(edt->tree, field_id, occurrence, result, expr, size);
327 epan_dissect_fill_in_columns(epan_dissect_t *edt, const gboolean fill_col_exprs, const gboolean fill_fd_colums)
329 col_custom_set_edt(edt, edt->pi.cinfo);
330 col_fill_in(&edt->pi, fill_col_exprs, fill_fd_colums);
334 epan_dissect_packet_contains_field(epan_dissect_t* edt,
335 const char *field_name)
339 gboolean contains_field;
341 if (!edt || !edt->tree)
343 field_id = proto_get_id_by_filter_name(field_name);
346 array = proto_find_finfo(edt->tree, field_id);
347 contains_field = (array->len > 0) ? TRUE : FALSE;
348 g_ptr_array_free(array, TRUE);
349 return contains_field;
353 * Get compile-time information for libraries used by libwireshark.
356 epan_get_compiled_version_info(GString *str)
359 g_string_append(str, ", ");
361 g_string_append(str, "with SMI " SMI_VERSION_STRING);
362 #else /* no SNMP library */
363 g_string_append(str, "without SMI");
367 g_string_append(str, ", ");
369 g_string_append(str, "with c-ares " ARES_VERSION_STR);
371 g_string_append(str, "without c-ares");
373 /* ADNS - only add if no c-ares */
374 g_string_append(str, ", ");
376 g_string_append(str, "with ADNS");
378 g_string_append(str, "without ADNS");
379 #endif /* HAVE_GNU_ADNS */
380 #endif /* HAVE_C_ARES */
383 g_string_append(str, ", ");
385 g_string_append(str, "with ");
386 g_string_append(str, LUA_VERSION);
388 g_string_append(str, "without Lua");
389 #endif /* HAVE_LUA */
391 g_string_append(str, ", ");
393 g_string_append(str, "with Python");
395 g_string_append(str, " " PY_VERSION);
396 #endif /* PY_VERSION */
398 g_string_append(str, "without Python");
399 #endif /* HAVE_PYTHON */
402 g_string_append(str, ", ");
403 #ifdef HAVE_LIBGNUTLS
404 g_string_append(str, "with GnuTLS " LIBGNUTLS_VERSION);
406 g_string_append(str, "without GnuTLS");
407 #endif /* HAVE_LIBGNUTLS */
410 g_string_append(str, ", ");
411 #ifdef HAVE_LIBGCRYPT
412 g_string_append(str, "with Gcrypt " GCRYPT_VERSION);
414 g_string_append(str, "without Gcrypt");
415 #endif /* HAVE_LIBGCRYPT */
418 /* XXX - I don't see how to get the version number, at least for KfW */
419 g_string_append(str, ", ");
421 #ifdef HAVE_MIT_KERBEROS
422 g_string_append(str, "with MIT Kerberos");
424 /* HAVE_HEIMDAL_KERBEROS */
425 g_string_append(str, "with Heimdal Kerberos");
428 g_string_append(str, "without Kerberos");
429 #endif /* HAVE_KERBEROS */
432 g_string_append(str, ", ");
434 g_string_append(str, "with GeoIP");
436 g_string_append(str, "without GeoIP");
437 #endif /* HAVE_GEOIP */
442 * Get runtime information for libraries used by libwireshark.
445 epan_get_runtime_version_info(GString *str
446 #if !defined(HAVE_LIBGNUTLS) && !defined(HAVE_LIBGCRYPT)
452 #ifdef HAVE_LIBGNUTLS
453 g_string_append_printf(str, ", GnuTLS %s", gnutls_check_version(NULL));
454 #endif /* HAVE_LIBGNUTLS */
457 #ifdef HAVE_LIBGCRYPT
458 g_string_append_printf(str, ", Gcrypt %s", gcry_check_version(NULL));
459 #endif /* HAVE_LIBGCRYPT */
463 * Editor modelines - http://www.wireshark.org/tools/modelines.html
468 * indent-tabs-mode: t
471 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
472 * :indentSize=8:tabSize=8:noTabs=false: