int main(int argc, char **argv) { char *init_progfile_dir_error; char *text; char *gpf_path, *pf_path; int gpf_open_errno, gpf_read_errno; int pf_open_errno, pf_read_errno; dfilter_t *df; /* * Get credential information for later use. */ init_process_policies(); /* * Attempt to get the pathname of the executable file. */ init_progfile_dir_error = init_progfile_dir(argv[0], main); if (init_progfile_dir_error != NULL) { fprintf(stderr, "dftest: Can't get pathname of dftest program: %s.\n", init_progfile_dir_error); } timestamp_set_type(TS_RELATIVE); timestamp_set_seconds_type(TS_SECONDS_DEFAULT); /* Register all dissectors; we must do this before checking for the "-g" flag, as the "-g" flag dumps a list of fields registered by the dissectors, and we must do it before we read the preferences, in case any dissectors register preferences. */ epan_init(register_all_protocols, register_all_protocol_handoffs, NULL, NULL, failure_message, open_failure_message, read_failure_message, write_failure_message); /* now register the preferences for any non-dissector modules. we must do that before we read the preferences as well. */ prefs_register_modules(); /* set the c-language locale to the native environment. */ setlocale(LC_ALL, ""); read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path, &pf_open_errno, &pf_read_errno, &pf_path); if (gpf_path != NULL) { if (gpf_open_errno != 0) { fprintf(stderr, "can't open global preferences file \"%s\": %s.\n", pf_path, g_strerror(gpf_open_errno)); } if (gpf_read_errno != 0) { fprintf(stderr, "I/O error reading global preferences file \"%s\": %s.\n", pf_path, g_strerror(gpf_read_errno)); } } if (pf_path != NULL) { if (pf_open_errno != 0) { fprintf(stderr, "can't open your preferences file \"%s\": %s.\n", pf_path, g_strerror(pf_open_errno)); } if (pf_read_errno != 0) { fprintf(stderr, "I/O error reading your preferences file \"%s\": %s.\n", pf_path, g_strerror(pf_read_errno)); } } /* notify all registered modules that have had any of their preferences changed either from one of the preferences file or from the command line that its preferences have changed. */ prefs_apply_all(); /* Check for filter on command line */ if (argc <= 1) { fprintf(stderr, "Usage: dftest <filter>\n"); exit(1); } /* Get filter text */ text = get_args_as_string(argc, argv, 1); printf("Filter: \"%s\"\n", text); /* Compile it */ if (!dfilter_compile(text, &df)) { fprintf(stderr, "dftest: %s\n", dfilter_error_msg); epan_cleanup(); exit(2); } printf("dfilter ptr = 0x%08x\n", GPOINTER_TO_INT(df)); printf("\n\n"); if (df == NULL) printf("Filter is empty\n"); else dfilter_dump(df); dfilter_free(df); epan_cleanup(); exit(0); }
int main(int argc, char **argv) { char *init_progfile_dir_error; char *text; dfilter_t *df; gchar *err_msg; /* * Get credential information for later use. */ init_process_policies(); /* * Attempt to get the pathname of the directory containing the * executable file. */ init_progfile_dir_error = init_progfile_dir(argv[0], main); if (init_progfile_dir_error != NULL) { fprintf(stderr, "dftest: Can't get pathname of directory containing the dftest program: %s.\n", init_progfile_dir_error); g_free(init_progfile_dir_error); } init_report_message(failure_warning_message, failure_warning_message, open_failure_message, read_failure_message, write_failure_message); timestamp_set_type(TS_RELATIVE); timestamp_set_seconds_type(TS_SECONDS_DEFAULT); #ifdef HAVE_PLUGINS /* Register all the plugin types we have. */ epan_register_plugin_types(); /* Types known to libwireshark */ /* Scan for plugins. This does *not* call their registration routines; that's done later. */ scan_plugins(REPORT_LOAD_FAILURE); #endif wtap_init(); /* Register all dissectors; we must do this before checking for the "-g" flag, as the "-g" flag dumps a list of fields registered by the dissectors, and we must do it before we read the preferences, in case any dissectors register preferences. */ if (!epan_init(register_all_protocols, register_all_protocol_handoffs, NULL, NULL)) return 2; /* set the c-language locale to the native environment. */ setlocale(LC_ALL, ""); /* Load libwireshark settings from the current profile. */ epan_load_settings(); /* notify all registered modules that have had any of their preferences changed either from one of the preferences file or from the command line that its preferences have changed. */ prefs_apply_all(); /* Check for filter on command line */ if (argc <= 1) { fprintf(stderr, "Usage: dftest <filter>\n"); exit(1); } /* Get filter text */ text = get_args_as_string(argc, argv, 1); printf("Filter: \"%s\"\n", text); /* Compile it */ if (!dfilter_compile(text, &df, &err_msg)) { fprintf(stderr, "dftest: %s\n", err_msg); g_free(err_msg); epan_cleanup(); exit(2); } printf("\n"); if (df == NULL) printf("Filter is empty\n"); else dfilter_dump(df); dfilter_free(df); epan_cleanup(); exit(0); }
int main(int argc, char *argv[]) { GString *comp_info_str; GString *runtime_info_str; wtap *wth; int err; gchar *err_info; int i; int opt; int overall_error_status; static const struct option long_options[] = { {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'v'}, {0, 0, 0, 0 } }; #ifdef HAVE_PLUGINS char *init_progfile_dir_error; #endif /* Set the C-language locale to the native environment. */ setlocale(LC_ALL, ""); /* Get the compile-time version information string */ comp_info_str = get_compiled_version_info(NULL, NULL); /* Get the run-time version information string */ runtime_info_str = get_runtime_version_info(NULL); /* Add it to the information to be reported on a crash. */ ws_add_crash_info("Captype (Wireshark) %s\n" "\n" "%s" "\n" "%s", get_ws_vcs_version_info(), comp_info_str->str, runtime_info_str->str); g_string_free(comp_info_str, TRUE); g_string_free(runtime_info_str, TRUE); #ifdef _WIN32 arg_list_utf_16to8(argc, argv); create_app_running_mutex(); #endif /* _WIN32 */ /* * Get credential information for later use. */ init_process_policies(); init_open_routines(); #ifdef HAVE_PLUGINS if ((init_progfile_dir_error = init_progfile_dir(argv[0], main))) { g_warning("captype: init_progfile_dir(): %s", init_progfile_dir_error); g_free(init_progfile_dir_error); } else { /* Register all the plugin types we have. */ wtap_register_plugin_types(); /* Types known to libwiretap */ init_report_err(failure_message,NULL,NULL,NULL); /* Scan for plugins. This does *not* call their registration routines; that's done later. Don't report failures to load plugins because most (non-wiretap) plugins *should* fail to load (because we're not linked against libwireshark and dissector plugins need libwireshark). */ scan_plugins(DONT_REPORT_LOAD_FAILURE); /* Register all libwiretap plugin modules. */ register_all_wiretap_modules(); } #endif /* Process the options */ while ((opt = getopt_long(argc, argv, "hv", long_options, NULL)) !=-1) { switch (opt) { case 'h': printf("Captype (Wireshark) %s\n" "Print the file types of capture files.\n" "See https://www.wireshark.org for more information.\n", get_ws_vcs_version_info()); print_usage(stdout); exit(0); break; case 'v': comp_info_str = get_compiled_version_info(NULL, NULL); runtime_info_str = get_runtime_version_info(NULL); show_version("Captype (Wireshark)", comp_info_str, runtime_info_str); g_string_free(comp_info_str, TRUE); g_string_free(runtime_info_str, TRUE); exit(0); break; case '?': /* Bad flag - print usage message */ print_usage(stderr); exit(1); break; } } if (argc < 2) { print_usage(stderr); return 1; } overall_error_status = 0; for (i = 1; i < argc; i++) { wth = wtap_open_offline(argv[i], WTAP_TYPE_AUTO, &err, &err_info, FALSE); if(wth) { printf("%s: %s\n", argv[i], wtap_file_type_subtype_short_string(wtap_file_type_subtype(wth))); wtap_close(wth); } else { if (err == WTAP_ERR_FILE_UNKNOWN_FORMAT) printf("%s: unknown\n", argv[i]); else { fprintf(stderr, "captype: Can't open %s: %s\n", argv[i], wtap_strerror(err)); if (err_info != NULL) { fprintf(stderr, "(%s)\n", err_info); g_free(err_info); } overall_error_status = 1; /* remember that an error has occurred */ } } } return overall_error_status; }
int main(int argc, char *argv[]) { char* err_msg; int result; int option_idx = 0; ssh_params_t* ssh_params = ssh_params_new(); char* remote_interface = NULL; char* remote_filter = NULL; guint32 count = 0; int ret = EXIT_FAILURE; extcap_parameters * extcap_conf = g_new0(extcap_parameters, 1); char* help_url; char* help_header = NULL; /* * Get credential information for later use. */ init_process_policies(); /* * Attempt to get the pathname of the directory containing the * executable file. */ err_msg = init_progfile_dir(argv[0]); if (err_msg != NULL) { g_warning("Can't get pathname of directory containing the captype program: %s.", err_msg); g_free(err_msg); } help_url = data_file_url("ciscodump.html"); extcap_base_set_util_info(extcap_conf, argv[0], CISCODUMP_VERSION_MAJOR, CISCODUMP_VERSION_MINOR, CISCODUMP_VERSION_RELEASE, help_url); g_free(help_url); extcap_base_register_interface(extcap_conf, CISCODUMP_EXTCAP_INTERFACE, "Cisco remote capture", 147, "Remote capture dependent DLT"); help_header = g_strdup_printf( " %s --extcap-interfaces\n" " %s --extcap-interface=%s --extcap-dlts\n" " %s --extcap-interface=%s --extcap-config\n" " %s --extcap-interface=%s --remote-host myhost --remote-port 22222 " "--remote-username myuser --remote-interface gigabit0/0 " "--fifo=FILENAME --capture\n", argv[0], argv[0], CISCODUMP_EXTCAP_INTERFACE, argv[0], CISCODUMP_EXTCAP_INTERFACE, argv[0], CISCODUMP_EXTCAP_INTERFACE); extcap_help_add_header(extcap_conf, help_header); g_free(help_header); extcap_help_add_option(extcap_conf, "--help", "print this help"); extcap_help_add_option(extcap_conf, "--version", "print the version"); extcap_help_add_option(extcap_conf, "--remote-host <host>", "the remote SSH host"); extcap_help_add_option(extcap_conf, "--remote-port <port>", "the remote SSH port (default: 22)"); extcap_help_add_option(extcap_conf, "--remote-username <username>", "the remote SSH username (default: the current user)"); extcap_help_add_option(extcap_conf, "--remote-password <password>", "the remote SSH password. " "If not specified, ssh-agent and ssh-key are used"); extcap_help_add_option(extcap_conf, "--sshkey <public key path>", "the path of the ssh key"); extcap_help_add_option(extcap_conf, "--sshkey-passphrase <public key passphrase>", "the passphrase to unlock public ssh"); extcap_help_add_option(extcap_conf, "--proxycommand <proxy command>", "the command to use as proxy the the ssh connection"); extcap_help_add_option(extcap_conf, "--remote-interface <iface>", "the remote capture interface"); extcap_help_add_option(extcap_conf, "--remote-filter <filter>", "a filter for remote capture " "(default: don't capture data for lal interfaces IPs)"); opterr = 0; optind = 0; if (argc == 1) { extcap_help_print(extcap_conf); goto end; } while ((result = getopt_long(argc, argv, ":", longopts, &option_idx)) != -1) { switch (result) { case OPT_HELP: extcap_help_print(extcap_conf); ret = EXIT_SUCCESS; goto end; case OPT_VERSION: printf("%s\n", extcap_conf->version); goto end; case OPT_REMOTE_HOST: g_free(ssh_params->host); ssh_params->host = g_strdup(optarg); break; case OPT_REMOTE_PORT: if (!ws_strtou16(optarg, NULL, &ssh_params->port) || ssh_params->port == 0) { g_warning("Invalid port: %s", optarg); goto end; } break; case OPT_REMOTE_USERNAME: g_free(ssh_params->username); ssh_params->username = g_strdup(optarg); break; case OPT_REMOTE_PASSWORD: g_free(ssh_params->password); ssh_params->password = g_strdup(optarg); memset(optarg, 'X', strlen(optarg)); break; case OPT_SSHKEY: g_free(ssh_params->sshkey_path); ssh_params->sshkey_path = g_strdup(optarg); break; case OPT_SSHKEY_PASSPHRASE: g_free(ssh_params->sshkey_passphrase); ssh_params->sshkey_passphrase = g_strdup(optarg); memset(optarg, 'X', strlen(optarg)); break; case OPT_PROXYCOMMAND: g_free(ssh_params->proxycommand); ssh_params->proxycommand = g_strdup(optarg); break; case OPT_REMOTE_INTERFACE: g_free(remote_interface); remote_interface = g_strdup(optarg); break; case OPT_REMOTE_FILTER: g_free(remote_filter); remote_filter = g_strdup(optarg); break; case OPT_REMOTE_COUNT: if (!ws_strtou32(optarg, NULL, &count)) { g_warning("Invalid packet count: %s", optarg); goto end; } break; case ':': /* missing option argument */ g_warning("Option '%s' requires an argument", argv[optind - 1]); break; default: if (!extcap_base_parse_options(extcap_conf, result - EXTCAP_OPT_LIST_INTERFACES, optarg)) { g_warning("Invalid option: %s", argv[optind - 1]); goto end; } } } extcap_cmdline_debug(argv, argc); if (optind != argc) { g_warning("Unexpected extra option: %s", argv[optind]); goto end; } if (extcap_base_handle_interface(extcap_conf)) { ret = EXIT_SUCCESS; goto end; } if (extcap_conf->show_config) { ret = list_config(extcap_conf->interface, ssh_params->port); goto end; } err_msg = ws_init_sockets(); if (err_msg != NULL) { g_warning("ERROR: %s", err_msg); g_free(err_msg); g_warning("%s", please_report_bug()); goto end; } if (extcap_conf->capture) { if (!ssh_params->host) { g_warning("Missing parameter: --remote-host"); goto end; } if (!remote_interface) { g_warning("ERROR: No interface specified (--remote-interface)"); goto end; } if (count == 0) { g_warning("ERROR: count of packets must be specified (--remote-count)"); goto end; } ssh_params->debug = extcap_conf->debug; ret = ssh_open_remote_connection(ssh_params, remote_interface, remote_filter, count, extcap_conf->fifo); } else { g_debug("You should not come here... maybe some parameter missing?"); ret = EXIT_FAILURE; } end: ssh_params_free(ssh_params); g_free(remote_interface); g_free(remote_filter); extcap_base_cleanup(&extcap_conf); return ret; }
/* And now our feature presentation... [ fade to music ] */ int main(int argc, char *argv[]) { WiresharkApplication a(argc, argv); MainWindow *w; char *init_progfile_dir_error; char *s; int opt; gboolean arg_error = FALSE; extern int info_update_freq; /* Found in about_dlg.c. */ const gchar *filter; #ifdef _WIN32 WSADATA wsaData; #endif /* _WIN32 */ char *rf_path; int rf_open_errno; char *gdp_path, *dp_path; int err; #ifdef HAVE_LIBPCAP gboolean start_capture = FALSE; gboolean list_link_layer_types = FALSE; GList *if_list; gchar *err_str; #else gboolean capture_option_specified = FALSE; #ifdef _WIN32 #ifdef HAVE_AIRPCAP gchar *err_str; #endif #endif #endif gint pl_size = 280, tv_size = 95, bv_size = 75; gchar *rc_file, *cf_name = NULL, *rfilter = NULL, *jfilter = NULL; dfilter_t *rfcode = NULL; gboolean rfilter_parse_failed = FALSE; e_prefs *prefs_p; char badopt; //GtkWidget *splash_win = NULL; GLogLevelFlags log_flags; guint go_to_packet = 0; gboolean jump_backwards = FALSE; dfilter_t *jump_to_filter = NULL; int optind_initial; int status; //initialize language ! QString locale = QLocale::system().name(); g_log(NULL, G_LOG_LEVEL_DEBUG, "Translator %s", locale.toStdString().c_str()); QTranslator translator; translator.load(QString(":/i18n/qtshark_") + locale); a.installTranslator(&translator); // Hopefully we won't have to use QString::fromUtf8() in as many places. QTextCodec *utf8codec = QTextCodec::codecForName("UTF-8"); QTextCodec::setCodecForCStrings(utf8codec); QTextCodec::setCodecForTr(utf8codec); #ifdef HAVE_LIBPCAP #if defined(_WIN32) || defined(HAVE_PCAP_CREATE) #define OPTSTRING_B "B:" #else #define OPTSTRING_B "" #endif /* _WIN32 or HAVE_PCAP_CREATE */ #else /* HAVE_LIBPCAP */ #define OPTSTRING_B "" #endif /* HAVE_LIBPCAP */ #ifdef HAVE_PCAP_CREATE #define OPTSTRING_I "I" #else #define OPTSTRING_I "" #endif #define OPTSTRING "a:b:" OPTSTRING_B "c:C:Df:g:Hhi:" OPTSTRING_I "jJ:kK:lLm:nN:o:P:pQr:R:Ss:t:u:vw:X:y:z:" static const char optstring[] = OPTSTRING; /* * Get credential information for later use, and drop privileges * before doing anything else. * Let the user know if anything happened. */ init_process_policies(); relinquish_special_privs_perm(); /* * Attempt to get the pathname of the executable file. */ init_progfile_dir_error = init_progfile_dir(argv[0], main); g_log(NULL, G_LOG_LEVEL_DEBUG, "progfile_dir: %s", get_progfile_dir()); /* initialize the funnel mini-api */ // xxx qtshark //initialize_funnel_ops(); AirPDcapInitContext(&airpdcap_ctx); // xxx qtshark #ifdef _WIN32 /* Load wpcap if possible. Do this before collecting the run-time version information */ load_wpcap(); /* ... and also load the packet.dll from wpcap */ wpcap_packet_load(); #ifdef HAVE_AIRPCAP /* Load the airpcap.dll. This must also be done before collecting * run-time version information. */ airpcap_dll_ret_val = load_airpcap(); switch (airpcap_dll_ret_val) { case AIRPCAP_DLL_OK: /* load the airpcap interfaces */ airpcap_if_list = get_airpcap_interface_list(&err, &err_str); if (airpcap_if_list == NULL || g_list_length(airpcap_if_list) == 0){ if (err == CANT_GET_AIRPCAP_INTERFACE_LIST && err_str != NULL) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", "Failed to open Airpcap Adapters!"); g_free(err_str); } airpcap_if_active = NULL; } else { /* select the first ad default (THIS SHOULD BE CHANGED) */ airpcap_if_active = airpcap_get_default_if(airpcap_if_list); } break; #if 0 /* * XXX - Maybe we need to warn the user if one of the following happens??? */ case AIRPCAP_DLL_OLD: simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s","AIRPCAP_DLL_OLD\n"); break; case AIRPCAP_DLL_ERROR: simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s","AIRPCAP_DLL_ERROR\n"); break; case AIRPCAP_DLL_NOT_FOUND: simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s","AIRPCAP_DDL_NOT_FOUND\n"); break; #endif } #endif /* HAVE_AIRPCAP */ /* Start windows sockets */ WSAStartup( MAKEWORD( 1, 1 ), &wsaData ); #endif /* _WIN32 */ profile_store_persconffiles (TRUE); /* Assemble the compile-time version information string */ comp_info_str = g_string_new("Compiled "); // xxx qtshark get_compiled_version_info(comp_info_str, get_qt_compiled_info, get_gui_compiled_info); /* Assemble the run-time version information string */ runtime_info_str = g_string_new("Running "); // xxx qtshark get_runtime_version_info(runtime_info_str, get_gui_runtime_info); /* Read the profile independent recent file. We have to do this here so we can */ /* set the profile before it can be set from the command line parameterts */ // xxx qtshark //recent_read_static(&rf_path, &rf_open_errno); //if (rf_path != NULL && rf_open_errno != 0) { // simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK, // "Could not open common recent file\n\"%s\": %s.", // rf_path, strerror(rf_open_errno)); //} /* "pre-scan" the command line parameters, if we have "console only" parameters. We do this so we don't start GTK+ if we're only showing command-line help or version information. XXX - this pre-scan is done before we start GTK+, so we haven't run gtk_init() on the arguments. That means that GTK+ arguments have not been removed from the argument list; those arguments begin with "--", and will be treated as an error by getopt(). We thus ignore errors - *and* set "opterr" to 0 to suppress the error messages. */ opterr = 0; optind_initial = optind; while ((opt = getopt(argc, argv, optstring)) != -1) { switch (opt) { case 'C': /* Configuration Profile */ if (profile_exists (optarg, FALSE)) { set_profile_name (optarg); } else { cmdarg_err("Configuration Profile \"%s\" does not exist", optarg); exit(1); } break; case 'D': /* Print a list of capture devices and exit */ #ifdef HAVE_LIBPCAP if_list = capture_interface_list(&err, &err_str); if (if_list == NULL) { switch (err) { case CANT_GET_INTERFACE_LIST: cmdarg_err("%s", err_str); g_free(err_str); break; case NO_INTERFACES_FOUND: cmdarg_err("There are no interfaces on which a capture can be done"); break; } exit(2); } capture_opts_print_interfaces(if_list); free_interface_list(if_list); exit(0); #else capture_option_specified = TRUE; arg_error = TRUE; #endif break; case 'h': /* Print help and exit */ print_usage(TRUE); exit(0); break; #ifdef _WIN32 case 'i': if (strcmp(optarg, "-") == 0) stdin_capture = TRUE; break; #endif case 'P': /* Path settings - change these before the Preferences and alike are processed */ status = filesystem_opt(opt, optarg); if(status != 0) { cmdarg_err("-P flag \"%s\" failed (hint: is it quoted and existing?)", optarg); exit(status); } break; case 'v': /* Show version and exit */ show_version(); exit(0); break; case 'X': /* * Extension command line options have to be processed before * we call epan_init() as they are supposed to be used by dissectors * or taps very early in the registration process. */ ex_opt_add(optarg); break; case '?': /* Ignore errors - the "real" scan will catch them. */ break; } } cf_callback_add(main_cf_callback, NULL); /* Arrange that if we have no console window, and a GLib message logging routine is called to log a message, we pop up a console window. We do that by inserting our own handler for all messages logged to the default domain; that handler pops up a console if necessary, and then calls the default handler. */ /* We might want to have component specific log levels later ... */ log_flags = (GLogLevelFlags) ( G_LOG_LEVEL_ERROR| G_LOG_LEVEL_CRITICAL| G_LOG_LEVEL_WARNING| G_LOG_LEVEL_MESSAGE| G_LOG_LEVEL_INFO| G_LOG_LEVEL_DEBUG| G_LOG_FLAG_FATAL|G_LOG_FLAG_RECURSION ); g_log_set_handler(NULL, log_flags, console_log_handler, NULL /* user_data */); g_log_set_handler(LOG_DOMAIN_MAIN, log_flags, console_log_handler, NULL /* user_data */); #ifdef HAVE_LIBPCAP g_log_set_handler(LOG_DOMAIN_CAPTURE, log_flags, console_log_handler, NULL /* user_data */); g_log_set_handler(LOG_DOMAIN_CAPTURE_CHILD, log_flags, console_log_handler, NULL /* user_data */); /* Set the initial values in the capture options. This might be overwritten by preference settings and then again by the command line parameters. */ capture_opts_init(&global_capture_opts, &cfile); #endif /* Register all dissectors; we must do this before checking for the "-G" flag, as the "-G" flag dumps information registered by the dissectors, and we must do it before we read the preferences, in case any dissectors register preferences. */ epan_init(register_all_protocols,register_all_protocol_handoffs, NULL, NULL, // splash_update, (gpointer) splash_win, failure_alert_box,open_failure_alert_box,read_failure_alert_box, write_failure_alert_box ); // splash_update(RA_LISTENERS, NULL, (gpointer)splash_win); /* Register all tap listeners; we do this before we parse the arguments, as the "-z" argument can specify a registered tap. */ /* we register the plugin taps before the other taps because stats_tree taps plugins will be registered as tap listeners by stats_tree_stat.c and need to registered before that */ g_log(NULL, G_LOG_LEVEL_DEBUG, "plugin_dir: %s", get_plugin_dir()); #ifdef HAVE_PLUGINS register_all_plugin_tap_listeners(); #endif // register_all_tap_listeners(); // splash_update(RA_PREFERENCES, NULL, (gpointer)splash_win); prefs_p = read_configuration_files (&gdp_path, &dp_path); /* Removed thread code: * http://anonsvn.wireshark.org/viewvc/viewvc.cgi?view=rev&revision=35027 */ g_log(NULL, G_LOG_LEVEL_DEBUG, "FIX: timestamp types should be set elsewhere"); timestamp_set_type(TS_RELATIVE); timestamp_set_precision(TS_PREC_AUTO_USEC); timestamp_set_seconds_type(TS_SECONDS_DEFAULT); ///////// build_column_format_array(&cfile.cinfo, prefs_p->num_cols, TRUE); font_init(); //////// /* Read the dynamic part of the recent file, as we have the gui now ready for it. */ recent_read_dynamic(&rf_path, &rf_open_errno); if (rf_path != NULL && rf_open_errno != 0) { simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK, "Could not open recent file\n\"%s\": %s.", rf_path, g_strerror(rf_open_errno)); } color_filters_enable(recent.packet_list_colorize); g_log(NULL, G_LOG_LEVEL_DEBUG, "FIX: fetch recent color settings"); color_filters_enable(TRUE); //////// switch (user_font_apply()) { case FA_SUCCESS: break; case FA_FONT_NOT_RESIZEABLE: /* "user_font_apply()" popped up an alert box. */ /* turn off zooming - font can't be resized */ case FA_FONT_NOT_AVAILABLE: /* XXX - did we successfully load the un-zoomed version earlier? If so, this *probably* means the font is available, but not at this particular zoom level, but perhaps some other failure occurred; I'm not sure you can determine which is the case, however. */ /* turn off zooming - zoom level is unavailable */ default: /* in any other case than FA_SUCCESS, turn off zooming */ // recent.gui_zoom_level = 0; /* XXX: would it be a good idea to disable zooming (insensitive GUI)? */ break; } //////// color_filters_init(); //////// w = new(MainWindow); w->show(); return a.exec(); }
int main(int argc, char *argv[]) { GString *comp_info_str; GString *runtime_info_str; char *init_progfile_dir_error; wtap *wth = NULL; wtap_dumper *pdh = NULL; wtap_rec dump_rec; Buffer buf; int err; gchar *err_info; gint64 data_offset; const wtap_rec *rec; guint wrong_order_count = 0; gboolean write_output_regardless = TRUE; guint i; GArray *shb_hdrs = NULL; wtapng_iface_descriptions_t *idb_inf = NULL; GArray *nrb_hdrs = NULL; int ret = EXIT_SUCCESS; GPtrArray *frames; FrameRecord_t *prevFrame = NULL; int opt; static const struct option long_options[] = { {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'v'}, {0, 0, 0, 0 } }; int file_count; char *infile; const char *outfile; cmdarg_err_init(failure_warning_message, failure_message_cont); /* Get the compile-time version information string */ comp_info_str = get_compiled_version_info(NULL, NULL); /* Get the run-time version information string */ runtime_info_str = get_runtime_version_info(NULL); /* Add it to the information to be reported on a crash. */ ws_add_crash_info("Reordercap (Wireshark) %s\n" "\n" "%s" "\n" "%s", get_ws_vcs_version_info(), comp_info_str->str, runtime_info_str->str); g_string_free(comp_info_str, TRUE); g_string_free(runtime_info_str, TRUE); /* * Get credential information for later use. */ init_process_policies(); /* * Attempt to get the pathname of the directory containing the * executable file. */ init_progfile_dir_error = init_progfile_dir(argv[0]); if (init_progfile_dir_error != NULL) { fprintf(stderr, "reordercap: Can't get pathname of directory containing the reordercap program: %s.\n", init_progfile_dir_error); g_free(init_progfile_dir_error); } init_report_message(failure_warning_message, failure_warning_message, NULL, NULL, NULL); wtap_init(TRUE); /* Process the options first */ while ((opt = getopt_long(argc, argv, "hnv", long_options, NULL)) != -1) { switch (opt) { case 'n': write_output_regardless = FALSE; break; case 'h': printf("Reordercap (Wireshark) %s\n" "Reorder timestamps of input file frames into output file.\n" "See https://www.wireshark.org for more information.\n", get_ws_vcs_version_info()); print_usage(stdout); goto clean_exit; case 'v': comp_info_str = get_compiled_version_info(NULL, NULL); runtime_info_str = get_runtime_version_info(NULL); show_version("Reordercap (Wireshark)", comp_info_str, runtime_info_str); g_string_free(comp_info_str, TRUE); g_string_free(runtime_info_str, TRUE); goto clean_exit; case '?': print_usage(stderr); ret = INVALID_OPTION; goto clean_exit; } } /* Remaining args are file names */ file_count = argc - optind; if (file_count == 2) { infile = argv[optind]; outfile = argv[optind+1]; } else { print_usage(stderr); ret = INVALID_OPTION; goto clean_exit; } /* Open infile */ /* TODO: if reordercap is ever changed to give the user a choice of which open_routine reader to use, then the following needs to change. */ wth = wtap_open_offline(infile, WTAP_TYPE_AUTO, &err, &err_info, TRUE); if (wth == NULL) { cfile_open_failure_message("reordercap", infile, err, err_info); ret = OPEN_ERROR; goto clean_exit; } DEBUG_PRINT("file_type_subtype is %d\n", wtap_file_type_subtype(wth)); shb_hdrs = wtap_file_get_shb_for_new_file(wth); idb_inf = wtap_file_get_idb_info(wth); nrb_hdrs = wtap_file_get_nrb_for_new_file(wth); /* Open outfile (same filetype/encap as input file) */ if (strcmp(outfile, "-") == 0) { pdh = wtap_dump_open_stdout_ng(wtap_file_type_subtype(wth), wtap_file_encap(wth), wtap_snapshot_length(wth), FALSE, shb_hdrs, idb_inf, nrb_hdrs, &err); } else { pdh = wtap_dump_open_ng(outfile, wtap_file_type_subtype(wth), wtap_file_encap(wth), wtap_snapshot_length(wth), FALSE, shb_hdrs, idb_inf, nrb_hdrs, &err); } g_free(idb_inf); idb_inf = NULL; if (pdh == NULL) { cfile_dump_open_failure_message("reordercap", outfile, err, wtap_file_type_subtype(wth)); wtap_block_array_free(shb_hdrs); wtap_block_array_free(nrb_hdrs); ret = OUTPUT_FILE_ERROR; goto clean_exit; } /* Allocate the array of frame pointers. */ frames = g_ptr_array_new(); /* Read each frame from infile */ while (wtap_read(wth, &err, &err_info, &data_offset)) { FrameRecord_t *newFrameRecord; rec = wtap_get_rec(wth); newFrameRecord = g_slice_new(FrameRecord_t); newFrameRecord->num = frames->len + 1; newFrameRecord->offset = data_offset; if (rec->presence_flags & WTAP_HAS_TS) { newFrameRecord->frame_time = rec->ts; } else { nstime_set_unset(&newFrameRecord->frame_time); } if (prevFrame && frames_compare(&newFrameRecord, &prevFrame) < 0) { wrong_order_count++; } g_ptr_array_add(frames, newFrameRecord); prevFrame = newFrameRecord; } if (err != 0) { /* Print a message noting that the read failed somewhere along the line. */ cfile_read_failure_message("reordercap", infile, err, err_info); } printf("%u frames, %u out of order\n", frames->len, wrong_order_count); /* Sort the frames */ if (wrong_order_count > 0) { g_ptr_array_sort(frames, frames_compare); } /* Write out each sorted frame in turn */ wtap_rec_init(&dump_rec); ws_buffer_init(&buf, 1500); for (i = 0; i < frames->len; i++) { FrameRecord_t *frame = (FrameRecord_t *)frames->pdata[i]; /* Avoid writing if already sorted and configured to */ if (write_output_regardless || (wrong_order_count > 0)) { frame_write(frame, wth, pdh, &dump_rec, &buf, infile, outfile); } g_slice_free(FrameRecord_t, frame); } wtap_rec_cleanup(&dump_rec); ws_buffer_free(&buf); if (!write_output_regardless && (wrong_order_count == 0)) { printf("Not writing output file because input file is already in order.\n"); } /* Free the whole array */ g_ptr_array_free(frames, TRUE); /* Close outfile */ if (!wtap_dump_close(pdh, &err)) { cfile_close_failure_message(outfile, err); wtap_block_array_free(shb_hdrs); wtap_block_array_free(nrb_hdrs); ret = OUTPUT_FILE_ERROR; goto clean_exit; } wtap_block_array_free(shb_hdrs); wtap_block_array_free(nrb_hdrs); /* Finally, close infile and release resources. */ wtap_close(wth); clean_exit: wtap_cleanup(); free_progdirs(); return ret; }