#if defined(HAVE_LIBSMI)
#include "epan/oids.h"
#endif
-#if defined(HAVE_GEOIP)
-#include "epan/geoip_db.h"
-#endif
+#include "epan/maxmind_db.h"
#include "epan/register.h"
#include <epan/epan_dissect.h>
#include <epan/tap.h>
#include "caputils/capture_ifinfo.h"
#ifdef _WIN32
#include "caputils/capture-wpcap.h"
-#include <wsutil/os_version_info.h>
#include <wsutil/unicode-utils.h>
#endif /* _WIN32 */
#include <capchild/capture_session.h>
*/
#define LONGOPT_COLOR (65536+1000)
#define LONGOPT_NO_DUPLICATE_KEYS (65536+1001)
+#ifdef HAVE_JSONGLIB
+#define LONGOPT_ELASTIC_MAPPING_FILTER (65536+1002)
+#endif
#if 0
#define tshark_debug(...) g_warning(__VA_ARGS__)
}
static void
-string_elem_print(gpointer data, gpointer not_used _U_)
+string_elem_print(gpointer data)
{
fprintf(stderr, " %s - %s\n",
((struct string_elem *)data)->sstr,
list = g_slist_insert_sorted(list, &captypes[i], string_compare);
}
}
- g_slist_foreach(list, string_elem_print, NULL);
- g_slist_free(list);
+ g_slist_free_full(list, string_elem_print);
g_free(captypes);
}
captypes[i].lstr = (open_routines[i].type == OPEN_INFO_MAGIC) ? magic : heuristic;
list = g_slist_insert_sorted(list, &captypes[i], string_compare);
}
- g_slist_foreach(list, string_elem_print, NULL);
- g_slist_free(list);
+ g_slist_free_full(list, string_elem_print);
g_free(captypes);
}
fprintf(output, " (Note that attributes are nonstandard)\n");
fprintf(output, " --no-duplicate-keys If -T json is specified, merge duplicate keys in an object\n");
fprintf(output, " into a single key with as value a json array containing all\n");
- fprintf(output, " values");
+ fprintf(output, " values\n");
+#ifdef HAVE_JSONGLIB
+ fprintf(output, " --elastic-mapping-filter <protocols> If -G elastic-mapping is specified, put only the\n");
+ fprintf(output, " specified protocols within the mapping file\n");
+#endif
fprintf(output, "\n");
fprintf(output, "Miscellaneous:\n");
fprintf(output, " -G column-formats dump column format codes and exit\n");
fprintf(output, " -G decodes dump \"layer type\"/\"decode as\" associations and exit\n");
fprintf(output, " -G dissector-tables dump dissector table names, types, and properties\n");
+#ifdef HAVE_JSONGLIB
+ fprintf(output, " -G elastic-mapping dump ElasticSearch mapping file\n");
+#endif
fprintf(output, " -G fieldcount dump count of header fields and exit\n");
fprintf(output, " -G fields dump fields glossary and exit\n");
fprintf(output, " -G ftypes dump field type basic and descriptive names\n");
g_strfreev(resultArray);
-#ifdef HAVE_GEOIP
- /* GeoIP */
- path = geoip_db_get_paths();
+ /* MaxMindDB */
+ path = maxmind_db_get_paths();
resultArray = g_strsplit(path, G_SEARCHPATH_SEPARATOR_S, 10);
for(i = 0; resultArray[i]; i++)
- printf("%-21s\t%s\n", "GeoIP path:", g_strstrip(resultArray[i]));
+ printf("%-21s\t%s\n", "MaxMind database path:", g_strstrip(resultArray[i]));
g_strfreev(resultArray);
g_free(path);
-#endif
#ifdef HAVE_LIBSMI
/* SMI MIBs/PIBs */
path = oid_get_default_mib_path();
- resultArray = g_strsplit(path, G_SEARCHPATH_SEPARATOR_S, 10);
+
+ resultArray = g_strsplit(path, G_SEARCHPATH_SEPARATOR_S, 20);
for(i = 0; resultArray[i]; i++)
printf("%-21s\t%s\n", "MIB/PIB path:", g_strstrip(resultArray[i]));
}
+static gboolean
+must_do_dissection(dfilter_t *rfcode, dfilter_t *dfcode,
+ gchar *volatile pdu_export_arg)
+{
+ /* We have to dissect each packet if:
+
+ we're printing information about each packet;
+
+ we're using a read filter on the packets;
+
+ we're using a display filter on the packets;
+
+ we're exporting PDUs;
+
+ we're using any taps that need dissection. */
+ return print_packet_info || rfcode || dfcode || pdu_export_arg ||
+ tap_listeners_require_dissection() || dissect_color;
+}
+
int
main(int argc, char *argv[])
{
{"export-objects", required_argument, NULL, LONGOPT_EXPORT_OBJECTS},
{"color", no_argument, NULL, LONGOPT_COLOR},
{"no-duplicate-keys", no_argument, NULL, LONGOPT_NO_DUPLICATE_KEYS},
+#ifdef HAVE_JSONGLIB
+ {"elastic-mapping-filter", required_argument, NULL, LONGOPT_ELASTIC_MAPPING_FILTER},
+#endif
{0, 0, 0, 0 }
};
gboolean arg_error = FALSE;
gchar *volatile pdu_export_arg = NULL;
const char *volatile exp_pdu_filename = NULL;
exp_pdu_t exp_pdu_tap_data;
+#ifdef HAVE_JSONGLIB
+ const gchar* elastic_mapping_filter = NULL;
+#endif
/*
* The leading + ensures that getopt_long() does not permute the argv[]
#ifdef _WIN32
arg_list_utf_16to8(argc, argv);
create_app_running_mutex();
-#if !GLIB_CHECK_VERSION(2,31,0)
- g_thread_init(NULL);
-#endif
#endif /* _WIN32 */
/*
* Attempt to get the pathname of the directory containing the
* executable file.
*/
- init_progfile_dir_error = init_progfile_dir(argv[0], main);
+ init_progfile_dir_error = init_progfile_dir(argv[0]);
if (init_progfile_dir_error != NULL) {
fprintf(stderr,
"tshark: Can't get pathname of directory containing the tshark program: %s.\n"
load_wpcap();
/* Warn the user if npf.sys isn't loaded. */
- if (!npf_sys_is_running() && get_windows_major_version() >= 6) {
+ if (!npf_sys_is_running()) {
fprintf(stderr, "The NPF driver isn't running. You may have trouble "
"capturing or\nlisting interfaces.\n");
}
case 'X':
ex_opt_add(optarg);
break;
+#ifdef HAVE_JSONGLIB
+ case LONGOPT_ELASTIC_MAPPING_FILTER:
+ elastic_mapping_filter = optarg;
+ break;
+#endif
default:
break;
}
hostlist_table_set_gui_info(init_hostlists);
srt_table_iterate_tables(register_srt_tables, NULL);
rtd_table_iterate_tables(register_rtd_tables, NULL);
- new_stat_tap_iterate_tables(register_simple_stat_tables, NULL);
+ stat_tap_iterate_tables(register_simple_stat_tables, NULL);
/* If invoked with the "-G" flag, we dump out information based on
the argument to the "-G" flag; if no argument is specified,
write_prefs(NULL);
else if (strcmp(argv[2], "dissector-tables") == 0)
dissector_dump_dissector_tables();
+#ifdef HAVE_JSONGLIB
+ else if (strcmp(argv[2], "elastic-mapping") == 0)
+ proto_registrar_dump_elastic(elastic_mapping_filter);
+#endif
else if (strcmp(argv[2], "fieldcount") == 0) {
/* return value for the test suite */
exit_status = proto_registrar_dump_fieldcount();
goto clean_exit;
} else if (strcmp(argv[2], "fields") == 0)
proto_registrar_dump_fields();
- else if (strcmp(argv[2], "folders") == 0)
+ else if (strcmp(argv[2], "folders") == 0) {
+ epan_load_settings();
about_folders();
- else if (strcmp(argv[2], "ftypes") == 0)
+ } else if (strcmp(argv[2], "ftypes") == 0)
proto_registrar_dump_ftypes();
else if (strcmp(argv[2], "heuristic-decodes") == 0)
dissector_dump_heur_decodes();
line that their preferences have changed. */
prefs_apply_all();
- /* At this point MATE will have registered its field array so we can
- have a tap filter with one of MATE's late-registered fields as part
- of the filter. We can now process all the "-z" arguments. */
- start_requested_stats();
-
/* We can also enable specified taps for export object */
start_exportobjects();
}
}
- /* We have to dissect each packet if:
-
- we're printing information about each packet;
-
- we're using a read filter on the packets;
-
- we're using a display filter on the packets;
-
- we're exporting PDUs;
-
- we're using any taps that need dissection. */
- do_dissection = print_packet_info || rfcode || dfcode || pdu_export_arg ||
- tap_listeners_require_dissection() || dissect_color;
tshark_debug("tshark: do_dissection = %s", do_dissection ? "TRUE" : "FALSE");
if (cf_name) {
goto clean_exit;
}
+ /* Start statistics taps; we do so after successfully opening the
+ capture file, so we know we have something to compute stats
+ on, and after registering all dissectors, so that MATE will
+ have registered its field array so we can have a tap filter
+ with one of MATE's late-registered fields as part of the
+ filter. */
+ start_requested_stats();
+
+ /* Do we need to do dissection of packets? That depends on, among
+ other things, what taps are listening, so determine that after
+ starting the statistics taps. */
+ do_dissection = must_do_dissection(rfcode, dfcode, pdu_export_arg);
+
/* Process the packets in the file */
tshark_debug("tshark: invoking process_cap_file() to process the packets");
TRY {
}
tshark_debug("tshark: performing live capture");
+
+ /* Start statistics taps; we should only do so after the capture
+ started successfully, so we know we have something to compute
+ stats, but we currently don't check for that - see below.
+
+ We do so after registering all dissectors, so that MATE will
+ have registered its field array so we can have a tap filter
+ with one of MATE's late-registered fields as part of the
+ filter. */
+ start_requested_stats();
+
+ /* Do we need to do dissection of packets? That depends on, among
+ other things, what taps are listening, so determine that after
+ starting the statistics taps. */
+ do_dissection = must_do_dissection(rfcode, dfcode, pdu_export_arg);
+
/*
* XXX - this returns FALSE if an error occurred, but it also
* returns FALSE if the capture stops because a time limit
}
draw_tap_listeners(TRUE);
+ /* Memory cleanup */
+ reset_tap_listeners();
funnel_dump_all_text_windows();
epan_free(cfile.epan);
epan_cleanup();
wtap_cleanup();
free_progdirs();
cf_close(&cfile);
+ dfilter_free(dfcode);
return exit_status;
}
pipe_input.input_cb = input_cb;
#ifdef _WIN32
-#if GLIB_CHECK_VERSION(2,31,0)
pipe_input.callback_running = g_malloc(sizeof(GMutex));
g_mutex_init(pipe_input.callback_running);
-#else
- pipe_input.callback_running = g_mutex_new();
-#endif
/* Tricky to use pipes in win9x, as no concept of wait. NT can
do this but that doesn't cover all win32 platforms. GTK can do
this but doesn't seem to work over processes. Attempt to do
if (!ret)
return FALSE;
+ /*
+ * Force synchronous resolution of IP addresses; we're doing only
+ * one pass, so we can't do it in the background and fix up past
+ * dissections.
+ */
+ set_resolution_synchrony(TRUE);
+
/* the actual capture loop
*
* XXX - glib doesn't seem to provide any event based loop handling.
from the dissection or running taps on the packet; if we're doing
any of that, we'll do it in the second pass.) */
if (edt) {
- if (gbl_resolv_flags.mac_name || gbl_resolv_flags.network_name ||
- gbl_resolv_flags.transport_name)
- /* Grab any resolved addresses */
- host_name_lookup_process();
-
/* If we're running a read filter, prime the epan_dissect_t with that
filter. */
if (cf->rfcode)
passes over the packets; that's the pass where we print
packet information or run taps.) */
if (edt) {
- if (gbl_resolv_flags.mac_name || gbl_resolv_flags.network_name ||
- gbl_resolv_flags.transport_name)
- /* Grab any resolved addresses */
- host_name_lookup_process();
-
/* If we're running a display filter, prime the epan_dissect_t with that
filter. */
if (cf->dfcode)
edt = epan_dissect_new(cf->epan, create_proto_tree, print_packet_info && print_details);
}
+ /*
+ * Force synchronous resolution of IP addresses; in this pass, we
+ * can't do it in the background and fix up past dissections.
+ */
+ set_resolution_synchrony(TRUE);
+
for (framenum = 1; err == 0 && framenum <= cf->count; framenum++) {
fdata = frame_data_sequence_find(cf->provider.frames, framenum);
if (wtap_seek_read(cf->provider.wth, fdata->file_off, &rec, &buf, &err,
edt = epan_dissect_new(cf->epan, create_proto_tree, print_packet_info && print_details);
}
+ /*
+ * Force synchronous resolution of IP addresses; we're doing only
+ * one pass, so we can't do it in the background and fix up past
+ * dissections.
+ */
+ set_resolution_synchrony(TRUE);
+
while (wtap_read(cf->provider.wth, &err, &err_info, &data_offset)) {
framenum++;
over the packets, so, if we'll be printing packet information
or running taps, we'll be doing it here.) */
if (edt) {
- if (print_packet_info && (gbl_resolv_flags.mac_name || gbl_resolv_flags.network_name ||
- gbl_resolv_flags.transport_name))
- /* Grab any resolved addresses */
- host_name_lookup_process();
-
/* If we're running a filter, prime the epan_dissect_t with that
filter. */
if (cf->dfcode)